File tree 10 files changed +98
-282
lines changed
10 files changed +98
-282
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:dio/dio.dart' ;
2
+
3
+ class ClientHttp {
4
+ static final client = Dio ();
5
+
6
+ static Future <Response > get (String path) async {
7
+ return client.get (path);
8
+ }
9
+ }
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/foundation.dart' ;
2
+ import 'package:test_driven_development/http/http_client.dart' ;
2
3
3
4
import '../../domain/entities/promo.dart' ;
4
5
import '../models/promo_model.dart' ;
@@ -32,14 +33,13 @@ class ApiService {
32
33
}
33
34
34
35
Future <PromoModel ?> getFavPromo () async {
35
- await Future .delayed (const Duration (seconds: 10 ));
36
- if (kDebugMode) {
37
- print ("get Fav Promo pass" );
36
+ final response = await ClientHttp .get ("http://example.com" );
37
+ if (response.statusCode == 200 ) {
38
+ if (kDebugMode) {
39
+ print ("get Fav Promo pass" );
40
+ }
41
+ return PromoModel .fromJson (response.data);
38
42
}
39
- return PromoModel (
40
- eventName: "expiryEventName" ,
41
- poster: "expiryPromo" ,
42
- duration: 2 ,
43
- );
43
+ return null ;
44
44
}
45
45
}
Original file line number Diff line number Diff line change @@ -177,6 +177,14 @@ packages:
177
177
url: "https://pub.dev"
178
178
source: hosted
179
179
version: "2.3.2"
180
+ dio:
181
+ dependency: "direct main"
182
+ description:
183
+ name: dio
184
+ sha256: ce75a1b40947fea0a0e16ce73337122a86762e38b982e1ccb909daa3b9bc4197
185
+ url: "https://pub.dev"
186
+ source: hosted
187
+ version: "5.3.2"
180
188
equatable:
181
189
dependency: "direct main"
182
190
description:
@@ -259,14 +267,14 @@ packages:
259
267
url: "https://pub.dev"
260
268
source: hosted
261
269
version: "2.3.1"
262
- http :
270
+ http_mock_adapter :
263
271
dependency: "direct main"
264
272
description:
265
- name: http
266
- sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525 "
273
+ name: http_mock_adapter
274
+ sha256: "07e78a5b64410ff8404aee2f8889ebff08def0c752b85a3945dec2029a6e1110 "
267
275
url: "https://pub.dev"
268
276
source: hosted
269
- version: "1.1 .0"
277
+ version: "0.6 .0"
270
278
http_multi_server:
271
279
dependency: transitive
272
280
description:
@@ -315,6 +323,14 @@ packages:
315
323
url: "https://pub.dev"
316
324
source: hosted
317
325
version: "2.1.1"
326
+ logger:
327
+ dependency: transitive
328
+ description:
329
+ name: logger
330
+ sha256: "66cb048220ca51cf9011da69fa581e4ee2bed4be6e82870d9e9baae75739da49"
331
+ url: "https://pub.dev"
332
+ source: hosted
333
+ version: "2.0.1"
318
334
logging:
319
335
dependency: transitive
320
336
description:
Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ dependencies:
39
39
get : ^4.6.5
40
40
mockito : ^5.4.2
41
41
json_annotation : ^4.8.1
42
- http : ^1.1.0
42
+ dio : ^5.3.2
43
+ http_mock_adapter : ^0.6.0
43
44
44
45
dev_dependencies :
45
46
flutter_test :
Original file line number Diff line number Diff line change
1
+ import 'dart:convert' ;
1
2
import 'dart:io' ;
2
3
3
- String readJson (String name) {
4
+ Map < String , dynamic > readJson (String name) {
4
5
var dir = Directory .current.path;
5
6
if (dir.endsWith ('/test' )) {
6
7
dir = dir.replaceAll ('/test' , '' );
7
8
}
8
- return File ('$dir /test/helpers/dummy_data/$name ' ).readAsStringSync ();
9
+ return json
10
+ .decode (File ('$dir /test/helpers/dummy_data/$name ' ).readAsStringSync ());
9
11
}
Original file line number Diff line number Diff line change 1
- import 'package:http/http.dart' as http;
2
1
import 'package:mockito/annotations.dart' ;
3
2
import 'package:test_driven_development/promo/domain/repositories/promo_repository.dart' ;
4
3
5
4
@GenerateMocks (
6
5
[PromoRepository ],
7
- customMocks: [MockSpec <http.Client >(as : #MockHttpClient )],
8
6
)
9
7
void main () {}
You can’t perform that action at this time.
0 commit comments