Repository navigation
Expand file tree
/
Copy pathunit.spec.js
More file actions
164 lines (122 loc) · 4.17 KB
/
Copy pathunit.spec.js
File metadata and controls
164 lines (122 loc) · 4.17 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
//dependencies
var path = require('path');
var async = require('async');
var expect = require('chai').expect;
var faker = require('faker');
var PushNotification = require(path.join(__dirname, '..'));
describe('byteskode push', function () {
//seed
var pushNotification = {
to: faker.random.uuid(),
data: {
key1: 'message1',
key2: 'message2'
},
notification: {
title: 'Alert!!!',
body: 'Abnormal data access',
icon: 'ic_launcher'
},
options: {
collapseKey: 'demo',
priority: 'high',
contentAvailable: true,
delayWhileIdle: true,
timeToLive: 3,
restrictedPackageName: 'somePackageName',
dryRun: true
}
};
beforeEach(function (done) {
PushNotification.remove(done);
});
it('should be exported', function () {
expect(PushNotification).to.exist;
});
it('should be able to send and resend push notifications', function () {
expect(PushNotification.send).to.exist;
expect(PushNotification.resend).to.exist;
});
it('should be able to queue and requeue push notifications', function () {
expect(PushNotification.queue).to.exist;
expect(PushNotification.requeue).to.exist;
});
it('should be able to validate sent push notification', function (done) {
var pushNotification = new PushNotification();
pushNotification.validate(function (error) {
expect(error).to.exist;
expect(error.name).to.equal('ValidationError');
done();
});
});
it(
'should be able to send push notification in test and development mode',
function (done) {
PushNotification.send(pushNotification, function (error,
_pushNotification) {
expect(error).to.not.exist;
expect(_pushNotification).to.exist;
expect(_pushNotification._id).to.exist;
expect(_pushNotification.createdAt).to.exist;
expect(_pushNotification.sentAt).to.exist;
expect(_pushNotification.to).to.exist;
expect(_pushNotification.to).to.be.an.Array;
expect(_pushNotification.data).to.exist;
expect(_pushNotification.notification).to.exist;
expect(_pushNotification.options).to.exist;
done(error, _pushNotification);
});
});
it(
'should be able to resend push notification(s) in test and development mode',
function (done) {
async.waterfall([
function createPushNotification(next) {
PushNotification.queue(pushNotification, next);
},
function resend(_pushNotification, next) {
expect(_pushNotification.sentAt).to.not.exist;
PushNotification.resend(next);
}
], function (error, response) {
expect(error).to.not.exist;
expect(response).to.exist;
var _pushNotification = response[0];
expect(_pushNotification._id).to.exist;
expect(_pushNotification.createdAt).to.exist;
expect(_pushNotification.sentAt).to.exist;
expect(_pushNotification.to).to.exist;
expect(_pushNotification.to).to.be.an.Array;
expect(_pushNotification.data).to.exist;
expect(_pushNotification.notification).to.exist;
expect(_pushNotification.options).to.exist;
done(error, response);
});
});
it(
'should be able to queue push notification in test and development mode for later send',
function (done) {
PushNotification.on('push:queued', function (_pushNotification) {
expect(_pushNotification).to.exist;
expect(_pushNotification._id).to.exist;
expect(_pushNotification.createdAt).to.exist;
expect(_pushNotification.sentAt).to.not.exist;
expect(_pushNotification.to).to.exist;
expect(_pushNotification.to).to.be.an.Array;
expect(_pushNotification.data).to.exist;
expect(_pushNotification.notification).to.exist;
expect(_pushNotification.options).to.exist;
done(null, _pushNotification);
});
//queue pushNotification
PushNotification.queue(pushNotification);
});
after(function (done) {
if (PushNotification._queue) {
PushNotification._queue.shutdown(5000, done);
} else {
done();
}
});
});