11import 'package:http/http.dart' as http;
2-
32import 'package:mocktail/mocktail.dart' ;
3+ import 'package:tbdex/src/http_client/exceptions/http_exceptions.dart' ;
44import 'package:tbdex/src/http_client/tbdex_http_client.dart' ;
55import 'package:test/test.dart' ;
66
@@ -51,6 +51,26 @@ void main() async {
5151 ).called (1 );
5252 });
5353
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+
5474 test ('can list exchanges' , () async {
5575 when (
5676 () => mockHttpClient.get (
@@ -73,6 +93,22 @@ void main() async {
7393 ).called (1 );
7494 });
7595
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+
76112 test ('can list offerings' , () async {
77113 when (
78114 () => mockHttpClient.get (Uri .parse ('$pfiServiceEndpoint /offerings/' )),
@@ -88,6 +124,19 @@ void main() async {
88124 ).called (1 );
89125 });
90126
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+
91140 test ('can create exchange' , () async {
92141 final rfq = TestData .getRfq (to: pfiDid);
93142 await rfq.sign (TestData .aliceDid);
@@ -113,6 +162,26 @@ void main() async {
113162 ).called (1 );
114163 });
115164
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+
116185 test ('can submit order' , () async {
117186 final order = TestData .getOrder (to: pfiDid);
118187 final exchangeId = order.metadata.exchangeId;
@@ -139,6 +208,27 @@ void main() async {
139208 ).called (1 );
140209 });
141210
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+
142232 test ('can submit close' , () async {
143233 final close = TestData .getClose (to: pfiDid);
144234 final exchangeId = close.metadata.exchangeId;
@@ -164,5 +254,26 @@ void main() async {
164254 ),
165255 ).called (1 );
166256 });
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+ });
167278 });
168279}
0 commit comments