Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Aug 12, 2024
1 parent 20a53c1 commit 1914280
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/postgrest/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ void main() {
final httpClient = CustomHttpClient();
final postgrest = PostgrestClient(rootUrl, httpClient: httpClient);

await postgrest.rpc('func').setHeader("myKey", "myValue").select();
await postgrest
.rpc('empty-succ')
.setHeader("myKey", "myValue")
.select()
.head();
expect(httpClient.lastRequest!.headers, containsPair("myKey", "myValue"));

// Other following requests should not have the header
await postgrest.rpc('func').select();
await postgrest.rpc('empty-succ').select().head();
expect(httpClient.lastRequest!.headers,
isNot(containsPair("myKey", "myValue")));
});
Expand All @@ -104,11 +108,15 @@ void main() {
final httpClient = CustomHttpClient();
final postgrest = PostgrestClient(rootUrl, httpClient: httpClient);

await postgrest.from('users').setHeader("myKey", "myValue").select();
await postgrest
.from('empty-succ')
.setHeader("myKey", "myValue")
.select()
.head();
expect(httpClient.lastRequest!.headers, containsPair("myKey", "myValue"));

// Other following requests should not have the header
await postgrest.from('users').select();
await postgrest.from('empty-succ').select().head();
expect(httpClient.lastRequest!.headers,
isNot(containsPair("myKey", "myValue")));
});
Expand Down
7 changes: 7 additions & 0 deletions packages/postgrest/test/custom_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class CustomHttpClient extends BaseClient {
Future<StreamedResponse> send(BaseRequest request) async {
lastRequest = request;

if (request.url.path.endsWith("empty-succ")) {
return StreamedResponse(
Stream.empty(),
200,
request: request,
);
}
//Return custom status code to check for usage of this client.
return StreamedResponse(
request.finalize(),
Expand Down

0 comments on commit 1914280

Please sign in to comment.