@@ -11,6 +11,7 @@ import 'package:zulip/model/localizations.dart';
11
11
12
12
import '../model/binding.dart' ;
13
13
import '../stdlib_checks.dart' ;
14
+ import '../test_async.dart' ;
14
15
import 'exception_checks.dart' ;
15
16
import 'fake_api.dart' ;
16
17
import '../example_data.dart' as eg;
@@ -19,8 +20,8 @@ void main() {
19
20
TestZulipBinding .ensureInitialized ();
20
21
21
22
test ('ApiConnection.get' , () async {
22
- Future < void > checkRequest (Map <String , dynamic >? params, String expectedRelativeUrl) {
23
- return FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
23
+ void checkRequest (Map <String , dynamic >? params, String expectedRelativeUrl) {
24
+ finish ( FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
24
25
connection.prepare (json: {});
25
26
await connection.get (kExampleRouteName, (json) => json, 'example/route' , params);
26
27
check (connection.lastRequest! ).isA< http.Request > ()
@@ -31,7 +32,7 @@ void main() {
31
32
...kFallbackUserAgentHeader,
32
33
})
33
34
..body.equals ('' );
34
- });
35
+ })) ;
35
36
}
36
37
37
38
checkRequest (null , '/api/v1/example/route' );
@@ -50,8 +51,8 @@ void main() {
50
51
});
51
52
52
53
test ('ApiConnection.post' , () async {
53
- Future < void > checkRequest (Map <String , dynamic >? params, String expectedBody, {bool expectContentType = true }) {
54
- return FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
54
+ void checkRequest (Map <String , dynamic >? params, String expectedBody, {bool expectContentType = true }) {
55
+ finish ( FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
55
56
connection.prepare (json: {});
56
57
await connection.post (kExampleRouteName, (json) => json, 'example/route' , params);
57
58
check (connection.lastRequest! ).isA< http.Request > ()
@@ -64,7 +65,7 @@ void main() {
64
65
'content-type' : 'application/x-www-form-urlencoded; charset=utf-8' ,
65
66
})
66
67
..body.equals (expectedBody);
67
- });
68
+ })) ;
68
69
}
69
70
70
71
checkRequest (null , '' , expectContentType: false );
@@ -81,9 +82,9 @@ void main() {
81
82
});
82
83
83
84
test ('ApiConnection.postFileFromStream' , () async {
84
- Future < void > checkRequest (List <List <int >> content, int length,
85
+ void checkRequest (List <List <int >> content, int length,
85
86
{String ? filename, String ? contentType, bool isContentTypeInvalid = false }) {
86
- return FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
87
+ finish ( FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
87
88
connection.prepare (json: {});
88
89
await connection.postFileFromStream (
89
90
kExampleRouteName, (json) => json, 'example/route' ,
@@ -108,7 +109,7 @@ void main() {
108
109
..has <Future <List <int >>>((f) => f.finalize ().toBytes (), 'contents' )
109
110
.completes ((it) => it.deepEquals (content.expand ((l) => l)))
110
111
);
111
- });
112
+ })) ;
112
113
}
113
114
114
115
checkRequest ([], 0 , filename: null );
@@ -126,8 +127,8 @@ void main() {
126
127
});
127
128
128
129
test ('ApiConnection.delete' , () async {
129
- Future < void > checkRequest (Map <String , dynamic >? params, String expectedBody, {bool expectContentType = true }) {
130
- return FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
130
+ void checkRequest (Map <String , dynamic >? params, String expectedBody, {bool expectContentType = true }) {
131
+ finish ( FakeApiConnection .with_ (account: eg.selfAccount, (connection) async {
131
132
connection.prepare (json: {});
132
133
await connection.delete (kExampleRouteName, (json) => json, 'example/route' , params);
133
134
check (connection.lastRequest! ).isA< http.Request > ()
@@ -140,7 +141,7 @@ void main() {
140
141
'content-type' : 'application/x-www-form-urlencoded; charset=utf-8' ,
141
142
})
142
143
..body.equals (expectedBody);
143
- });
144
+ })) ;
144
145
}
145
146
146
147
checkRequest (null , '' , expectContentType: false );
@@ -166,13 +167,13 @@ void main() {
166
167
});
167
168
168
169
test ('API network errors' , () async {
169
- Future < void > checkRequest <T extends Object >(
170
+ void checkRequest <T extends Object >(
170
171
T exception, Condition <NetworkException > condition) {
171
- return check (tryRequest (exception: exception))
172
+ finish ( check (tryRequest (exception: exception))
172
173
.throws <NetworkException >((it) => it
173
174
..routeName.equals (kExampleRouteName)
174
175
..cause.equals (exception)
175
- ..which (condition));
176
+ ..which (condition))) ;
176
177
}
177
178
178
179
final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
@@ -219,14 +220,14 @@ void main() {
219
220
});
220
221
221
222
test ('API 4xx errors, malformed' , () async {
222
- Future < void > checkMalformed ({
223
- int httpStatus = 400 , Map <String , dynamic >? json, String ? body}) async {
223
+ void checkMalformed ({
224
+ int httpStatus = 400 , Map <String , dynamic >? json, String ? body}) {
224
225
assert ((json == null ) != (body == null ));
225
- await check (tryRequest (httpStatus: httpStatus, json: json, body: body))
226
+ finish ( check (tryRequest (httpStatus: httpStatus, json: json, body: body))
226
227
.throws <MalformedServerResponseException >((it) => it
227
228
..routeName.equals (kExampleRouteName)
228
229
..httpStatus.equals (httpStatus)
229
- ..data.deepEquals (json));
230
+ ..data.deepEquals (json))) ;
230
231
}
231
232
232
233
await check (
0 commit comments