generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest-setup.ts
More file actions
74 lines (64 loc) · 1.61 KB
/
vitest-setup.ts
File metadata and controls
74 lines (64 loc) · 1.61 KB
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
66
67
68
69
70
71
72
73
74
import { vi } from "vitest";
import type { Sql } from "postgres";
process.env = {
...process.env,
ENVIRONMENT_MODE: "production",
FRESHDESK_API_KEY: "test",
REDIS_URL: "test",
VAULT_FILE_STORAGE_BUCKET_NAME: "bucket",
ZITADEL_TRUSTED_DOMAIN: "http://test",
ZITADEL_URL: "http://test",
ZITADEL_APPLICATION_KEY: JSON.stringify({
keyId: "test",
clientId: "test",
key: "test",
}),
};
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const mockSql: Sql<any> = vi.fn().mockResolvedValue([]) as unknown as Sql<any>;
class PostgresConnectorMock {
executeSqlStatement() {
return mockSql;
}
}
vi.mock("@gcforms/connectors", async () => {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const actual: any = await vi.importActual("@gcforms/connectors");
return {
...actual,
PostgresConnector: {
defaultUsingPostgresConnectionUrlFromAwsSecret: vi.fn(
async () => new PostgresConnectorMock(),
),
},
};
});
vi.mock("./src/lib/logging/auditLogs", () => ({
auditLog: vi.fn(),
}));
vi.mock("got", () => ({
default: {
post: vi.fn().mockReturnValue({
json: vi.fn().mockResolvedValue({}),
}),
},
}));
vi.mock("node:crypto", async (importOriginal) => {
const original = (await importOriginal()) as object;
return {
...original,
createPublicKey: vi.fn(),
createPrivateKey: vi.fn(),
publicEncrypt: vi.fn(),
};
});
vi.mock("redis", () => {
const client = {
connect: vi.fn().mockResolvedValue({}),
quit: vi.fn(),
on: vi.fn().mockReturnThis(),
};
return {
createClient: vi.fn(() => client),
};
});