pryv 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsdoc-conf.json +29 -0
- package/.mocharc.js +13 -0
- package/LICENSE.md +27 -0
- package/README.md +723 -0
- package/package.json +57 -0
- package/scripts/setup-environment-dev.sh +28 -0
- package/scripts/upload.sh +15 -0
- package/src/Auth/AuthController.js +276 -0
- package/src/Auth/AuthStates.js +20 -0
- package/src/Auth/LoginMessages.js +29 -0
- package/src/Auth/index.js +43 -0
- package/src/Browser/CookieUtils.js +51 -0
- package/src/Browser/LoginButton.js +199 -0
- package/src/Browser/index.js +55 -0
- package/src/Connection.js +331 -0
- package/src/Pryv.js +19 -0
- package/src/Service.js +197 -0
- package/src/ServiceAssets.js +162 -0
- package/src/index-socket.io-monitor.js +4 -0
- package/src/index.html +17 -0
- package/src/index.js +3 -0
- package/src/lib/browser-getEventStreamed.js +80 -0
- package/src/lib/json-parser.js +156 -0
- package/src/utils.js +136 -0
- package/test/Browser.AuthController.test.js +97 -0
- package/test/Browser.test.js +79 -0
- package/test/Connection.test.js +455 -0
- package/test/Service.test.js +89 -0
- package/test/ServiceAssets.test.js +79 -0
- package/test/Y.png +0 -0
- package/test/browser-index.js +11 -0
- package/test/browser-tests.html +31 -0
- package/test/helpers.js +8 -0
- package/test/load-test-account.js +108 -0
- package/test/test-data.js +92 -0
- package/test/utils.test.js +68 -0
- package/web-demos/auth-with-redirection.html +72 -0
- package/web-demos/auth.html +77 -0
- package/web-demos/custom-login-button.html +158 -0
- package/web-demos/index.html +186 -0
- package/web-demos/service-info.json +13 -0
- package/web-demos/stream-examples.html +80 -0
- package/webpack.config.js +71 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
const should = chai.should();
|
|
2
|
+
const expect = chai.expect;
|
|
3
|
+
const testData = require('./test-data.js');
|
|
4
|
+
let conn = null;
|
|
5
|
+
const { URL, URLSearchParams } = require('universal-url');
|
|
6
|
+
const cuid = require('cuid');
|
|
7
|
+
const { readFileSync } = require('fs');
|
|
8
|
+
|
|
9
|
+
describe('Connection', () => {
|
|
10
|
+
|
|
11
|
+
before(async function () {
|
|
12
|
+
this.timeout(5000);
|
|
13
|
+
await testData.prepare();
|
|
14
|
+
conn = new Pryv.Connection(testData.apiEndpointWithToken);
|
|
15
|
+
|
|
16
|
+
// create some events
|
|
17
|
+
const toBeDeletedId = cuid();
|
|
18
|
+
const toBeTrashed = cuid();
|
|
19
|
+
const resSetup = await conn.api([
|
|
20
|
+
{
|
|
21
|
+
method: 'events.create',
|
|
22
|
+
params: {
|
|
23
|
+
streamIds: ['data'],
|
|
24
|
+
type: 'note/txt',
|
|
25
|
+
content: 'Hello test ' + new Date()
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
method: 'events.create',
|
|
30
|
+
params: {
|
|
31
|
+
streamIds: ['data'],
|
|
32
|
+
type: 'note/txt',
|
|
33
|
+
content: 'Hello test ' + new Date(),
|
|
34
|
+
id: toBeTrashed
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
method: 'events.create',
|
|
39
|
+
params: {
|
|
40
|
+
id: toBeDeletedId,
|
|
41
|
+
streamIds: ['data'],
|
|
42
|
+
type: 'note/txt',
|
|
43
|
+
content: 'To be Deleted ' + new Date(),
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
method: 'events.delete',
|
|
48
|
+
params: {
|
|
49
|
+
id: toBeTrashed
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
method: 'events.delete',
|
|
54
|
+
params: {
|
|
55
|
+
id: toBeDeletedId
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
method: 'events.delete',
|
|
60
|
+
params: {
|
|
61
|
+
id: toBeDeletedId
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('.service', function () {
|
|
68
|
+
it('return a Pryv.Service object', async () => {
|
|
69
|
+
const service = conn.service;
|
|
70
|
+
expect(service instanceof Pryv.Service).to.equal(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('.username() ', function () {
|
|
76
|
+
it('return the username of this connection', async () => {
|
|
77
|
+
const username = await conn.username();
|
|
78
|
+
expect(username).to.equals(testData.username);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
describe('.api()', function () {
|
|
85
|
+
this.timeout(5000);
|
|
86
|
+
it('.api() events.get', async () => {
|
|
87
|
+
const res = await conn.api(
|
|
88
|
+
[
|
|
89
|
+
{
|
|
90
|
+
method: "events.get",
|
|
91
|
+
params: {}
|
|
92
|
+
}
|
|
93
|
+
]);
|
|
94
|
+
res.length.should.equal(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('.api() events.get split in chunks', async () => {
|
|
98
|
+
conn.options.chunkSize = 2;
|
|
99
|
+
const res = await conn.api(
|
|
100
|
+
[
|
|
101
|
+
{ method: "events.get", params: {} },
|
|
102
|
+
{ method: "events.get", params: {} },
|
|
103
|
+
{ method: "events.get", params: {} }
|
|
104
|
+
]);
|
|
105
|
+
res.length.should.equal(3);
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
it('.api() events.get with handleResult call', async () => {
|
|
111
|
+
conn.options.chunkSize = 2;
|
|
112
|
+
|
|
113
|
+
let resultsRecievedCount = 0;
|
|
114
|
+
function oneMoreResult(res) {
|
|
115
|
+
should.exist(res.events);
|
|
116
|
+
resultsRecievedCount++;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const res = await conn.api(
|
|
120
|
+
[
|
|
121
|
+
{ method: "events.get", params: {}, handleResult: oneMoreResult },
|
|
122
|
+
{ method: "events.get", params: {}, handleResult: oneMoreResult },
|
|
123
|
+
{ method: "events.get", params: {}, handleResult: oneMoreResult }
|
|
124
|
+
]);
|
|
125
|
+
res.length.should.equal(3);
|
|
126
|
+
res.length.should.equal(resultsRecievedCount);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('.api() events.get with async handleResult call', async () => {
|
|
130
|
+
conn.options.chunkSize = 2;
|
|
131
|
+
|
|
132
|
+
let resultsRecievedCount = 0;
|
|
133
|
+
async function oneMoreResult(res) {
|
|
134
|
+
should.exist(res.events);
|
|
135
|
+
|
|
136
|
+
let promise = new Promise((res, rej) => {
|
|
137
|
+
setTimeout(() => res("Now it's done!"), 100)
|
|
138
|
+
});
|
|
139
|
+
// wait until the promise returns us a value
|
|
140
|
+
await promise;
|
|
141
|
+
resultsRecievedCount++;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const res = await conn.api(
|
|
145
|
+
[
|
|
146
|
+
{ method: "events.get", params: {}, handleResult: oneMoreResult },
|
|
147
|
+
{ method: "events.get", params: {}, handleResult: oneMoreResult },
|
|
148
|
+
{ method: "events.get", params: {}, handleResult: oneMoreResult }
|
|
149
|
+
]);
|
|
150
|
+
res.length.should.equal(3);
|
|
151
|
+
res.length.should.equal(resultsRecievedCount);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('.api() events.get split in chunks and send percentages', async () => {
|
|
155
|
+
conn.options.chunkSize = 2;
|
|
156
|
+
const percentres = { 1: 67, 2: 100 }
|
|
157
|
+
let count = 1;
|
|
158
|
+
const res = await conn.api(
|
|
159
|
+
[
|
|
160
|
+
{ method: "events.get", params: {} },
|
|
161
|
+
{ method: "events.get", params: {} },
|
|
162
|
+
{ method: "events.get", params: {} }
|
|
163
|
+
], function (percent) {
|
|
164
|
+
percent.should.equal(percentres[count]);
|
|
165
|
+
count++;
|
|
166
|
+
});
|
|
167
|
+
res.length.should.equal(3);
|
|
168
|
+
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('.api() with callbacks', (done) => {
|
|
172
|
+
conn.api(
|
|
173
|
+
[
|
|
174
|
+
{ method: "events.get", params: {} }
|
|
175
|
+
]).then((res) => {
|
|
176
|
+
res.length.should.equal(1);
|
|
177
|
+
done();
|
|
178
|
+
}, (err) => {
|
|
179
|
+
should.not.exist(err);
|
|
180
|
+
done();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('Attachements', () => {
|
|
187
|
+
it('Create event with attachment from file', async () => {
|
|
188
|
+
let res = null;
|
|
189
|
+
|
|
190
|
+
if (typeof window === 'undefined') { // node
|
|
191
|
+
|
|
192
|
+
res = await conn.createEventWithFile({
|
|
193
|
+
type: 'picture/attached',
|
|
194
|
+
streamId: 'data'
|
|
195
|
+
}, './test/Y.png');
|
|
196
|
+
|
|
197
|
+
} else { // browser
|
|
198
|
+
const formData = new FormData();
|
|
199
|
+
var blob = new Blob(['Hello'], { type: "text/txt" });
|
|
200
|
+
formData.append("webmasterfile", blob);
|
|
201
|
+
|
|
202
|
+
res = await conn.createEventWithFormData({
|
|
203
|
+
type: 'file/attached',
|
|
204
|
+
streamId: 'data'
|
|
205
|
+
}, formData);
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
should.exist(res);
|
|
211
|
+
should.exist(res.event);
|
|
212
|
+
should.exist(res.event.attachments);
|
|
213
|
+
res.event.attachments.length.should.equal(1);
|
|
214
|
+
res.event.attachments[0].size.should.equal(14798);
|
|
215
|
+
res.event.attachments[0].type.should.equal('image/png');
|
|
216
|
+
res.event.attachments[0].fileName.should.equal('Y.png');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('Create event with attachment from Buffer', async () => {
|
|
220
|
+
const fileData = readFileSync('./test/Y.png');
|
|
221
|
+
|
|
222
|
+
let res = null;
|
|
223
|
+
|
|
224
|
+
if (typeof window === 'undefined') { // node
|
|
225
|
+
|
|
226
|
+
res = await conn.createEventWithFileFromBuffer({
|
|
227
|
+
type: 'picture/attached',
|
|
228
|
+
streamId: 'data'
|
|
229
|
+
}, fileData, 'Y.png');
|
|
230
|
+
|
|
231
|
+
} else { // browser
|
|
232
|
+
const formData = new FormData();
|
|
233
|
+
var blob = new Blob(['Hello'], { type: "text/txt" });
|
|
234
|
+
formData.append("webmasterfile", blob);
|
|
235
|
+
|
|
236
|
+
res = await conn.createEventWithFormData({
|
|
237
|
+
type: 'file/attached',
|
|
238
|
+
streamId: 'data'
|
|
239
|
+
}, formData);
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
should.exist(res);
|
|
245
|
+
should.exist(res.event);
|
|
246
|
+
should.exist(res.event.attachments);
|
|
247
|
+
res.event.attachments.length.should.equal(1);
|
|
248
|
+
res.event.attachments[0].size.should.equal(14798);
|
|
249
|
+
res.event.attachments[0].type.should.equal('image/png');
|
|
250
|
+
res.event.attachments[0].fileName.should.equal('Y.png');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('HF events', () => {
|
|
257
|
+
|
|
258
|
+
it('Add data points to HF event', async () => {
|
|
259
|
+
|
|
260
|
+
const res = await conn.api([{
|
|
261
|
+
method: 'events.create',
|
|
262
|
+
params: {
|
|
263
|
+
type: 'series:mass/kg', streamId: 'data'
|
|
264
|
+
}
|
|
265
|
+
}]);
|
|
266
|
+
should.exist(res);
|
|
267
|
+
should.exist(res[0]);
|
|
268
|
+
should.exist(res[0].event);
|
|
269
|
+
should.exist(res[0].event.id);
|
|
270
|
+
const event = res[0].event;
|
|
271
|
+
|
|
272
|
+
const res2 = await conn.addPointsToHFEvent(
|
|
273
|
+
event.id,
|
|
274
|
+
['deltaTime', 'value'],
|
|
275
|
+
[[0, 1], [1, 1]]);
|
|
276
|
+
|
|
277
|
+
should.exist(res2);
|
|
278
|
+
'ok'.should.equal(res2.status);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
describe('.get()', () => {
|
|
284
|
+
it('/events', async () => {
|
|
285
|
+
const res = await conn.get('events', { limit: 1 });
|
|
286
|
+
res.events.length.should.equal(1);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe('time', () => {
|
|
292
|
+
it('deltatime property', async () => {
|
|
293
|
+
await conn.get('events', { limit: 1 });
|
|
294
|
+
const deltaTime = conn.deltaTime;
|
|
295
|
+
expect(Math.abs(deltaTime) < 2).to.be.true;
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('API', () => {
|
|
300
|
+
it('endpoint property', async () => {
|
|
301
|
+
const apiEndpoint = conn.apiEndpoint;
|
|
302
|
+
expect(apiEndpoint.startsWith('https://' + conn.token + '@')).to.be.true;
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('Streamed event get', function () {
|
|
307
|
+
this.timeout(5000);
|
|
308
|
+
const now = (new Date()).getTime() / 1000 + 1000;
|
|
309
|
+
|
|
310
|
+
describe('Node & Browser', function () {
|
|
311
|
+
it('streaming ', async () => {
|
|
312
|
+
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
313
|
+
let eventsCount = 0;
|
|
314
|
+
function forEachEvent(event) { eventsCount++; }
|
|
315
|
+
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
316
|
+
expect(eventsCount).to.equal(res.eventsCount);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
it('streaming includesDeletion', async () => {
|
|
321
|
+
const queryParams = { fromTime: 0, toTime: now, limit: 10000, includeDeletions: true, modifiedSince: 0, state: 'all' };
|
|
322
|
+
let eventsCount = 0;
|
|
323
|
+
let trashedCount = 0;
|
|
324
|
+
let deletedCount = 0;
|
|
325
|
+
function forEachEvent(event) {
|
|
326
|
+
if (event.deleted) {
|
|
327
|
+
deletedCount++;
|
|
328
|
+
} else if (event.trashed) {
|
|
329
|
+
trashedCount++;
|
|
330
|
+
} else {
|
|
331
|
+
eventsCount++;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
335
|
+
expect(trashedCount + eventsCount).to.equal(res.eventsCount);
|
|
336
|
+
expect(deletedCount).to.equal(res.eventDeletionsCount);
|
|
337
|
+
expect(eventsCount).to.be.gt(0);
|
|
338
|
+
expect(deletedCount).to.be.gt(0);
|
|
339
|
+
expect(trashedCount).to.be.gt(0);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('no-events ', async () => {
|
|
343
|
+
const queryParams = { fromTime: 0, toTime: now, tags: ['RANDOM-123'] };
|
|
344
|
+
function forEachEvent(event) { }
|
|
345
|
+
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
346
|
+
expect(0).to.equal(res.eventsCount);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('no-events includeDeletions', async () => {
|
|
350
|
+
const queryParams = { fromTime: 0, toTime: now, tags: ['RANDOM-123'], includeDeletions: true, modifiedSince: 0 };
|
|
351
|
+
function forEachEvent(event) { }
|
|
352
|
+
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
353
|
+
expect(0).to.equal(res.eventsCount);
|
|
354
|
+
expect(res.eventDeletionsCount).to.be.gte(0);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
if (typeof window === 'undefined') {
|
|
361
|
+
describe('Browser mock', function () {
|
|
362
|
+
beforeEach(function () {
|
|
363
|
+
const browser = new Browser();
|
|
364
|
+
browser.visit('./');
|
|
365
|
+
global.document = browser.document;
|
|
366
|
+
global.window = browser.window;
|
|
367
|
+
global.location = browser.location;
|
|
368
|
+
function fetch(...args) {
|
|
369
|
+
return browser.fetch(...args);
|
|
370
|
+
}
|
|
371
|
+
global.fetch = fetch;
|
|
372
|
+
global.URL = URL;
|
|
373
|
+
global.URLSearchParams = URLSearchParams;
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
afterEach(function () {
|
|
377
|
+
delete global.document;
|
|
378
|
+
delete global.window;
|
|
379
|
+
delete global.location;
|
|
380
|
+
delete global.fetch;
|
|
381
|
+
delete global.URL;
|
|
382
|
+
delete global.URLSearchParams;
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it(' without fetch', async () => {
|
|
386
|
+
delete global.fetch;
|
|
387
|
+
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
388
|
+
let eventsCount = 0;
|
|
389
|
+
function forEachEvent(event) { eventsCount++; }
|
|
390
|
+
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
391
|
+
expect(eventsCount).to.equal(res.eventsCount);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
xit(' with fetch', async () => {
|
|
395
|
+
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
396
|
+
let eventsCount = 0;
|
|
397
|
+
function forEachEvent(event) { eventsCount++; }
|
|
398
|
+
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
399
|
+
expect(eventsCount).to.equal(res.eventsCount);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
describe('Access Info', () => {
|
|
406
|
+
let newUser;
|
|
407
|
+
let accessInfoUser;
|
|
408
|
+
before(async () => {
|
|
409
|
+
newUser = (await conn.api([
|
|
410
|
+
{
|
|
411
|
+
method: "accesses.create", params: {
|
|
412
|
+
"name": "test",
|
|
413
|
+
"permissions": [
|
|
414
|
+
{
|
|
415
|
+
"streamId": "data",
|
|
416
|
+
"level": "read"
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
]))[0];
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
beforeEach(async () => {
|
|
425
|
+
const regexAPIandToken = /(.+):\/\/(.+)/gm;
|
|
426
|
+
const res = regexAPIandToken.exec(testData.apiEndpoint);
|
|
427
|
+
const apiEndpointWithToken = res[1] + '://' + newUser.access.token + '@' + res[2];
|
|
428
|
+
const newConn = new Pryv.Connection(apiEndpointWithToken);
|
|
429
|
+
accessInfoUser = await newConn.accessInfo();
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
after(async () => {
|
|
433
|
+
await conn.api([
|
|
434
|
+
{
|
|
435
|
+
method: "accesses.delete", params: {
|
|
436
|
+
"id": newUser.access.id
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
]);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('has same username', () => {
|
|
443
|
+
should.exist(accessInfoUser);
|
|
444
|
+
should.exist(accessInfoUser.name);
|
|
445
|
+
should.equal(newUser.access.name, accessInfoUser.name);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('has same token', () => {
|
|
449
|
+
should.exist(accessInfoUser.token);
|
|
450
|
+
should.equal(newUser.access.token, accessInfoUser.token);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const should = chai.should();
|
|
4
|
+
const expect = chai.expect;
|
|
5
|
+
const assert = chai.assert;
|
|
6
|
+
|
|
7
|
+
const chaiAsPromised = require('chai-as-promised');
|
|
8
|
+
chai.use(chaiAsPromised);
|
|
9
|
+
|
|
10
|
+
const testData = require('./test-data.js');
|
|
11
|
+
|
|
12
|
+
describe('Service', function () {
|
|
13
|
+
|
|
14
|
+
before(async function () {
|
|
15
|
+
this.timeout(5000);
|
|
16
|
+
await testData.prepare();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('info()', async () => {
|
|
20
|
+
const pryvService = new Pryv.Service(testData.serviceInfoUrl);
|
|
21
|
+
const res = await pryvService.info();
|
|
22
|
+
should.exist(res);
|
|
23
|
+
|
|
24
|
+
['access', 'api', 'register'].forEach((key) => {
|
|
25
|
+
should.exist(res[key]);
|
|
26
|
+
// all API endpoints should end with a '/';
|
|
27
|
+
res[key].slice(-1).should.equal('/');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('info() 2x ', async () => {
|
|
32
|
+
const pryvService = new Pryv.Service(testData.serviceInfoUrl);
|
|
33
|
+
const res = await pryvService.info();
|
|
34
|
+
should.exist(res);
|
|
35
|
+
should.exist(res.access);
|
|
36
|
+
const res2 = await pryvService.info();
|
|
37
|
+
should.exist(res2);
|
|
38
|
+
should.exist(res2.access);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('login()', async function () {
|
|
42
|
+
this.timeout(5000);
|
|
43
|
+
const pryvService = new Pryv.Service(testData.serviceInfoUrl);
|
|
44
|
+
const conn = await pryvService.login(testData.username, testData.password, 'jslib-test');
|
|
45
|
+
should.exist(conn);
|
|
46
|
+
should.exist(conn.token);
|
|
47
|
+
should.exist(conn.endpoint);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
it('assets()', async function() {
|
|
54
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
55
|
+
const assets = await pryvService.assets();
|
|
56
|
+
should.exist(assets);
|
|
57
|
+
|
|
58
|
+
//assets should be cached
|
|
59
|
+
const assets2 = await pryvService.assets();
|
|
60
|
+
expect(assets).to.equal(assets2);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('Errors', async function () {
|
|
64
|
+
|
|
65
|
+
it('Throw error with invalid content', async () => {
|
|
66
|
+
const service = new Pryv.Service(null, {});
|
|
67
|
+
await assert.isRejected(service.info(),
|
|
68
|
+
'Invalid data from service/info');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('Warn if no assets', async () => {
|
|
72
|
+
let serviceInfoCopy = Object.assign({}, testData.serviceInfo);
|
|
73
|
+
delete serviceInfoCopy.assets;
|
|
74
|
+
const pryvService = new Pryv.Service(null, serviceInfoCopy);
|
|
75
|
+
const assets = await pryvService.assets();
|
|
76
|
+
expect(assets).to.be.null;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('login() failed', async function () {
|
|
80
|
+
this.timeout(5000);
|
|
81
|
+
const pryvService = new Pryv.Service(testData.serviceInfoUrl);
|
|
82
|
+
await assert.isRejected(
|
|
83
|
+
pryvService.login(testData.username, 'bobby', 'jslib-test'),'The given username/password pair is invalid.');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const expect = chai.expect;
|
|
2
|
+
|
|
3
|
+
const testData = require('./test-data.js');
|
|
4
|
+
|
|
5
|
+
describe('ServiceAssets', function () {
|
|
6
|
+
let removeZombie = false;
|
|
7
|
+
|
|
8
|
+
before(async function () {
|
|
9
|
+
this.timeout(5000);
|
|
10
|
+
await testData.prepare();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
before(async () => {
|
|
14
|
+
if (typeof document !== 'undefined') return; // in browser
|
|
15
|
+
removeZombie = true;
|
|
16
|
+
const browser = new Browser();
|
|
17
|
+
browser.visit('./');
|
|
18
|
+
global.document = browser.document;
|
|
19
|
+
global.window = browser.window;
|
|
20
|
+
global.location = browser.location;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
after(async () => {
|
|
24
|
+
if (! removeZombie) return; // in browser
|
|
25
|
+
delete global.document;
|
|
26
|
+
delete global.window;
|
|
27
|
+
delete global.location;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('relativeURL()', async () => {
|
|
31
|
+
|
|
32
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
33
|
+
const assets = await pryvService.assets();
|
|
34
|
+
expect(assets.relativeURL('./toto')).to.eql(testData.serviceInfo.assets.definitions.replace('index.json', 'toto'));
|
|
35
|
+
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('setAllDefaults()', async () => {
|
|
39
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
40
|
+
const assets = await pryvService.assets();
|
|
41
|
+
await assets.setAllDefaults();
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('Load all external elements', async () => {
|
|
46
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
47
|
+
const assets = await pryvService.assets();
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
await assets.loginButtonLoadCSS();
|
|
51
|
+
await assets.loginButtonGetHTML();
|
|
52
|
+
await assets.loginButtonGetMessages();
|
|
53
|
+
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('.get() returns all assets', async () => {
|
|
57
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
58
|
+
const assets = await pryvService.assets();
|
|
59
|
+
const allAssets = await assets.get();
|
|
60
|
+
expect(allAssets.favicon.default.url).to.eql('favicon.ico');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('.get(keyPath) ', async () => {
|
|
64
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
65
|
+
const assets = await pryvService.assets();
|
|
66
|
+
const faviconUrl = await assets.get('favicon:default:url');
|
|
67
|
+
expect(faviconUrl).to.eql('favicon.ico');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('.getUrl(keyPath) ', async () => {
|
|
71
|
+
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
72
|
+
const assets = await pryvService.assets();
|
|
73
|
+
const faviconUrl = await assets.getUrl('favicon:default:url');
|
|
74
|
+
expect(faviconUrl).to.eql(testData.serviceInfo.assets.definitions.replace('index.json', 'favicon.ico'));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
|
package/test/Y.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry Point for WebPack to build test series to be run in browser
|
|
3
|
+
*/
|
|
4
|
+
//mocha.setup({ ignoreLeaks: true });
|
|
5
|
+
|
|
6
|
+
require('./utils.test.js');
|
|
7
|
+
require('./Connection.test.js');
|
|
8
|
+
require('./Service.test.js');
|
|
9
|
+
require('./ServiceAssets.test.js');
|
|
10
|
+
require('./Browser.test.js');
|
|
11
|
+
require('./Browser.AuthController.test.js');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>Pryv Javascrip Lib - Browser Tests </title>
|
|
6
|
+
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body>
|
|
10
|
+
<div id="mocha"></div>
|
|
11
|
+
<script src="https://unpkg.com/chai/chai.js"></script>
|
|
12
|
+
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
|
13
|
+
<script class="mocha-init">
|
|
14
|
+
mocha.setup('bdd');
|
|
15
|
+
mocha.checkLeaks();
|
|
16
|
+
</script>
|
|
17
|
+
<script src="../pryv.js"></script>
|
|
18
|
+
|
|
19
|
+
<!-- load code you want to test here -->
|
|
20
|
+
<!-- ------------------------------------ -->
|
|
21
|
+
<script type="text/javascript" src="browser-tests.js"></script>
|
|
22
|
+
<!-- ------------------------------------ -->
|
|
23
|
+
<!-- load your test files here -->
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
mocha.run();
|
|
28
|
+
</script>
|
|
29
|
+
</body>
|
|
30
|
+
|
|
31
|
+
</html>
|