Skip to content

Commit 2f3ddb4

Browse files
committed
feat(Home): unit test for models
1 parent b92438a commit 2f3ddb4

File tree

9 files changed

+101
-5
lines changed

9 files changed

+101
-5
lines changed

.githooks/pre-push

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ if [ $? -ne 0 ]; then
1010
printf "\e[31;1m%s\e[0m\n" 'Flutter analyzer error'
1111
exit 1
1212
fi
13+
flutter test
14+
if [ $? -ne 0 ]; then
15+
printf "\e[31;1m%s\e[0m\n" 'Flutter test error'
16+
exit 1
17+
fi
1318
printf "\e[33;1m%s\e[0m\n" 'Finished running the Flutter analyzer'

test/features/auth/data/repositories/auth_repository_test.dart

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/features/auth/domain/usecases/login_with_email_test.dart

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/features/auth/domain/usecases/login_with_social_test.dart

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/features/auth/domain/usecases/register_with_email_test.dart

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,70 @@
1+
import 'dart:convert';
12

3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:streamskit_mobile/features/home/data/model/live_stream_model.dart';
5+
6+
import '../../../../fixtures/fixture_reader.dart';
7+
8+
void main() {
9+
final LiveStreamModel liveStreamModel = listLiveStreamFake[0];
10+
11+
test(
12+
'should be a subclass of LiveStream entity',
13+
() async {
14+
// assert
15+
expect(liveStreamModel, isA<LiveStreamModel>());
16+
},
17+
);
18+
19+
group('fromMap', () {
20+
test(
21+
'should return a valid model when the JSON',
22+
() async {
23+
// arrange
24+
final String jsonMap = fixture('live_stream_model.json');
25+
final List jsonListRaw = jsonDecode(jsonMap)['data'];
26+
// act
27+
final List<LiveStreamModel> result = jsonListRaw
28+
.map<LiveStreamModel>(
29+
(liveStreamJson) => LiveStreamModel.fromMap(liveStreamJson))
30+
.toList();
31+
// assert
32+
expect(result.length, jsonListRaw.length);
33+
},
34+
);
35+
});
36+
37+
group('toMap', () {
38+
test(
39+
'should return a MAP map containing the proper data',
40+
() async {
41+
// act
42+
final result = liveStreamModel.toMap();
43+
// assert
44+
final expectedMap = {
45+
'peopleParticipant': 910,
46+
'type': 1,
47+
'urlToImage': urlImageGame,
48+
};
49+
expect(result, expectedMap);
50+
},
51+
);
52+
});
53+
54+
group('toJson', () {
55+
test(
56+
'should return a JSON map containing the proper data',
57+
() async {
58+
// act
59+
final result = liveStreamModel.toJson();
60+
// assert
61+
final expectedMap = {
62+
'peopleParticipant': 910,
63+
'type': 1,
64+
'urlToImage': urlImageGame,
65+
};
66+
expect(result, jsonEncode(expectedMap));
67+
},
68+
);
69+
});
70+
}

test/features/home/data/repositories/live_stream_repository_test.dart

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/fixture_reader.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import 'dart:io';
2+
3+
String fixture(String name) => File('test/fixtures/$name').readAsStringSync();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"data": [
3+
{
4+
"peopleParticipant": 910,
5+
"type": 1,
6+
"urlToImage": ""
7+
},
8+
{
9+
"peopleParticipant": 910,
10+
"type": 2,
11+
"urlToImage": ""
12+
},
13+
{
14+
"peopleParticipant": 910,
15+
"type": 3,
16+
"urlToImage": ""
17+
},
18+
{
19+
"peopleParticipant": 910,
20+
"type": 4,
21+
"urlToImage": ""
22+
}
23+
]
24+
}

0 commit comments

Comments
 (0)