pryv 2.3.6 → 2.3.7
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/README.md +14 -0
- package/package.json +1 -1
- package/src/Service.js +19 -0
- package/src/ServiceAssets.js +2 -2
- package/test/Connection.test.js +12 -3
- package/test/Service.test.js +15 -1
package/README.md
CHANGED
|
@@ -696,6 +696,20 @@ just test <component> [...params]
|
|
|
696
696
|
- Extra parameters at the end are passed on to [Mocha](https://mochajs.org/) (default settings are defined in `.mocharc.js` files)
|
|
697
697
|
- Replace `test` with `test-debug`, `test-cover` for common presets
|
|
698
698
|
|
|
699
|
+
By default, tests are run against [Pryv Lab](https://www.pryv.com/pryvlab/) with service information URL `https://reg.pryv.me/service/info`.
|
|
700
|
+
|
|
701
|
+
To run the tests against another Pryv.io platform, set the `TEST_PRYVLIB_SERVICEINFO_URL` environment variable; for example:
|
|
702
|
+
|
|
703
|
+
```bash
|
|
704
|
+
TEST_PRYVLIB_SERVICEINFO_URL="https://reg.${DOMAIN}/service/info" just test all
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
To run the tests against _in-development_ API server components (e.g. open-source or Entreprise), set `TEST_PRYVLIB_DNSLESS_URL`; for example:
|
|
708
|
+
|
|
709
|
+
```bash
|
|
710
|
+
TEST_PRYVLIB_DNSLESS_URL="http://l.rec.la:3000/ just test all
|
|
711
|
+
```
|
|
712
|
+
|
|
699
713
|
#### Browser
|
|
700
714
|
|
|
701
715
|
Assuming browser files have been built (see above):
|
package/package.json
CHANGED
package/src/Service.js
CHANGED
|
@@ -68,6 +68,25 @@ class Service {
|
|
|
68
68
|
return this._serviceInfo;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Check if a service supports High Frequency Data Sets
|
|
73
|
+
* @return true if yes
|
|
74
|
+
*/
|
|
75
|
+
async supportsHF () {
|
|
76
|
+
const infos = await this.info();
|
|
77
|
+
return (infos.features == null || infos.features.noHF !== true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Check if a service has username in the hostname or in the path of the api
|
|
82
|
+
* @return true if the service does not rely on DNS to find a host related to a username
|
|
83
|
+
*/
|
|
84
|
+
async isDnsLess () {
|
|
85
|
+
const infos = await this.info();
|
|
86
|
+
const hostname = infos.api.split('/')[2];
|
|
87
|
+
return !hostname.includes('{username}');
|
|
88
|
+
}
|
|
89
|
+
|
|
71
90
|
/**
|
|
72
91
|
* @private
|
|
73
92
|
* @param {ServiceInfo} serviceInfo
|
package/src/ServiceAssets.js
CHANGED
|
@@ -36,7 +36,7 @@ class ServiceAssets {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* get a value from path separated by `:`
|
|
39
|
-
*
|
|
39
|
+
* example of key `lib-js:buttonSignIn`
|
|
40
40
|
* @param {string} [keyPath] if null, will return the all assets
|
|
41
41
|
*/
|
|
42
42
|
get (keyPath) {
|
|
@@ -53,7 +53,7 @@ class ServiceAssets {
|
|
|
53
53
|
/**
|
|
54
54
|
* get an Url from path separated by `:`
|
|
55
55
|
* identical to doing assets.relativeURL(assets.get(keyPath))
|
|
56
|
-
*
|
|
56
|
+
* example of key `lib-js:buttonSignIn`
|
|
57
57
|
* @param {string} [keyPath] if null, will return the all assets
|
|
58
58
|
*/
|
|
59
59
|
getUrl (keyPath) {
|
package/test/Connection.test.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
|
-
/* global describe, it, xit, before, after, beforeEach, afterEach, expect, Browser, pryv,
|
|
5
|
+
/* global describe, it, xit, before, after, beforeEach, afterEach, expect, Browser, pryv, Blob, FormData */
|
|
6
6
|
/* eslint-disable no-unused-expressions */
|
|
7
7
|
|
|
8
8
|
const { URL, URLSearchParams } = require('universal-url');
|
|
9
9
|
const cuid = require('cuid');
|
|
10
|
+
const testData = require('../../../test/test-data');
|
|
10
11
|
|
|
11
12
|
let conn = null;
|
|
12
13
|
|
|
@@ -261,7 +262,13 @@ describe('Connection', () => {
|
|
|
261
262
|
});
|
|
262
263
|
});
|
|
263
264
|
|
|
264
|
-
describe('HF events', ()
|
|
265
|
+
describe('HF events', async function () {
|
|
266
|
+
before(async function () {
|
|
267
|
+
if (!await conn.service.supportsHF()) {
|
|
268
|
+
this.skip();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
265
272
|
it('Add data points to HF event', async () => {
|
|
266
273
|
const res = await conn.api([{
|
|
267
274
|
method: 'events.create',
|
|
@@ -302,8 +309,10 @@ describe('Connection', () => {
|
|
|
302
309
|
|
|
303
310
|
describe('API', () => {
|
|
304
311
|
it('endpoint property', async () => {
|
|
312
|
+
const [protocol, hostPath] = testData.serviceInfo.api.split('://');
|
|
313
|
+
const challenge = protocol + '://' + conn.token + '@' + hostPath.replace('{username}', testData.username);
|
|
305
314
|
const apiEndpoint = conn.apiEndpoint;
|
|
306
|
-
expect(apiEndpoint
|
|
315
|
+
expect(apiEndpoint).to.equal(challenge);
|
|
307
316
|
});
|
|
308
317
|
});
|
|
309
318
|
|
package/test/Service.test.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
/* global describe, it, before, expect, pryv, testData */
|
|
6
6
|
/* eslint-disable no-unused-expressions */
|
|
7
7
|
|
|
8
|
+
const isNode = (typeof window === 'undefined');
|
|
9
|
+
|
|
8
10
|
describe('Service', function () {
|
|
9
11
|
before(async function () {
|
|
10
12
|
this.timeout(5000);
|
|
@@ -75,7 +77,19 @@ describe('Service', function () {
|
|
|
75
77
|
it('login() failed on wrong username', async function () {
|
|
76
78
|
this.timeout(5000);
|
|
77
79
|
const pryvService = new pryv.Service(testData.serviceInfoUrl);
|
|
78
|
-
|
|
80
|
+
// check if username is in path or domain
|
|
81
|
+
try {
|
|
82
|
+
await pryvService.login('wrong-username', 'bobby', 'jslib-test');
|
|
83
|
+
} catch (error) {
|
|
84
|
+
let errorMessage = isNode ? 'getaddrinfo ENOTFOUND wrong' : 'Request has been terminated';
|
|
85
|
+
if (await pryvService.isDnsLess()) {
|
|
86
|
+
errorMessage = 'Unknown user "wrong-username"';
|
|
87
|
+
}
|
|
88
|
+
const receivedMessage = error.message.slice(0, errorMessage.length);
|
|
89
|
+
expect(receivedMessage).to.be.equal(errorMessage);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Should fail');
|
|
79
93
|
});
|
|
80
94
|
});
|
|
81
95
|
});
|