pryv 2.2.0 → 2.3.2

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