1
1
import 'package:http/http.dart' as http;
2
-
3
2
import 'package:mocktail/mocktail.dart' ;
3
+ import 'package:tbdex/src/http_client/exceptions/http_exceptions.dart' ;
4
4
import 'package:tbdex/src/http_client/tbdex_http_client.dart' ;
5
5
import 'package:test/test.dart' ;
6
6
@@ -51,6 +51,26 @@ void main() async {
51
51
).called (1 );
52
52
});
53
53
54
+ test ('get exchange throws ResponseError' , () async {
55
+ when (
56
+ () => mockHttpClient.get (
57
+ Uri .parse ('$pfiServiceEndpoint /exchanges/1234' ),
58
+ headers: any (named: 'headers' ),
59
+ ),
60
+ ).thenAnswer (
61
+ (_) async => http.Response ('Error' , 400 ),
62
+ );
63
+
64
+ expect (
65
+ () async => TbdexHttpClient .getExchange (
66
+ TestData .aliceDid,
67
+ pfiDid,
68
+ '1234' ,
69
+ ),
70
+ throwsA (isA <ResponseError >()),
71
+ );
72
+ });
73
+
54
74
test ('can list exchanges' , () async {
55
75
when (
56
76
() => mockHttpClient.get (
@@ -73,6 +93,22 @@ void main() async {
73
93
).called (1 );
74
94
});
75
95
96
+ test ('list exchanges throws ResponseError' , () async {
97
+ when (
98
+ () => mockHttpClient.get (
99
+ Uri .parse ('$pfiServiceEndpoint /exchanges/' ),
100
+ headers: any (named: 'headers' ),
101
+ ),
102
+ ).thenAnswer (
103
+ (_) async => http.Response ('Error' , 400 ),
104
+ );
105
+
106
+ expect (
107
+ () async => TbdexHttpClient .listExchanges (TestData .aliceDid, pfiDid),
108
+ throwsA (isA <ResponseError >()),
109
+ );
110
+ });
111
+
76
112
test ('can list offerings' , () async {
77
113
when (
78
114
() => mockHttpClient.get (Uri .parse ('$pfiServiceEndpoint /offerings/' )),
@@ -88,6 +124,19 @@ void main() async {
88
124
).called (1 );
89
125
});
90
126
127
+ test ('list offerings throws ResponseError' , () async {
128
+ when (
129
+ () => mockHttpClient.get (Uri .parse ('$pfiServiceEndpoint /offerings/' )),
130
+ ).thenAnswer (
131
+ (_) async => http.Response ('Error' , 400 ),
132
+ );
133
+
134
+ expect (
135
+ () async => await TbdexHttpClient .listOfferings (pfiDid),
136
+ throwsA (isA <ResponseError >()),
137
+ );
138
+ });
139
+
91
140
test ('can create exchange' , () async {
92
141
final rfq = TestData .getRfq (to: pfiDid);
93
142
await rfq.sign (TestData .aliceDid);
@@ -113,6 +162,26 @@ void main() async {
113
162
).called (1 );
114
163
});
115
164
165
+ test ('create exchange throws ResponseError' , () async {
166
+ final rfq = TestData .getRfq (to: pfiDid);
167
+ await rfq.sign (TestData .aliceDid);
168
+
169
+ when (
170
+ () => mockHttpClient.post (
171
+ Uri .parse ('$pfiServiceEndpoint /exchanges' ),
172
+ headers: any (named: 'headers' ),
173
+ body: TestData .getCreateExchangeRequest (rfq, replyTo: 'reply_to' ),
174
+ ),
175
+ ).thenAnswer (
176
+ (_) async => http.Response ('Error' , 400 ),
177
+ );
178
+
179
+ expect (
180
+ () async => TbdexHttpClient .createExchange (rfq, replyTo: 'reply_to' ),
181
+ throwsA (isA <ResponseError >()),
182
+ );
183
+ });
184
+
116
185
test ('can submit order' , () async {
117
186
final order = TestData .getOrder (to: pfiDid);
118
187
final exchangeId = order.metadata.exchangeId;
@@ -139,6 +208,27 @@ void main() async {
139
208
).called (1 );
140
209
});
141
210
211
+ test ('submit order throws ResponseError' , () async {
212
+ final order = TestData .getOrder (to: pfiDid);
213
+ final exchangeId = order.metadata.exchangeId;
214
+ await order.sign (TestData .aliceDid);
215
+
216
+ when (
217
+ () => mockHttpClient.put (
218
+ Uri .parse ('$pfiServiceEndpoint /exchanges/$exchangeId ' ),
219
+ headers: any (named: 'headers' ),
220
+ body: TestData .getSubmitOrderRequest (order),
221
+ ),
222
+ ).thenAnswer (
223
+ (_) async => http.Response ('Error' , 400 ),
224
+ );
225
+
226
+ expect (
227
+ () async => TbdexHttpClient .submitOrder (order),
228
+ throwsA (isA <ResponseError >()),
229
+ );
230
+ });
231
+
142
232
test ('can submit close' , () async {
143
233
final close = TestData .getClose (to: pfiDid);
144
234
final exchangeId = close.metadata.exchangeId;
@@ -164,5 +254,26 @@ void main() async {
164
254
),
165
255
).called (1 );
166
256
});
257
+
258
+ test ('submit close throws ResponseError' , () async {
259
+ final close = TestData .getClose (to: pfiDid);
260
+ final exchangeId = close.metadata.exchangeId;
261
+ await close.sign (TestData .aliceDid);
262
+
263
+ when (
264
+ () => mockHttpClient.put (
265
+ Uri .parse ('$pfiServiceEndpoint /exchanges/$exchangeId ' ),
266
+ headers: any (named: 'headers' ),
267
+ body: TestData .getSubmitCloseRequest (close),
268
+ ),
269
+ ).thenAnswer (
270
+ (_) async => http.Response ('Error' , 400 ),
271
+ );
272
+
273
+ expect (
274
+ () async => TbdexHttpClient .submitClose (close),
275
+ throwsA (isA <ResponseError >()),
276
+ );
277
+ });
167
278
});
168
279
}
0 commit comments