Skip to content

Commit 56aee00

Browse files
committed
usecase testing and model testing for promotion
1 parent cc7288d commit 56aee00

14 files changed

+435
-108
lines changed

lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MyApp extends StatelessWidget {
2626
onPressed: () {
2727
promoUsecase.saveFavPromo(
2828
promo: PromoModel(
29-
duration: DateTime.now(),
29+
duration: 2,
3030
eventName: "eventName",
3131
poster: 'poster',
3232
),

lib/promo/data/data_sources/api_service.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ApiService {
2727
return PromoModel(
2828
eventName: "eventName",
2929
poster: "promo",
30-
duration: DateTime.now(),
30+
duration: 1,
3131
);
3232
}
3333

@@ -39,7 +39,7 @@ class ApiService {
3939
return PromoModel(
4040
eventName: "expiryEventName",
4141
poster: "expiryPromo",
42-
duration: DateTime.now(),
42+
duration: 2,
4343
);
4444
}
4545
}

lib/promo/data/models/promo_model.dart

+11
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,15 @@ class PromoModel extends Promo {
77
required super.poster,
88
required super.duration,
99
});
10+
11+
factory PromoModel.fromJson(Map<String, dynamic> json) => PromoModel(
12+
eventName: json["eventName"],
13+
poster: json["poster"],
14+
duration: json["duration"]);
15+
16+
Map<String, dynamic> toJson() => {
17+
"eventName": eventName,
18+
"poster": poster,
19+
"duration": duration,
20+
};
1021
}

lib/promo/domain/entities/promo.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:equatable/equatable.dart';
44
abstract class Promo extends Equatable {
55
final String eventName;
66
final String poster;
7-
final DateTime duration;
7+
final int duration;
88

99
const Promo({
1010
required this.eventName,

pubspec.lock

+8
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ packages:
259259
url: "https://pub.dev"
260260
source: hosted
261261
version: "2.3.1"
262+
http:
263+
dependency: "direct main"
264+
description:
265+
name: http
266+
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
267+
url: "https://pub.dev"
268+
source: hosted
269+
version: "1.1.0"
262270
http_multi_server:
263271
dependency: transitive
264272
description:

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies:
3939
get: ^4.6.5
4040
mockito: ^5.4.2
4141
json_annotation: ^4.8.1
42+
http: ^1.1.0
4243

4344
dev_dependencies:
4445
flutter_test:

readme-img/geeks-vs-repetitive.jpg

64.3 KB
Loading
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"duration": 3,
3+
"eventName": "Love O'clock",
4+
"poster": "Love"
5+
}

test/helpers/json_reader.dart

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'dart:io';
2+
3+
String readJson(String name) {
4+
var dir = Directory.current.path;
5+
if (dir.endsWith('/test')) {
6+
dir = dir.replaceAll('/test', '');
7+
}
8+
return File('$dir/test/helpers/dummy_data/$name').readAsStringSync();
9+
}

test/helpers/mock_helper.dart

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:http/http.dart' as http;
2+
import 'package:mockito/annotations.dart';
3+
import 'package:test_driven_development/promo/domain/repositories/promo_repository.dart';
4+
5+
@GenerateMocks(
6+
[PromoRepository],
7+
customMocks: [MockSpec<http.Client>(as: #MockHttpClient)],
8+
)
9+
void main() {}

0 commit comments

Comments
 (0)