From e16ee362b3f199ba5afd04ff13af39b502cdc617 Mon Sep 17 00:00:00 2001 From: mertmit Date: Mon, 8 May 2023 13:11:40 +0300 Subject: [PATCH] test: support parallel for api token test Signed-off-by: mertmit --- .../test/TestResetService/index.ts | 31 ++++++++++++------- .../tests/db/accountTokenManagement.spec.ts | 5 +-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/nocodb/src/controllers/test/TestResetService/index.ts b/packages/nocodb/src/controllers/test/TestResetService/index.ts index a4003a0062..6a5d67ec46 100644 --- a/packages/nocodb/src/controllers/test/TestResetService/index.ts +++ b/packages/nocodb/src/controllers/test/TestResetService/index.ts @@ -13,6 +13,7 @@ import ProjectUser from '../../../models/ProjectUser'; import resetPgSakilaProject from './resetPgSakilaProject'; import resetMysqlSakilaProject from './resetMysqlSakilaProject'; import resetMetaSakilaSqliteProject from './resetMetaSakilaSqliteProject'; +import type ApiToken from '../../../models/ApiToken'; const workerStatus = {}; @@ -84,7 +85,7 @@ export class TestResetService { try { await removeAllProjectCreatedByTheTest(this.parallelId); await removeAllPrefixedUsersExceptSuper(this.parallelId); - await removeAllTokensCreatedByTheTest(); + await removeAllTokensCreatedByTheTest(this.parallelId); } catch (e) { console.log(`Error in cleaning up project: ${this.parallelId}`, e); } @@ -179,19 +180,25 @@ const removeAllPrefixedUsersExceptSuper = async (parallelId: string) => { } }; -const removeAllTokensCreatedByTheTest = async () => { - const tokens = await Noco.ncMeta.metaList(null, null, MetaTable.API_TOKENS); +const removeAllTokensCreatedByTheTest = async (parallelId: string) => { + const tokens: ApiToken[] = await Noco.ncMeta.metaList( + null, + null, + MetaTable.API_TOKENS, + ); for (const token of tokens) { - await NocoCache.deepDel( - CacheScope.API_TOKEN, - `${CacheScope.API_TOKEN}:${token.token}`, - CacheDelDirection.CHILD_TO_PARENT, - ); - - await Noco.ncMeta.metaDelete(null, null, MetaTable.API_TOKENS, { - token: token.token, - }); + if (token.description.startsWith(`nc_test_${parallelId}`)) { + await NocoCache.deepDel( + CacheScope.API_TOKEN, + `${CacheScope.API_TOKEN}:${token.token}`, + CacheDelDirection.CHILD_TO_PARENT, + ); + + await Noco.ncMeta.metaDelete(null, null, MetaTable.API_TOKENS, { + token: token.token, + }); + } } }; diff --git a/tests/playwright/tests/db/accountTokenManagement.spec.ts b/tests/playwright/tests/db/accountTokenManagement.spec.ts index 10de551fd9..1cd9ace2eb 100644 --- a/tests/playwright/tests/db/accountTokenManagement.spec.ts +++ b/tests/playwright/tests/db/accountTokenManagement.spec.ts @@ -17,8 +17,9 @@ test.describe('User roles', () => { test('Create and Delete token', async () => { test.slow(); + const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0'; await accountTokenPage.goto(); - await accountTokenPage.createToken({ description: 'test token' }); - await accountTokenPage.deleteToken({ description: 'test token' }); + await accountTokenPage.createToken({ description: `nc_test_${parallelId} test token` }); + await accountTokenPage.deleteToken({ description: `nc_test_${parallelId} test token` }); }); });