Skip to content

Commit 8928cd1

Browse files
committed
Update test structure
1 parent 780f935 commit 8928cd1

File tree

16 files changed

+109
-2
lines changed

16 files changed

+109
-2
lines changed

backend/api/jest.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
5+
rootDir: '.',
6+
testMatch: [
7+
"<rootDir>/tests/**/*.test.ts",
8+
"<rootDir>/tests/**/*.spec.ts"
9+
],
10+
11+
moduleNameMapper: {
12+
"^api/(.*)$": "<rootDir>/src/$1",
13+
"^shared/(.*)$": "<rootDir>/../shared/src/$1",
14+
"^common/(.*)$": "<rootDir>/../../common/src/$1",
15+
"^email/(.*)$": "<rootDir>/../email/emails/$1"
16+
},
17+
18+
moduleFileExtensions: ["ts", "js", "json"],
19+
clearMocks: true,
20+
21+
globals: {
22+
'ts-jest': {
23+
tsconfig: '<rootDir>/tsconfig.json'
24+
}
25+
}
26+
};

backend/api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"verify": "yarn --cwd=../.. verify",
2121
"verify:dir": "npx eslint . --max-warnings 0",
2222
"regen-types": "cd ../supabase && make ENV=prod regen-types",
23-
"regen-types-dev": "cd ../supabase && make ENV=dev regen-types-dev"
23+
"regen-types-dev": "cd ../supabase && make ENV=dev regen-types-dev",
24+
"test": "jest"
2425
},
2526
"engines": {
2627
"node": ">=20.0.0"

backend/api/tests/integration/.keep

Whitespace-only changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { getUser } from "api/get-user";
2+
import { createSupabaseDirectClient } from "shared/supabase/init";
3+
import { toUserAPIResponse } from "common/api/user-types";
4+
import { convertUser } from "common/supabase/users";
5+
6+
jest.mock("shared/supabase/init");
7+
jest.mock("common/supabase/users");
8+
jest.mock("common/api/utils");
9+
describe('getUser', () =>{
10+
let mockPg: any;
11+
12+
beforeEach(() => {
13+
mockPg = {
14+
oneOrNone: jest.fn(),
15+
};
16+
(createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg);
17+
18+
jest.clearAllMocks();
19+
});
20+
21+
it('should fetch user successfully by id', async () => {
22+
const mockDbUser = {
23+
created_time: '2025-11-11T16:42:05.188Z',
24+
data: { link: {}, avatarUrl: "", isBannedFromPosting: false },
25+
id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP',
26+
name: 'Franklin Buckridge',
27+
name_username_vector: "'buckridg':2,4 'franklin':1,3",
28+
username: 'Franky_Buck'
29+
};
30+
const mockConvertedUser = {
31+
created_time: new Date(),
32+
id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP',
33+
name: 'Franklin Buckridge',
34+
name_username_vector: "'buckridg':2,4 'franklin':1,3",
35+
username: 'Franky_Buck'
36+
37+
};
38+
const mockApiResponse = {
39+
created_time: '2025-11-11T16:42:05.188Z',
40+
data: { link: {}, avatarUrl: "", isBannedFromPosting: false },
41+
id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP',
42+
name: 'Franklin Buckridge',
43+
username: 'Franky_Buck'
44+
};
45+
46+
// mockPg.oneOrNone.mockImplementation((query: any, params: any, callback: any) => {
47+
// return Promise.resolve(callback(mockDbUser))
48+
// })
49+
50+
// (convertUser as jest.Mock).mockReturnValue(mockConvertedUser);
51+
// ( toUserAPIResponse as jest.Mock).mockReturnValue(mockApiResponse);
52+
53+
// const result = await getUser({id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP'})
54+
55+
// console.log(result);
56+
57+
})
58+
})

backend/api/tsconfig.test.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"baseUrl": ".",
6+
"paths": {
7+
"api/*": ["src/*"],
8+
"shared/*": ["../shared/src/*"],
9+
"common/*": ["../../common/src/*"],
10+
"email/*": ["../email/emails/*"]
11+
}
12+
},
13+
"include": ["tests/**/*.ts", "src/**/*.ts"]
14+
}

backend/email/tests/integration/.keep

Whitespace-only changes.

backend/email/tests/unit/.keep

Whitespace-only changes.

backend/shared/tests/integration/.keep

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Note: may not be needed. `shared` rarely needs integration tests.

backend/shared/tests/unit/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)