Skip to content

Commit a2d0759

Browse files
committed
Adding more tests for application
1 parent 6b0b47b commit a2d0759

8 files changed

Lines changed: 247 additions & 16 deletions

File tree

docs/hds-lib.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/hds-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/tests-browser.js

Lines changed: 128 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21173,7 +21173,7 @@ async function createAppStreams (app) {
2117321173
}
2117421174
if (!masterFound) { // check that app has "manage" level on baseStreamId
2117521175
const baseStreamFound = infos.permissions.find(p => (p.streamId === app.baseStreamId && p.level === 'manage'));
21176-
if (!baseStreamFound) throw new Error(`Application with "app" type of access requires (streamId = '${app.baseStreamId}', level = "manage") or master access`);
21176+
if (!baseStreamFound) throw new Error(`Application with "app" type of access requires (streamId = "${app.baseStreamId}", level = "manage") or master access`);
2117721177
}
2117821178
}
2117921179
// get streamStructure
@@ -21188,9 +21188,6 @@ async function createAppStreams (app) {
2118821188
}
2118921189
// not found create streams
2119021190
if (!found) {
21191-
if (app.appName == null) {
21192-
throw new Error('Cannot create app stream if not "appName" has been given');
21193-
}
2119421191
if (!isPersonalOrMaster) {
2119521192
throw new Error('Token has not sufficient right to create App streams. Create them upfront');
2119621193
}
@@ -22430,6 +22427,129 @@ function deepFreeze (object) {
2243022427
}
2243122428

2243222429

22430+
/***/ }),
22431+
22432+
/***/ "./tests/applicationClass.test.js":
22433+
/*!****************************************!*\
22434+
!*** ./tests/applicationClass.test.js ***!
22435+
\****************************************/
22436+
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
22437+
22438+
/* eslint-env mocha */
22439+
const { assert } = __webpack_require__(/*! ./test-utils/deps-node */ "./tests/test-utils/deps-browser.js");
22440+
const { createUserAndPermissions } = __webpack_require__(/*! ./test-utils/pryvService */ "./tests/test-utils/pryvService.js");
22441+
const Application = __webpack_require__(/*! ../src/appTemplates/Application */ "./src/appTemplates/Application.js");
22442+
22443+
describe('[APAX] Application class', () => {
22444+
const baseStreamId = 'application-class';
22445+
const appName = 'application-app';
22446+
let user;
22447+
before(async () => {
22448+
const initialStreams = [{ id: 'applications', name: 'Applications' }, { id: baseStreamId, name: appName, parentId: 'applications' }];
22449+
const permissionsManager = [{ streamId: baseStreamId, level: 'manage' }];
22450+
user = await createUserAndPermissions(null, permissionsManager, initialStreams, appName);
22451+
});
22452+
22453+
it('[APAI] Application extension', async () => {
22454+
class Dummy extends Application { }
22455+
22456+
try {
22457+
await Dummy.newFromApiEndpoint(baseStreamId, user.appApiEndpoint, appName);
22458+
throw new Error('Should throw an error');
22459+
} catch (e) {
22460+
assert.equal(e.message, 'appSettings must be implemented');
22461+
}
22462+
22463+
try {
22464+
// eslint-disable-next-line no-new
22465+
new Dummy('u', user.appApiEndpoint, appName);
22466+
throw new Error('Should throw an error');
22467+
} catch (e) {
22468+
assert.equal(e.message, 'Missing or too short baseStreamId');
22469+
}
22470+
});
22471+
22472+
it('[APAA] Application name form accessInfo fails in not in settings', () => {
22473+
class Dummy extends Application {
22474+
get appSettings () {
22475+
return { };
22476+
}
22477+
}
22478+
22479+
try {
22480+
// eslint-disable-next-line no-new
22481+
new Dummy(baseStreamId, user.appApiEndpoint);
22482+
throw new Error('Should throw an error');
22483+
} catch (e) {
22484+
assert.equal(e.message, 'appName must be given unless appSettings.appNameFromAccessInfo = true');
22485+
}
22486+
});
22487+
22488+
it('[APAB] Application name form accessInfo', async () => {
22489+
class Dummy2 extends Application {
22490+
get appSettings () {
22491+
return {
22492+
appNameFromAccessInfo: true
22493+
};
22494+
}
22495+
}
22496+
22497+
const dummy2 = await Dummy2.newFromApiEndpoint(baseStreamId, user.appApiEndpoint);
22498+
assert.ok(dummy2, 'if appSettings.appNameFromAccessInfo = true appName is not required');
22499+
});
22500+
22501+
it('[APAC] Application should throw error if baseStream is not accessible', async () => {
22502+
class Dummy extends Application {
22503+
get appSettings () {
22504+
return { };
22505+
}
22506+
}
22507+
22508+
try {
22509+
// eslint-disable-next-line no-new
22510+
await Dummy.newFromApiEndpoint('uuuu', user.appApiEndpoint, appName);
22511+
throw new Error('Should throw an error');
22512+
} catch (e) {
22513+
assert.equal(e.message, 'Application with "app" type of access requires (streamId = "uuuu", level = "manage") or master access');
22514+
}
22515+
});
22516+
22517+
it('[APAD] Application should throw error if personaToken are not explicity allowed', async () => {
22518+
class Dummy extends Application {
22519+
get appSettings () {
22520+
return { };
22521+
}
22522+
}
22523+
22524+
try {
22525+
// eslint-disable-next-line no-new
22526+
await Dummy.newFromApiEndpoint('uuuu', user.personalApiEndpoint, appName);
22527+
throw new Error('Should throw an error');
22528+
} catch (e) {
22529+
assert.equal(e.message, 'Application should not use a personal token');
22530+
}
22531+
});
22532+
22533+
it('[APAE] Application should throw error if master token not provided and required', async () => {
22534+
class Dummy extends Application {
22535+
get appSettings () {
22536+
return {
22537+
mustBemaster: true
22538+
};
22539+
}
22540+
}
22541+
22542+
try {
22543+
// eslint-disable-next-line no-new
22544+
await Dummy.newFromApiEndpoint('uuuu', user.appApiEndpoint, appName);
22545+
throw new Error('Should throw an error');
22546+
} catch (e) {
22547+
assert.equal(e.message, 'Application with "app" type of access requires "master" token (streamId = "*", level = "manage")');
22548+
}
22549+
});
22550+
});
22551+
22552+
2243322553
/***/ }),
2243422554

2243522555
/***/ "./tests/apptemplates.test.js":
@@ -22565,7 +22685,6 @@ describe('[APTX] appTemplates', function () {
2256522685
});
2256622686

2256722687
describe('[APIX] Collector invite flows & internals', () => {
22568-
2256922688
it('[APTI] Collector invite accept full flow testing internal', async () => {
2257022689
const newCollector = await appManaging.createCollector('Invite test 1');
2257122690
assert(newCollector.statusCode, 'draft');
@@ -22687,7 +22806,7 @@ describe('[APTX] appTemplates', function () {
2268722806
assert.equal(invites2[0].status, 'active');
2268822807
});
2268922808

22690-
it('[APIA] Collector invite accept', async () => {
22809+
it('[APIA] Collector invite accept', async () => {
2269122810
const { collector, collectorClient, invite } = await helperNewInvite(appManaging, appClient, 'APIA');
2269222811
assert.ok(invite.status, 'pending');
2269322812
await collectorClient.accept();
@@ -22719,7 +22838,7 @@ describe('[APTX] appTemplates', function () {
2271922838
// connection is cached and valid
2272022839
const connection = invite.connection;
2272122840
const inviteInfo = await connection.accessInfo();
22722-
assert.ok(!!inviteInfo.clientData.hdsCollectorClient)
22841+
assert.ok(!!inviteInfo.clientData.hdsCollectorClient);
2272322842
});
2272422843

2272522844
it('[APTR] Collector invite refuse', async () => {
@@ -22808,7 +22927,7 @@ describe('[APTX] appTemplates', function () {
2280822927
await AppClientAccount.newFromApiEndpoint(baseStreamIdClient, clientUserNonMaster.appApiEndpoint, appClientName);
2280922928
throw new Error('Should throw error');
2281022929
} catch (e) {
22811-
assert.equal(e.message, `Application with "app" type of access requires (streamId = '${baseStreamIdClient}', level = "manage") or master access`);
22930+
assert.equal(e.message, `Application with "app" type of access requires (streamId = "${baseStreamIdClient}", level = "manage") or master access`);
2281222931
}
2281322932
// personal
2281422933
const appClient = await AppClientAccount.newFromApiEndpoint(baseStreamIdClient, clientUser.apiEndpoint, appClientName);
@@ -23767,6 +23886,7 @@ var __webpack_exports__ = {};
2376723886
* Hook for webpack to build browser test-suite
2376823887
* Add new tests here
2376923888
*/
23889+
__webpack_require__(/*! ./applicationClass.test */ "./tests/applicationClass.test.js");
2377023890
__webpack_require__(/*! ./apptemplates.test */ "./tests/apptemplates.test.js");
2377123891
__webpack_require__(/*! ./hdsModel.test */ "./tests/hdsModel.test.js");
2377223892
__webpack_require__(/*! ./libSettings.test */ "./tests/libSettings.test.js");

docs/tests-browser.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/appTemplates/Application.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async function createAppStreams (app) {
120120
}
121121
if (!masterFound) { // check that app has "manage" level on baseStreamId
122122
const baseStreamFound = infos.permissions.find(p => (p.streamId === app.baseStreamId && p.level === 'manage'));
123-
if (!baseStreamFound) throw new Error(`Application with "app" type of access requires (streamId = '${app.baseStreamId}', level = "manage") or master access`);
123+
if (!baseStreamFound) throw new Error(`Application with "app" type of access requires (streamId = "${app.baseStreamId}", level = "manage") or master access`);
124124
}
125125
}
126126
// get streamStructure
@@ -135,9 +135,6 @@ async function createAppStreams (app) {
135135
}
136136
// not found create streams
137137
if (!found) {
138-
if (app.appName == null) {
139-
throw new Error('Cannot create app stream if not "appName" has been given');
140-
}
141138
if (!isPersonalOrMaster) {
142139
throw new Error('Token has not sufficient right to create App streams. Create them upfront');
143140
}

tests/applicationClass.test.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* eslint-env mocha */
2+
const { assert } = require('./test-utils/deps-node');
3+
const { createUserAndPermissions } = require('./test-utils/pryvService');
4+
const Application = require('../src/appTemplates/Application');
5+
6+
describe('[APAX] Application class', () => {
7+
const baseStreamId = 'application-class';
8+
const appName = 'application-app';
9+
let user;
10+
before(async () => {
11+
const initialStreams = [{ id: 'applications', name: 'Applications' }, { id: baseStreamId, name: appName, parentId: 'applications' }];
12+
const permissionsManager = [{ streamId: baseStreamId, level: 'manage' }];
13+
user = await createUserAndPermissions(null, permissionsManager, initialStreams, appName);
14+
});
15+
16+
it('[APAI] Application extension', async () => {
17+
class Dummy extends Application { }
18+
19+
try {
20+
await Dummy.newFromApiEndpoint(baseStreamId, user.appApiEndpoint, appName);
21+
throw new Error('Should throw an error');
22+
} catch (e) {
23+
assert.equal(e.message, 'appSettings must be implemented');
24+
}
25+
26+
try {
27+
// eslint-disable-next-line no-new
28+
new Dummy('u', user.appApiEndpoint, appName);
29+
throw new Error('Should throw an error');
30+
} catch (e) {
31+
assert.equal(e.message, 'Missing or too short baseStreamId');
32+
}
33+
});
34+
35+
it('[APAA] Application name form accessInfo fails in not in settings', () => {
36+
class Dummy extends Application {
37+
get appSettings () {
38+
return { };
39+
}
40+
}
41+
42+
try {
43+
// eslint-disable-next-line no-new
44+
new Dummy(baseStreamId, user.appApiEndpoint);
45+
throw new Error('Should throw an error');
46+
} catch (e) {
47+
assert.equal(e.message, 'appName must be given unless appSettings.appNameFromAccessInfo = true');
48+
}
49+
});
50+
51+
it('[APAB] Application name form accessInfo', async () => {
52+
class Dummy2 extends Application {
53+
get appSettings () {
54+
return {
55+
appNameFromAccessInfo: true
56+
};
57+
}
58+
}
59+
60+
const dummy2 = await Dummy2.newFromApiEndpoint(baseStreamId, user.appApiEndpoint);
61+
assert.ok(dummy2, 'if appSettings.appNameFromAccessInfo = true appName is not required');
62+
});
63+
64+
it('[APAC] Application should throw error if baseStream is not accessible', async () => {
65+
class Dummy extends Application {
66+
get appSettings () {
67+
return { };
68+
}
69+
}
70+
71+
try {
72+
// eslint-disable-next-line no-new
73+
await Dummy.newFromApiEndpoint('uuuu', user.appApiEndpoint, appName);
74+
throw new Error('Should throw an error');
75+
} catch (e) {
76+
assert.equal(e.message, 'Application with "app" type of access requires (streamId = "uuuu", level = "manage") or master access');
77+
}
78+
});
79+
80+
it('[APAD] Application should throw error if personaToken are not explicity allowed', async () => {
81+
class Dummy extends Application {
82+
get appSettings () {
83+
return { };
84+
}
85+
}
86+
87+
try {
88+
// eslint-disable-next-line no-new
89+
await Dummy.newFromApiEndpoint('uuuu', user.personalApiEndpoint, appName);
90+
throw new Error('Should throw an error');
91+
} catch (e) {
92+
assert.equal(e.message, 'Application should not use a personal token');
93+
}
94+
});
95+
96+
it('[APAE] Application should throw error if master token not provided and required', async () => {
97+
class Dummy extends Application {
98+
get appSettings () {
99+
return {
100+
mustBemaster: true
101+
};
102+
}
103+
}
104+
105+
try {
106+
// eslint-disable-next-line no-new
107+
await Dummy.newFromApiEndpoint('uuuu', user.appApiEndpoint, appName);
108+
throw new Error('Should throw an error');
109+
} catch (e) {
110+
assert.equal(e.message, 'Application with "app" type of access requires "master" token (streamId = "*", level = "manage")');
111+
}
112+
});
113+
});

tests/apptemplates.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ describe('[APTX] appTemplates', function () {
367367
await AppClientAccount.newFromApiEndpoint(baseStreamIdClient, clientUserNonMaster.appApiEndpoint, appClientName);
368368
throw new Error('Should throw error');
369369
} catch (e) {
370-
assert.equal(e.message, `Application with "app" type of access requires (streamId = '${baseStreamIdClient}', level = "manage") or master access`);
370+
assert.equal(e.message, `Application with "app" type of access requires (streamId = "${baseStreamIdClient}", level = "manage") or master access`);
371371
}
372372
// personal
373373
const appClient = await AppClientAccount.newFromApiEndpoint(baseStreamIdClient, clientUser.apiEndpoint, appClientName);

tests/browser-tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Hook for webpack to build browser test-suite
33
* Add new tests here
44
*/
5+
require('./applicationClass.test');
56
require('./apptemplates.test');
67
require('./hdsModel.test');
78
require('./libSettings.test');

0 commit comments

Comments
 (0)