-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathQB-CoreSpec.js
230 lines (189 loc) · 7.34 KB
/
QB-CoreSpec.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
'use strict';
var REST_REQUESTS_TIMEOUT = 10000;
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
var QuickBlox = isNodeEnv ? require('../src/qbMain') : window.QB;
var QB;
var CREDS = isNodeEnv ? require('./config').CREDS : window.CREDS;
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
describe('QB init tests', function () {
beforeEach(function () {
QB = new QuickBlox.QuickBlox();
});
it('can init SDK with session token and appId (without accountKey)', function () {
QB.init('56655ac9a0eb476d92002b66', CREDS.appId);
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDS.appId);
});
it('can init SDK with appId, authKey, authSecret, accountKey, config', function () {
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CREDS.accountKey, CONFIG);
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDS.appId);
expect(QB.service.qbInst.config.creds.authKey).toEqual(CREDS.authKey);
expect(QB.service.qbInst.config.creds.authSecret).toEqual(CREDS.authSecret);
expect(QB.service.qbInst.config.creds.accountKey).toEqual(CREDS.accountKey);
expect(QB.service.qbInst.config.debug).toEqual(CONFIG.debug);
});
it('can init SDK with appId, authKey, authSecret, config (without accountKey)', function () {
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, undefined, CONFIG);
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDS.appId);
expect(QB.service.qbInst.config.creds.authKey).toEqual(CREDS.authKey);
expect(QB.service.qbInst.config.creds.authSecret).toEqual(CREDS.authSecret);
expect(QB.service.qbInst.config.debug).toEqual(CONFIG.debug);
});
});
describe('Ping tests', function () {
beforeAll(function (done) {
QB = new QuickBlox.QuickBlox();
QB.init(
CREDS.appId,
CREDS.authKey,
CREDS.authSecret,
CREDS.accountKey,
CONFIG
);
var chatConnectParams = {
userId: QBUser1.id,
password: QBUser1.password
};
QB.chat.connect(chatConnectParams, function(err) {
if (err) {
done.fail('Connection to chat error: ' + JSON.stringify(err));
} else {
done();
}
});
});
afterAll(function () {
QB.chat.disconnect();
});
it('should ping shared chat server', function (done) {
QB.chat.ping(function (err) {
if (err) {
done.fail(err);
} else {
done();
}
})
});
it('should ping logged-in user and respond with pong', function (done) {
QB.chat.ping(QBUser1.id, function (err) {
if (err) {
done.fail(err);
} else {
done();
}
});
});
it('should return error within "pingTimeout"', function (done) {
QB.chat.ping(-1, function (err) {
expect(err).toEqual('No answer');
done();
});
});
});
describe('Session API', function () {
beforeAll(function () {
QB = new QuickBlox.QuickBlox();
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CREDS.accountKey, CONFIG);
});
it('can create a session', function (done) {
QB.createSession(function (err, session) {
if (err) {
done.fail('Create a session error: ' + JSON.stringify(err));
} else {
expect(session).not.toBeNull();
expect(session.application_id).toEqual(CREDS.appId);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can create a User session', function (done) {
QB.createSession(QBUser1, function (err, session) {
if (err) {
done.fail("Create a User session error: " + JSON.stringify(err));
} else {
expect(session).not.toBeNull();
expect(session.application_id).toEqual(CREDS.appId);
expect(session.user_id).toEqual(QBUser1.id);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can login a user', function (done) {
QB.login(QBUser1, function (err, user) {
if (err) {
done.fail("Login user error2: " + JSON.stringify(err));
} else {
expect(user).not.toBeNull();
expect(user.login).toEqual(QBUser1.login);
expect(user.id).toEqual(QBUser1.id);
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can logout a user', function (done) {
QB.logout(function (err, result) {
if (err) {
done.fail("Logout user error3: " + JSON.stringify(err));
} else {
expect(null).toBeNull(); /** we just have to have some expectations. */
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can destroy a session', function (done) {
QB.destroySession(function (err, result) {
if (err) {
done.fail("Destroy session error2: " + JSON.stringify(err));
} else {
expect(QB.service.qbInst.session).toBeNull();
done();
}
});
}, REST_REQUESTS_TIMEOUT);
it('can connect to custom domains', function () {
/** Test old way to set domains */
var CUSTOMCONFIG = {
endpoints: {
api: 'apicustomdomain.quickblox.com',
chat: 'chatcustomdomain.quickblox.com',
muc: 'muc.chatcustomdomain.quickblox.com'
},
chatProtocol: {
bosh: 'https://chatcustomdomain.quickblox.com:5281',
websocket: 'wss://chatcustomdomain.quickblox.com:5291'
}
};
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CREDS.accountKey, CUSTOMCONFIG);
expect(QB.service.qbInst.config.endpoints.api).toEqual('apicustomdomain.quickblox.com');
expect(QB.service.qbInst.config.endpoints.chat).toEqual('chatcustomdomain.quickblox.com');
expect(QB.service.qbInst.config.endpoints.muc).toEqual('muc.chatcustomdomain.quickblox.com');
expect(QB.service.qbInst.config.chatProtocol.bosh).toEqual('https://chatcustomdomain.quickblox.com:5281');
expect(QB.service.qbInst.config.chatProtocol.websocket).toEqual('wss://chatcustomdomain.quickblox.com:5291');
/** Test new way to set domains */
var CUSTOMCONFIG2 = {
endpoints: {
api: 'apicustomdomain2.quickblox.com',
chat: 'chatcustomdomain2.quickblox.com'
}
};
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CREDS.accountKey, CUSTOMCONFIG2);
expect(QB.service.qbInst.config.endpoints.api).toEqual('apicustomdomain2.quickblox.com');
expect(QB.service.qbInst.config.endpoints.chat).toEqual('chatcustomdomain2.quickblox.com');
expect(QB.service.qbInst.config.endpoints.muc).toEqual('muc.chatcustomdomain2.quickblox.com');
expect(QB.service.qbInst.config.chatProtocol.bosh).toEqual('https://chatcustomdomain2.quickblox.com:5281');
expect(QB.service.qbInst.config.chatProtocol.websocket).toEqual('wss://chatcustomdomain2.quickblox.com:5291');
/** return back to default domains */
var DEFAULTCONFIG = {
endpoints: {
api: 'api.quickblox.com',
chat: 'chat.quickblox.com'
}
};
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CREDS.accountKey, DEFAULTCONFIG);
expect(QB.service.qbInst.config.endpoints.api).toEqual('api.quickblox.com');
expect(QB.service.qbInst.config.endpoints.chat).toEqual('chat.quickblox.com');
expect(QB.service.qbInst.config.endpoints.muc).toEqual('muc.chat.quickblox.com');
expect(QB.service.qbInst.config.chatProtocol.bosh).toEqual('https://chat.quickblox.com:5281');
expect(QB.service.qbInst.config.chatProtocol.websocket).toEqual('wss://chat.quickblox.com:5291');
});
});