Skip to content

Commit a184927

Browse files
committed
Add Create Notification Tests
• Adds tests to make sure that OSCreateNotification is getting parsed correctly • Moves some common test params (ie. testPlayerId) to test_data.dart
1 parent e384325 commit a184927

File tree

3 files changed

+145
-7
lines changed

3 files changed

+145
-7
lines changed

test/create_notification_test.dart

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import 'package:test/test.dart';
2+
import 'test_data.dart';
3+
4+
void main() {
5+
6+
//silent notification tests
7+
test ('expect silent notifications contentAvailable param to be true wihtout explicitly passing it into the constructor', () {
8+
expect(silentNotification.contentAvailable, true);
9+
});
10+
11+
test ('expect notification to parse player IDs correctly', () {
12+
expect(silentNotification.playerIds.first, testPlayerId);
13+
});
14+
15+
test ('expect notification to parse additional data correctly', () {
16+
expect(silentNotification.additionalData['test'], 'value' );
17+
});
18+
19+
//normal notification tests
20+
test('expect notification content to be correct', () {
21+
expect(notificationJson['contents']['es'], 'test_content');
22+
});
23+
24+
test('expect notification headings to be correct', () {
25+
expect(notificationJson['headings']['es'], 'test heading');
26+
});
27+
28+
test('expect subtitle to be correct', () {
29+
expect(notificationJson['subtitle']['es'], 'test subtitle' );
30+
});
31+
32+
test('expect contentAvailable to be parsed correctly', () {
33+
expect(notificationJson['content_available'], true);
34+
});
35+
36+
test('expect url to be parsed correctly', () {
37+
expect(notificationJson['url'], 'https://www.google.com/');
38+
});
39+
40+
test('expect ios attahgments to be parsed correctly', () {
41+
expect(notificationJson['ios_attachments']['id1'], 'puppy.jpg');
42+
});
43+
44+
test('expect big picture to be parsed correctly', () {
45+
expect(notificationJson['big_picture'], 'puppy2.jpg');
46+
});
47+
48+
test('expect ios category to be parsed correctly', () {
49+
expect(notificationJson['ios_category'], 'test_category');
50+
});
51+
52+
test('expect ios sound to be parsed correctly', () {
53+
expect(notificationJson['ios_sound'], 'ping.aiff');
54+
});
55+
56+
test('expect android sound to be parsed correctly', () {
57+
expect(notificationJson['android_sound'], 'ping.mp3');
58+
});
59+
60+
test('expect android small icon to be parsed correctly', () {
61+
expect(notificationJson['small_icon'], 'puppy_small.jpg');
62+
});
63+
64+
test('expect android large icon to be parsed correctly', () {
65+
expect(notificationJson['large_icon'], 'puppy_large.jpg');
66+
});
67+
68+
test('expect android channel ID to be parsed correctly', () {
69+
expect(notificationJson['android_channel_id'], 'test_channel_id');
70+
});
71+
72+
test('expect iOS badge type to be parsed correctly', () {
73+
expect(notificationJson['ios_badgeType'], 'Increase');
74+
});
75+
76+
test('expect iOS badge count to be parsed correctly', () {
77+
expect(notificationJson['ios_badgeCount'], 2);
78+
});
79+
80+
test('expect collapse ID to be parsed correctly', () {
81+
expect(notificationJson['collapse_id'], 'test_collapse_id');
82+
});
83+
84+
test('expect sendAfter to be parsed correctly', () {
85+
expect(notificationJson['send_after'], "2018-07-24T20:38:24.571Z UTC00:00:00");
86+
});
87+
88+
test('expect delayed option to be parsed correctly', () {
89+
expect(notificationJson['delay_option'], 'last_active');
90+
});
91+
92+
test('expect delivery time of day to be parsed correctly', () {
93+
expect(notificationJson['delivery_time_of_day'], '9:00 AM');
94+
});
95+
96+
test('expect buttons to be parsed correctly', () {
97+
var buttonsJson = notificationJson['buttons'] as List<Map<String, dynamic>>;
98+
expect(buttonsJson.first['id'], 'test_id');
99+
expect(buttonsJson.first['text'], 'test_text');
100+
expect(buttonsJson.first['icon'], 'test_icon');
101+
});
102+
}

test/onesignal_test.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import 'package:test/test.dart';
22
import 'package:OneSignalFlutter/onesignal.dart';
33
import 'mock_channel.dart';
4+
import 'test_data.dart';
45

56
void main() {
67
OneSignalMockChannelController channelController = OneSignalMockChannelController();
78
OneSignal onesignal = OneSignal();
89

9-
// test values
10-
const String testAppId = "35b3mbq4-7ce2-401f-9da0-2d41f287ebaf";
11-
const String testPlayerId = "c1b395fc-3b17-4c18-aaa6-195cd3461311";
12-
const String testEmail = "test@example.com";
13-
const String testEmailAuthHashToken = "4f1916b13a164a765b42b3205b49670a40309127179cb2687ea7feae6f61ee45";
14-
1510
setUp(() {
1611
channelController.resetState();
1712
});

test/test_data.dart

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import 'dart:convert';
22
import 'dart:io';
3+
import 'package:OneSignalFlutter/src/create_notification.dart';
4+
import 'package:OneSignalFlutter/src/notification.dart';
5+
import 'package:OneSignalFlutter/src/defines.dart';
36

47
class TestData {
58
static final file = new File('test.json');
@@ -8,4 +11,42 @@ class TestData {
811
static dynamic jsonForTest(String test) {
912
return json[test];
1013
}
11-
}
14+
}
15+
16+
// test values
17+
const String testAppId = "35b3mbq4-7ce2-401f-9da0-2d41f287ebaf";
18+
const String testPlayerId = "c1b395fc-3b17-4c18-aaa6-195cd3461311";
19+
const String testEmail = "test@example.com";
20+
const String testEmailAuthHashToken = "4f1916b13a164a765b42b3205b49670a40309127179cb2687ea7feae6f61ee45";
21+
22+
final silentNotification = OSCreateNotification.silentNotification(
23+
playerIds: ['testPlayerID'],
24+
additionalData: {'test' : 'value'}
25+
);
26+
27+
final notificationJson = OSCreateNotification(
28+
playerIds: [testPlayerId],
29+
content: 'test_content',
30+
additionalData: {'test' : 'value'},
31+
languageCode: 'es',
32+
heading: 'test heading',
33+
subtitle: 'test subtitle',
34+
contentAvailable: true,
35+
mutableContent: true,
36+
url: 'https://www.google.com/',
37+
iosAttachments: {'id1' : 'puppy.jpg'},
38+
bigPicture: 'puppy2.jpg',
39+
buttons: <OSActionButton> [OSActionButton(text: 'test_text', id: 'test_id', icon: 'test_icon')],
40+
iosCategory: 'test_category',
41+
iosSound: 'ping.aiff',
42+
androidSound: 'ping.mp3',
43+
androidSmallIcon: 'puppy_small.jpg',
44+
androidLargeIcon: 'puppy_large.jpg',
45+
androidChannelId: 'test_channel_id',
46+
iosBadgeType: OSCreateNotificationBadgeType.increase,
47+
iosBadgeCount: 2,
48+
collapseId: 'test_collapse_id',
49+
sendAfter: DateTime.fromMillisecondsSinceEpoch(1532464704571, isUtc: true), //corresponds to 2018-07-24T20:38:24.571Z UTC00:00:00
50+
delayedOption: OSCreateNotificationDelayOption.lastActive,
51+
deliveryTimeOfDay: '9:00 AM'
52+
).mapRepresentation();

0 commit comments

Comments
 (0)