Skip to content

Commit 1914280

Browse files
committed
test: fix tests
1 parent 20a53c1 commit 1914280

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

packages/postgrest/test/basic_test.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ void main() {
9191
final httpClient = CustomHttpClient();
9292
final postgrest = PostgrestClient(rootUrl, httpClient: httpClient);
9393

94-
await postgrest.rpc('func').setHeader("myKey", "myValue").select();
94+
await postgrest
95+
.rpc('empty-succ')
96+
.setHeader("myKey", "myValue")
97+
.select()
98+
.head();
9599
expect(httpClient.lastRequest!.headers, containsPair("myKey", "myValue"));
96100

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

107-
await postgrest.from('users').setHeader("myKey", "myValue").select();
111+
await postgrest
112+
.from('empty-succ')
113+
.setHeader("myKey", "myValue")
114+
.select()
115+
.head();
108116
expect(httpClient.lastRequest!.headers, containsPair("myKey", "myValue"));
109117

110118
// Other following requests should not have the header
111-
await postgrest.from('users').select();
119+
await postgrest.from('empty-succ').select().head();
112120
expect(httpClient.lastRequest!.headers,
113121
isNot(containsPair("myKey", "myValue")));
114122
});

packages/postgrest/test/custom_http_client.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ class CustomHttpClient extends BaseClient {
66
Future<StreamedResponse> send(BaseRequest request) async {
77
lastRequest = request;
88

9+
if (request.url.path.endsWith("empty-succ")) {
10+
return StreamedResponse(
11+
Stream.empty(),
12+
200,
13+
request: request,
14+
);
15+
}
916
//Return custom status code to check for usage of this client.
1017
return StreamedResponse(
1118
request.finalize(),

0 commit comments

Comments
 (0)