@@ -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");
0 commit comments