Skip to content

Commit 1c2ae70

Browse files
committed
test(push_notifications): improve PushNotificationPayload test
- Refactor test to use fixture data for consistency - Update props test to reflect current model structure - Enhance copyWith test to include additional fields - Simplify import statement for core package
1 parent 88c83c0 commit 1c2ae70

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

test/src/models/push_notifications/push_notification_payload_test.dart

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
1-
import 'package:core/src/models/push_notifications/push_notification_payload.dart';
1+
import 'package:core/core.dart';
22
import 'package:test/test.dart';
33

44
void main() {
55
group('PushNotificationPayload', () {
6-
const title = 'Breaking News';
7-
const imageUrl = 'https://example.com/image.jpg';
8-
const data = <String, dynamic>{
9-
'contentType': 'headline',
10-
'id': 'headline-123',
11-
};
12-
13-
const payload = PushNotificationPayload(
14-
title: title,
15-
imageUrl: imageUrl,
16-
data: data,
17-
);
18-
19-
final json = <String, dynamic>{
20-
'title': title,
21-
'imageUrl': imageUrl,
22-
'data': data,
23-
};
6+
// Use a fixture to ensure consistency and avoid manual setup.
7+
final payload = inAppNotificationsFixturesData.first.payload;
8+
final json = payload.toJson();
249

2510
test('supports value equality', () {
2611
// Arrange: Create another instance with the same values.
27-
const anotherPayload = PushNotificationPayload(
28-
title: title,
29-
imageUrl: imageUrl,
30-
data: data,
31-
);
12+
final anotherPayload = payload.copyWith();
3213

3314
// Assert: The two instances should be equal.
3415
expect(payload, equals(anotherPayload));
3516
});
3617

3718
test('props are correct', () {
3819
// Assert: The props list should contain all the fields.
39-
expect(payload.props, equals([title, imageUrl, data]));
20+
expect(
21+
payload.props,
22+
equals([
23+
payload.title,
24+
payload.notificationId,
25+
payload.notificationType,
26+
payload.contentType,
27+
payload.contentId,
28+
payload.imageUrl,
29+
]),
30+
);
4031
});
4132

4233
test('can be created from JSON', () {
@@ -58,17 +49,22 @@ void main() {
5849
test('copyWith creates a copy with updated values', () {
5950
// Arrange: Define the updated values.
6051
const newTitle = 'Updated News';
52+
const newContentId = 'new-content-id';
6153

6254
// Act: Create a copy with the updated values.
63-
final copiedPayload = payload.copyWith(title: newTitle);
55+
final copiedPayload = payload.copyWith(
56+
title: newTitle,
57+
contentId: newContentId,
58+
);
6459

6560
// Assert: The new instance should have the updated values.
6661
expect(copiedPayload.title, equals(newTitle));
67-
expect(copiedPayload.imageUrl, equals(imageUrl));
68-
expect(copiedPayload.data, equals(data));
62+
expect(copiedPayload.contentId, equals(newContentId));
63+
expect(copiedPayload.imageUrl, equals(payload.imageUrl));
64+
expect(copiedPayload.notificationId, equals(payload.notificationId));
6965

7066
// Assert: The original instance should remain unchanged.
71-
expect(payload.title, equals(title));
67+
expect(payload.title, isNot(equals(newTitle)));
7268
});
7369

7470
test(

0 commit comments

Comments
 (0)