Browse Source

test: support parallel for api token test

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest
mertmit 2 years ago
parent
commit
e16ee362b3
  1. 31
      packages/nocodb/src/controllers/test/TestResetService/index.ts
  2. 5
      tests/playwright/tests/db/accountTokenManagement.spec.ts

31
packages/nocodb/src/controllers/test/TestResetService/index.ts

@ -13,6 +13,7 @@ import ProjectUser from '../../../models/ProjectUser';
import resetPgSakilaProject from './resetPgSakilaProject'; import resetPgSakilaProject from './resetPgSakilaProject';
import resetMysqlSakilaProject from './resetMysqlSakilaProject'; import resetMysqlSakilaProject from './resetMysqlSakilaProject';
import resetMetaSakilaSqliteProject from './resetMetaSakilaSqliteProject'; import resetMetaSakilaSqliteProject from './resetMetaSakilaSqliteProject';
import type ApiToken from '../../../models/ApiToken';
const workerStatus = {}; const workerStatus = {};
@ -84,7 +85,7 @@ export class TestResetService {
try { try {
await removeAllProjectCreatedByTheTest(this.parallelId); await removeAllProjectCreatedByTheTest(this.parallelId);
await removeAllPrefixedUsersExceptSuper(this.parallelId); await removeAllPrefixedUsersExceptSuper(this.parallelId);
await removeAllTokensCreatedByTheTest(); await removeAllTokensCreatedByTheTest(this.parallelId);
} catch (e) { } catch (e) {
console.log(`Error in cleaning up project: ${this.parallelId}`, e); console.log(`Error in cleaning up project: ${this.parallelId}`, e);
} }
@ -179,19 +180,25 @@ const removeAllPrefixedUsersExceptSuper = async (parallelId: string) => {
} }
}; };
const removeAllTokensCreatedByTheTest = async () => { const removeAllTokensCreatedByTheTest = async (parallelId: string) => {
const tokens = await Noco.ncMeta.metaList(null, null, MetaTable.API_TOKENS); const tokens: ApiToken[] = await Noco.ncMeta.metaList(
null,
null,
MetaTable.API_TOKENS,
);
for (const token of tokens) { for (const token of tokens) {
await NocoCache.deepDel( if (token.description.startsWith(`nc_test_${parallelId}`)) {
CacheScope.API_TOKEN, await NocoCache.deepDel(
`${CacheScope.API_TOKEN}:${token.token}`, CacheScope.API_TOKEN,
CacheDelDirection.CHILD_TO_PARENT, `${CacheScope.API_TOKEN}:${token.token}`,
); CacheDelDirection.CHILD_TO_PARENT,
);
await Noco.ncMeta.metaDelete(null, null, MetaTable.API_TOKENS, {
token: token.token, await Noco.ncMeta.metaDelete(null, null, MetaTable.API_TOKENS, {
}); token: token.token,
});
}
} }
}; };

5
tests/playwright/tests/db/accountTokenManagement.spec.ts

@ -17,8 +17,9 @@ test.describe('User roles', () => {
test('Create and Delete token', async () => { test('Create and Delete token', async () => {
test.slow(); test.slow();
const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0';
await accountTokenPage.goto(); await accountTokenPage.goto();
await accountTokenPage.createToken({ description: 'test token' }); await accountTokenPage.createToken({ description: `nc_test_${parallelId} test token` });
await accountTokenPage.deleteToken({ description: 'test token' }); await accountTokenPage.deleteToken({ description: `nc_test_${parallelId} test token` });
}); });
}); });

Loading…
Cancel
Save