-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile_tweet_mapper_test.dart
More file actions
115 lines (102 loc) · 3.06 KB
/
Copy pathprofile_tweet_mapper_test.dart
File metadata and controls
115 lines (102 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import 'package:flutter_test/flutter_test.dart';
import 'package:lam7a/features/profile/utils/profile_tweet_mapper.dart';
import 'package:lam7a/features/common/models/tweet_model.dart';
void main() {
group('read<T>()', () {
test('returns first non-null key value', () {
final json = {
'a': null,
'b': 5,
'c': 10,
};
final result = read<int>(json, ['a', 'b', 'c']);
expect(result, 5);
});
test('returns null when all keys are missing or null', () {
final json = {'a': null};
final result = read<String>(json, ['x', 'y']);
expect(result, isNull);
});
});
group('convertProfileJsonToTweetModel', () {
test('maps normal tweet correctly', () {
final json = {
'postId': 1,
'userId': 2,
'username': 'user',
'name': 'User Name',
'text': 'Hello world',
'likesCount': 3,
'retweetsCount': 1,
'commentsCount': 2,
'date': '2024-01-01T12:00:00Z',
};
final tweet = convertProfileJsonToTweetModel(json);
expect(tweet, isA<TweetModel>());
expect(tweet.id, '1');
expect(tweet.userId, '2');
expect(tweet.body, 'Hello world');
expect(tweet.likes, 3);
expect(tweet.repost, 1);
expect(tweet.comments, 2);
expect(tweet.isRepost, false);
expect(tweet.isQuote, false);
});
test('maps repost tweet correctly', () {
final json = {
'postId': 100,
'userId': 1,
'username': 'reposter',
'name': 'Reposter',
'date': '2024-01-02T10:00:00Z',
'isRepost': true,
'originalPostData': {
'postId': 50,
'userId': 9,
'username': 'original',
'name': 'Original User',
'text': 'Original tweet',
'likesCount': 10,
'retweetsCount': 5,
'commentsCount': 3,
'date': '2024-01-01T09:00:00Z',
},
};
final tweet = convertProfileJsonToTweetModel(json);
expect(tweet.isRepost, true);
expect(tweet.originalTweet, isNotNull);
expect(tweet.body, 'Original tweet');
expect(tweet.originalTweet!.username, 'original');
});
test('maps quote tweet correctly', () {
final json = {
'postId': 200,
'userId': 3,
'username': 'quoter',
'name': 'Quoter',
'text': 'My opinion',
'likesCount': 1,
'retweetsCount': 0,
'commentsCount': 0,
'date': '2024-01-03T11:00:00Z',
'isQuote': true,
'originalPostData': {
'postId': 80,
'userId': 7,
'username': 'parent',
'name': 'Parent User',
'text': 'Parent tweet',
'likesCount': 20,
'retweetsCount': 2,
'commentsCount': 4,
'date': '2024-01-02T08:00:00Z',
},
};
final tweet = convertProfileJsonToTweetModel(json);
expect(tweet.isQuote, true);
expect(tweet.originalTweet, isNotNull);
expect(tweet.body, 'My opinion');
expect(tweet.originalTweet!.body, 'Parent tweet');
});
});
}