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