Skip to content

Commit 1a8b855

Browse files
committed
test; maked all tests in sync with the new constrains
1 parent a3a82cb commit 1a8b855

25 files changed

+334
-279
lines changed

lib/src/models/entities/headline.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Headline extends FeedItem {
6767
final String? imageUrl;
6868

6969
/// Date and time when the headline was published.
70+
@JsonKey(fromJson: _dateTimeFromJson)
7071
final DateTime? publishedAt;
7172

7273
/// Source or origin of the headline.

lib/src/models/entities/headline.g.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/models/feed_decorators/engagement_content.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ class EngagementContent extends FeedItem {
100100
return EngagementContent(
101101
id: id ?? this.id,
102102
title: title ?? this.title,
103-
description: description ?? this.description,
103+
description: description,
104104
engagementContentType:
105105
engagementContentType ?? this.engagementContentType,
106-
callToActionText: callToActionText ?? this.callToActionText,
107-
callToActionUrl: callToActionUrl ?? this.callToActionUrl,
106+
callToActionText: callToActionText,
107+
callToActionUrl: callToActionUrl,
108108
action: action ?? this.action,
109109
);
110110
}

lib/src/models/user_settings/app_accent_theme.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
13
/// {@template app_accent_theme}
24
/// Represents a selection of predefined accent color themes.
35
///
@@ -6,6 +8,7 @@
68
/// The actual `ColorScheme` associated with each enum value would be defined
79
/// within the application's theme configuration.
810
/// {@endtemplate}
11+
@JsonEnum(fieldRename: FieldRename.snake)
912
enum AppAccentTheme {
1013
/// The default blue accent theme.
1114
defaultBlue,

lib/src/models/user_settings/display_settings.g.dart

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/src/models/core/feed_item_action_test.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ void main() {
4949
test('toJson returns correct JSON map', () {
5050
final json = openInternalContent.toJson();
5151
expect(json, <String, dynamic>{
52-
'contentId': contentId,
53-
'contentType': contentType.name,
52+
'content_id': contentId,
53+
'content_type': contentType.name,
5454
'type': 'open_internal_content',
5555
});
5656
});
5757

5858
test('fromJson returns correct OpenInternalContent object', () {
5959
final json = <String, dynamic>{
60-
'contentId': contentId,
61-
'contentType': contentType.name,
60+
'content_id': contentId,
61+
'content_type': contentType.name,
6262
'type': 'open_internal_content',
6363
};
6464
final fromJsonResult = OpenInternalContent.fromJson(json);
@@ -112,8 +112,8 @@ void main() {
112112
test('toJson returns correct JSON map', () {
113113
final json = showInterstitialThenOpenInternalContent.toJson();
114114
expect(json, <String, dynamic>{
115-
'contentId': contentId,
116-
'contentType': contentType.name,
115+
'content_id': contentId,
116+
'content_type': contentType.name,
117117
'type': 'show_interstitial_then_open_internal_content',
118118
});
119119
});
@@ -122,8 +122,8 @@ void main() {
122122
'fromJson returns correct ShowInterstitialThenOpenInternalContent '
123123
'object', () {
124124
final json = <String, dynamic>{
125-
'contentId': contentId,
126-
'contentType': contentType.name,
125+
'content_id': contentId,
126+
'content_type': contentType.name,
127127
'type': 'show_interstitial_then_open_internal_content',
128128
};
129129
final fromJsonResult =
@@ -168,8 +168,8 @@ void main() {
168168
group('feedItemActionFromJson', () {
169169
test('dispatches to OpenInternalContent', () {
170170
final json = <String, dynamic>{
171-
'contentId': 'id1',
172-
'contentType': 'headline',
171+
'content_id': 'id1',
172+
'content_type': 'headline',
173173
'type': 'open_internal_content',
174174
};
175175
final action = feedItemActionFromJson(json);
@@ -180,8 +180,8 @@ void main() {
180180

181181
test('dispatches to ShowInterstitialThenOpenInternalContent', () {
182182
final json = <String, dynamic>{
183-
'contentId': 'id2',
184-
'contentType': 'category',
183+
'content_id': 'id2',
184+
'content_type': 'category',
185185
'type': 'show_interstitial_then_open_internal_content',
186186
};
187187
final action = feedItemActionFromJson(json);
@@ -204,7 +204,7 @@ void main() {
204204
});
205205

206206
test('throws FormatException if type is missing', () {
207-
final json = <String, dynamic>{'contentId': 'id1'};
207+
final json = <String, dynamic>{'content_id': 'id1'};
208208
expect(
209209
() => feedItemActionFromJson(json),
210210
throwsA(
@@ -240,8 +240,8 @@ void main() {
240240
);
241241
final json = feedItemActionToJson(action);
242242
expect(json, <String, dynamic>{
243-
'contentId': 'id1',
244-
'contentType': 'headline',
243+
'content_id': 'id1',
244+
'content_type': 'headline',
245245
'type': 'open_internal_content',
246246
});
247247
});
@@ -253,8 +253,8 @@ void main() {
253253
);
254254
final json = feedItemActionToJson(action);
255255
expect(json, <String, dynamic>{
256-
'contentId': 'id2',
257-
'contentType': 'category',
256+
'content_id': 'id2',
257+
'content_type': 'category',
258258
'type': 'show_interstitial_then_open_internal_content',
259259
});
260260
});

test/src/models/entities/category_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void main() {
6262
'type': 'category',
6363
'action': {
6464
'type': 'open_internal_content',
65-
'contentId': 'science-id',
66-
'contentType': 'category',
65+
'content_id': 'science-id',
66+
'content_type': 'category',
6767
},
6868
};
6969
expect(
@@ -87,8 +87,8 @@ void main() {
8787
'type': 'category',
8888
'action': {
8989
'type': 'open_internal_content',
90-
'contentId': 'art-id',
91-
'contentType': 'category',
90+
'content_id': 'art-id',
91+
'content_type': 'category',
9292
},
9393
};
9494
final category = Category.fromJson(json);
@@ -115,8 +115,8 @@ void main() {
115115
'type': 'category',
116116
'action': {
117117
'type': 'open_internal_content',
118-
'contentId': 'test-id',
119-
'contentType': 'category',
118+
'content_id': 'test-id',
119+
'content_type': 'category',
120120
},
121121
});
122122
});
@@ -129,8 +129,8 @@ void main() {
129129
'type': 'category',
130130
'action': {
131131
'type': 'open_internal_content',
132-
'contentId': 'test-id',
133-
'contentType': 'category',
132+
'content_id': 'test-id',
133+
'content_type': 'category',
134134
},
135135
});
136136
});

test/src/models/entities/country_test.dart

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:ht_shared/src/models/core/feed_item_action.dart';
22
import 'package:ht_shared/src/models/entities/country.dart'; // Use direct import
3+
import 'package:json_annotation/json_annotation.dart';
34
import 'package:test/test.dart';
45
import 'package:uuid/uuid.dart';
56

@@ -156,66 +157,60 @@ void main() {
156157
});
157158

158159
// Updated to expect TypeError based on terminal output
159-
test('throws TypeError for missing iso_code', () {
160+
test('throws CheckedFromJsonException for missing iso_code', () {
160161
final json = createValidJsonMap()..remove('iso_code');
161162
expect(
162163
() => Country.fromJson(json),
163-
throwsA(isA<TypeError>()), // Expect TypeError
164+
throwsA(isA<CheckedFromJsonException>()),
164165
);
165166
});
166167

167-
// Updated to expect TypeError based on terminal output
168-
test('throws TypeError for missing name', () {
168+
test('throws CheckedFromJsonException for missing name', () {
169169
final json = createValidJsonMap()..remove('name');
170170
expect(
171171
() => Country.fromJson(json),
172-
throwsA(isA<TypeError>()), // Expect TypeError
172+
throwsA(isA<CheckedFromJsonException>()),
173173
);
174174
});
175175

176-
// Updated to expect TypeError based on terminal output
177-
test('throws TypeError for missing flag_url', () {
176+
test('throws CheckedFromJsonException for missing flag_url', () {
178177
final json = createValidJsonMap()..remove('flag_url');
179178
expect(
180179
() => Country.fromJson(json),
181-
throwsA(isA<TypeError>()), // Expect TypeError
180+
throwsA(isA<CheckedFromJsonException>()),
182181
);
183182
});
184183

185-
// Updated to expect TypeError based on terminal output
186-
test('throws TypeError for wrong type (id)', () {
184+
test('throws CheckedFromJsonException for wrong type (id)', () {
187185
final json = createValidJsonMap()..['id'] = 123; // Invalid type
188186
expect(
189187
() => Country.fromJson(json),
190-
throwsA(isA<TypeError>()), // Expect TypeError
188+
throwsA(isA<CheckedFromJsonException>()),
191189
);
192190
});
193191

194-
// Updated to expect TypeError based on terminal output
195-
test('throws TypeError for wrong type (iso_code)', () {
192+
test('throws CheckedFromJsonException for wrong type (iso_code)', () {
196193
final json = createValidJsonMap()..['iso_code'] = 123; // Invalid type
197194
expect(
198195
() => Country.fromJson(json),
199-
throwsA(isA<TypeError>()), // Expect TypeError
196+
throwsA(isA<CheckedFromJsonException>()),
200197
);
201198
});
202199

203-
// Updated to expect TypeError based on terminal output
204-
test('throws TypeError for wrong type (name)', () {
200+
test('throws CheckedFromJsonException for wrong type (name)', () {
205201
final json = createValidJsonMap()..['name'] = false; // Invalid type
206202
expect(
207203
() => Country.fromJson(json),
208-
throwsA(isA<TypeError>()), // Expect TypeError
204+
throwsA(isA<CheckedFromJsonException>()),
209205
);
210206
});
211207

212-
// Updated to expect TypeError based on terminal output
213-
test('throws TypeError for wrong type (flag_url)', () {
208+
test('throws CheckedFromJsonException for wrong type (flag_url)', () {
214209
final json = createValidJsonMap()
215210
..['flag_url'] = null; // Invalid type (non-nullable)
216211
expect(
217212
() => Country.fromJson(json),
218-
throwsA(isA<TypeError>()), // Expect TypeError
213+
throwsA(isA<CheckedFromJsonException>()),
219214
);
220215
});
221216
});

test/src/models/entities/headline_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void main() {
1010
final sampleSourceJson = {
1111
'id': 'src-test',
1212
'name': 'Test Source',
13-
'sourceType': 'news-agency', // Updated to match SourceType enum name
13+
'source_type': 'news_agency', // Corrected to snake_case for enum value
1414
'type': 'source',
1515
'action': {
1616
'type': 'open_external_url',
@@ -49,8 +49,8 @@ void main() {
4949
'title': 'Full Headline Title',
5050
'description': 'Full description.',
5151
'url': 'http://example.com/full',
52-
'imageUrl': 'http://example.com/full.jpg',
53-
'publishedAt': testTimeString,
52+
'image_url': 'http://example.com/full.jpg',
53+
'published_at': testTimeString,
5454
'source': sampleSourceJson,
5555
'category': sampleCategoryJson,
5656
'action': defaultAction.toJson(),
@@ -107,14 +107,14 @@ void main() {
107107

108108
test('should handle null DateTime correctly', () {
109109
final jsonWithNullDate = Map<String, dynamic>.from(fullHeadlineJson)
110-
..['publishedAt'] = null;
110+
..['published_at'] = null; // Use snake_case key
111111
final headline = Headline.fromJson(jsonWithNullDate);
112112
expect(headline.publishedAt, isNull);
113113
});
114114

115115
test('should handle invalid DateTime string gracef@ully', () {
116116
final jsonWithInvalidDate = Map<String, dynamic>.from(fullHeadlineJson)
117-
..['publishedAt'] = 'invalid-date';
117+
..['published_at'] = 'invalid-date'; // Use snake_case key
118118
final headline = Headline.fromJson(jsonWithInvalidDate);
119119
// tryParse returns null for invalid format
120120
expect(headline.publishedAt, isNull);
@@ -148,8 +148,8 @@ void main() {
148148
expect(json['title'], minimalHeadline.title);
149149
expect(json.containsKey('description'), isFalse);
150150
expect(json.containsKey('url'), isFalse);
151-
expect(json.containsKey('imageUrl'), isFalse);
152-
expect(json.containsKey('publishedAt'), isFalse);
151+
expect(json.containsKey('image_url'), isFalse);
152+
expect(json.containsKey('published_at'), isFalse);
153153
expect(json.containsKey('source'), isFalse);
154154
expect(json.containsKey('category'), isFalse);
155155
});
@@ -216,8 +216,8 @@ void main() {
216216
fullHeadline.title,
217217
fullHeadline.description,
218218
fullHeadline.url,
219-
fullHeadline.imageUrl,
220-
fullHeadline.publishedAt,
219+
fullHeadline.imageUrl,
220+
fullHeadline.publishedAt,
221221
fullHeadline.source,
222222
fullHeadline.category,
223223
fullHeadline.type,

0 commit comments

Comments
 (0)