From 1fea2158527db45c6dd15ebe2aa19205fd95bfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Thu, 28 Apr 2022 14:32:55 +0200 Subject: [PATCH] test(server default apps): expand default apps update test with token scopes checks --- .../server/modules/auth/tests/apps.spec.js | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/server/modules/auth/tests/apps.spec.js b/packages/server/modules/auth/tests/apps.spec.js index 2ad14a73b..25bf94c9c 100644 --- a/packages/server/modules/auth/tests/apps.spec.js +++ b/packages/server/modules/auth/tests/apps.spec.js @@ -1,10 +1,9 @@ /* istanbul ignore file */ const expect = require('chai').expect -const appRoot = require('app-root-path') -const { createUser } = require(`${appRoot}/modules/core/services/users`) -const { validateToken } = require(`${appRoot}/modules/core/services/tokens`) -const { beforeEachContext } = require(`${appRoot}/test/hooks`) +const { createUser } = require(`@/modules/core/services/users`) +const { validateToken } = require(`@/modules/core/services/tokens`) +const { beforeEachContext } = require(`@/test/hooks`) const { getApp, getAllPublicApps, @@ -19,6 +18,7 @@ const { const { Scopes } = require('@/modules/core/helpers/mainConstants') const { updateDefaultApp } = require('@/modules/auth/defaultApps') +const knex = require('@/db/knex') describe('Services @apps-services', () => { const actor = { @@ -243,14 +243,20 @@ describe('Services @apps-services', () => { // We now have one unused access code, an api token and a refresh token. // Proceed to update the app: const existingApp = await getApp({ id: speckleAppId }) + + const newScopes = [Scopes.Streams.Write, Scopes.Users.Read] + await updateDefaultApp( { name: 'updated test application', id: speckleAppId, - scopes: [Scopes.Streams.Write, Scopes.Users.Read] + scopes: newScopes }, existingApp ) + const updatedApp = await getApp({ id: speckleAppId }) + + expect(updatedApp.scopes.map((s) => s.name)).to.equalInAnyOrder(newScopes) const validationResponse = await validateToken(apiTokenResponse.token) expect(validationResponse.valid).to.equal(true) @@ -271,6 +277,19 @@ describe('Services @apps-services', () => { }) expect(appToken.token).to.exist expect(appToken.refreshToken).to.exist + + const apiTokens = await knex('user_server_app_tokens') + .join( + 'token_scopes', + 'user_server_app_tokens.tokenId', + '=', + 'token_scopes.tokenId' + ) + .where({ + appId: speckleAppId + }) + + expect(newScopes).to.include.members(apiTokens.map((t) => t.scopeName)) }) })