-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathsetup.ts
65 lines (57 loc) · 1.84 KB
/
setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as matchers from 'jest-extended';
import '../src/config';
import createOrGetConnection from '../src/db';
import { remoteConfig } from '../src/remoteConfig';
expect.extend(matchers);
global.structuredClone = (v) => JSON.parse(JSON.stringify(v));
jest.mock('../src/growthbook', () => ({
...(jest.requireActual('../src/growthbook') as Record<string, unknown>),
loadFeatures: jest.fn(),
getEncryptedFeatures: jest.fn(),
}));
jest.mock('../src/remoteConfig', () => ({
...(jest.requireActual('../src/remoteConfig') as Record<string, unknown>),
remoteConfig: {
init: jest.fn(),
vars: {
vordrWords: [
'vordrwillcatchyou',
'andvordrwillhavefun',
'and vordr will win',
],
vordrIps: ['192.0.2.0/24', '198.51.100.0/24', '203.0.113.0/24'],
ignoredWorkEmailDomains: ['igored.com', 'ignored.org'],
rateLimitReputationThreshold: 1,
pricingIds: { pricingGift: 'yearly' },
fees: {
transfer: 5,
},
enableBalance: true,
} as typeof remoteConfig.vars,
validLanguages: {
en: 'English',
es: 'Spanish',
fr: 'French',
de: 'German',
'zh-Hans': 'ChineseSimplified',
},
},
}));
const cleanDatabase = async (): Promise<void> => {
await remoteConfig.init();
const con = await createOrGetConnection();
for (const entity of con.entityMetadatas) {
const repository = con.getRepository(entity.name);
if (repository.metadata.tableType === 'view') continue;
await repository.query(`DELETE
FROM "${entity.tableName}";`);
for (const column of entity.primaryColumns) {
if (column.generationStrategy === 'increment') {
await repository.query(
`ALTER SEQUENCE ${entity.tableName}_${column.databaseName}_seq RESTART WITH 1`,
);
}
}
}
};
beforeEach(cleanDatabase);