Browse Source

test: clear api tokens on setup

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest
mertmit 2 years ago
parent
commit
d03adc0b3c
  1. 3
      packages/nocodb/.gitignore
  2. 23
      packages/nocodb/src/controllers/test/TestResetService/index.ts

3
packages/nocodb/.gitignore vendored

@ -38,4 +38,7 @@ lerna-debug.log*
# export
export/**
# test dbs
test_sakila_?.db
/docker/main.js

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

@ -4,7 +4,11 @@ import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2';
import Noco from '../../../Noco';
import User from '../../../models/User';
import NocoCache from '../../../cache/NocoCache';
import { CacheScope } from '../../../utils/globals';
import {
CacheDelDirection,
CacheScope,
MetaTable,
} from '../../../utils/globals';
import ProjectUser from '../../../models/ProjectUser';
import resetPgSakilaProject from './resetPgSakilaProject';
import resetMysqlSakilaProject from './resetMysqlSakilaProject';
@ -80,6 +84,7 @@ export class TestResetService {
try {
await removeAllProjectCreatedByTheTest(this.parallelId);
await removeAllPrefixedUsersExceptSuper(this.parallelId);
await removeAllTokensCreatedByTheTest();
} catch (e) {
console.log(`Error in cleaning up project: ${this.parallelId}`, e);
}
@ -174,6 +179,22 @@ const removeAllPrefixedUsersExceptSuper = async (parallelId: string) => {
}
};
const removeAllTokensCreatedByTheTest = async () => {
const tokens = 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,
});
}
};
// todo: Remove this once user deletion improvement PR is merged
const removeProjectUsersFromCache = async (project: Project) => {
const projectUsers: ProjectUser[] = await ProjectUser.getUsersList({

Loading…
Cancel
Save