supabase / postgrest-dart

Dart client for PostgREST
https://supabase.com
MIT License
136 stars 38 forks source link

Complete test coverage #2

Closed phamhieu closed 4 years ago

phamhieu commented 4 years ago

This is a Hacktoberfest task! You can read more about Hacktoberfest on our blog and see all tasks on our Hacktoberfest Project Board.

Summary

We need help with completing test coverage for this library. Following postgrest-js there are 4 test files:

Right now, there's only 1 test per file as example. We need to have all test cases as original postgrest-js project.

https://github.com/supabase/postgrest-js/blob/master/test/basic.test.ts https://github.com/supabase/postgrest-js/blob/master/test/filters.test.ts https://github.com/supabase/postgrest-js/blob/master/test/resource-embedding.test.ts https://github.com/supabase/postgrest-js/blob/master/test/transforms.test.ts

Details

Before running test file, It's required to start a docker instance first:

  1. Install Docker
  2. cd test/db
  3. make start
asaravindkumar commented 4 years ago

can you give me a sample of how to call Rpc method?

var res = await postgrest.rpc('get_status', {'username': 'supabot'}).end();

This gives 500 error as below

{body: null, status: 500, statusCode: StateError, statusText: Bad state: Cannot set the body fields of a Request with content-type "application/json".}

phamhieu commented 4 years ago

@asaravindkumar good catch!

I pushed a fix for this. In short, dart:http requires body to be a json encoded string.

phamhieu commented 4 years ago

Just a head up @asaravindkumar, this task is depended on #7 because the PR will convert return data into a PostgrestResponse obj instead of raw Map obj

7 is already merged. Let me know if you want to work on this task @asaravindkumar.

asaravindkumar commented 4 years ago

@phamhieu yes. I can work on this one. thanks

asaravindkumar commented 4 years ago

Thanks @phamhieu.

How would you want to treat errors from tests? shall I post here? or comment the expect part for now with a TODO?

For e.g., statusText is now string, so unable to get the error code.

statusText: {"hint":null,"details":null,"code":"42P01","message":"relation \"public.missing_table\" does not exist"}

phamhieu commented 4 years ago

can you get error code from error variable?

Screenshot 2020-10-04 at 4 25 19 PM

Screenshot 2020-10-04 at 4 26 15 PM