-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathQB-PushnotificationsSpec.js
161 lines (131 loc) · 4.59 KB
/
QB-PushnotificationsSpec.js
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
/* globals describe, beforeAll, expect, it, xit */
'use strict';
describe('PushNotifications API', function() {
var REST_REQUESTS_TIMEOUT = 3000;
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
var QB = isNodeEnv ? require('../src/qbMain') : window.QB;
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
var subscriptionId;
var eventId;
var params = {
notification_channels: 'gcm',
device: {
platform: 'android',
udid: 'jasmineUnique'
},
push_token: {
environment: 'development',
// 'client_identification_sequence' should be valid. Otherwise, the 'delete suscription' test will fail.
client_identification_sequence: "fDmkp3zhYgo:APA91bH-XBzYbDiifSaFhJvB4eSqbZnOXkw5eG4jJTc9L4vKZWHs6Zc4oNho3MMlvIJygdyHwEtQKAJRLTnrskej11_qo03vEejGuCTRvrXxC4cUY6QjgUWNaQgYHV5IwweHNmdhmpZS",
bundle_identifier: "com.quickblox.chatapp"
}
};
beforeAll(function(done){
QB.init(
CREDENTIALS.appId,
CREDENTIALS.authKey,
CREDENTIALS.authSecret,
CREDENTIALS.accountKey,
CONFIG
);
QB.createSession(QBUser1, function(err, session) {
if (err) {
done.fail('Create session error: ' + JSON.stringify(err));
} else {
expect(session).not.toBeNull();
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can create a subscription', function(done){
QB.pushnotifications.subscriptions.create(params, function(err, res){
if (err) {
done.fail("Create a subscription error: " + JSON.stringify(err));
} else {
expect(res).not.toBeNull();
expect(res[0].subscription.device.platform.name).toBe("android");
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can list a subscription', function(done){
QB.pushnotifications.subscriptions.list(function(err, result){
if (err) {
done.fail('List subscriptions error: ' + JSON.stringify(err));
} else {
expect(result).not.toBeNull();
expect(result[0].subscription.device.udid).toBe('jasmineUnique');
subscriptionId = result[0].subscription.id;
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can create event', function(done){
var params = {
notification_type: 'push',
push_type: 'gcm',
user: {ids: [QBUser1.id]},
environment: 'development',
message: QB.pushnotifications.base64Encode('hello QuickBlox!')
};
QB.pushnotifications.events.create(params, function(err, response) {
if (err) {
done.fail('Create event error: ' + JSON.stringify(err));
} else {
expect(response).not.toBeNull();
expect(response.event.message).toBe('data.message=aGVsbG8rUXVpY2tCbG94JTIx');
eventId = response.event.id;
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can list events', function(done){
QB.pushnotifications.events.list({page: '1', per_page: '25'}, function(err, response) {
if (err) {
done.fail('List events error: ' + JSON.stringify(err));
} else {
expect(response).not.toBeNull();
expect(response.items.length).toBeGreaterThan(0);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can get event by id', function(done){
QB.pushnotifications.events.get(eventId, function(err, response) {
if (err) {
done.fail('Get event by id error: ' + JSON.stringify(err));
} else {
expect(response).not.toBeNull();
expect(response.event.id).toBe(eventId);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
xit('can get event\'s status by id', function(done){
QB.pushnotifications.events.status(eventId, function(err, response) {
if (err) {
done.fail('Get event\'s status by id error: ' + JSON.stringify(err));
} else {
expect(response).not.toBeNull();
expect(response.event.id).toBe(eventId);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it("can delete event", function(done){
QB.pushnotifications.events.delete(eventId, function(err, response) {
expect(err).toBeNull();
done();
});
}, REST_REQUESTS_TIMEOUT);
xit('can delete subscription', function(done){
function deleteSubscriptionCb(err, res) {
expect(err).toBeNull();
expect(res).toBeDefined();
done();
}
QB.pushnotifications.subscriptions.delete(subscriptionId, deleteSubscriptionCb);
}, REST_REQUESTS_TIMEOUT);
});