mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-16 12:38:19 -04:00
Update test structure
This commit is contained in:
26
backend/api/jest.config.js
Normal file
26
backend/api/jest.config.js
Normal file
@@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
|
||||
rootDir: '.',
|
||||
testMatch: [
|
||||
"<rootDir>/tests/**/*.test.ts",
|
||||
"<rootDir>/tests/**/*.spec.ts"
|
||||
],
|
||||
|
||||
moduleNameMapper: {
|
||||
"^api/(.*)$": "<rootDir>/src/$1",
|
||||
"^shared/(.*)$": "<rootDir>/../shared/src/$1",
|
||||
"^common/(.*)$": "<rootDir>/../../common/src/$1",
|
||||
"^email/(.*)$": "<rootDir>/../email/emails/$1"
|
||||
},
|
||||
|
||||
moduleFileExtensions: ["ts", "js", "json"],
|
||||
clearMocks: true,
|
||||
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.json'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -20,7 +20,8 @@
|
||||
"verify": "yarn --cwd=../.. verify",
|
||||
"verify:dir": "npx eslint . --max-warnings 0",
|
||||
"regen-types": "cd ../supabase && make ENV=prod regen-types",
|
||||
"regen-types-dev": "cd ../supabase && make ENV=dev regen-types-dev"
|
||||
"regen-types-dev": "cd ../supabase && make ENV=dev regen-types-dev",
|
||||
"test": "jest"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
|
||||
0
backend/api/tests/integration/.keep
Normal file
0
backend/api/tests/integration/.keep
Normal file
58
backend/api/tests/unit/get-users.unit.test.ts
Normal file
58
backend/api/tests/unit/get-users.unit.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { getUser } from "api/get-user";
|
||||
import { createSupabaseDirectClient } from "shared/supabase/init";
|
||||
import { toUserAPIResponse } from "common/api/user-types";
|
||||
import { convertUser } from "common/supabase/users";
|
||||
|
||||
jest.mock("shared/supabase/init");
|
||||
jest.mock("common/supabase/users");
|
||||
jest.mock("common/api/utils");
|
||||
describe('getUser', () =>{
|
||||
let mockPg: any;
|
||||
|
||||
beforeEach(() => {
|
||||
mockPg = {
|
||||
oneOrNone: jest.fn(),
|
||||
};
|
||||
(createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg);
|
||||
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should fetch user successfully by id', async () => {
|
||||
const mockDbUser = {
|
||||
created_time: '2025-11-11T16:42:05.188Z',
|
||||
data: { link: {}, avatarUrl: "", isBannedFromPosting: false },
|
||||
id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP',
|
||||
name: 'Franklin Buckridge',
|
||||
name_username_vector: "'buckridg':2,4 'franklin':1,3",
|
||||
username: 'Franky_Buck'
|
||||
};
|
||||
const mockConvertedUser = {
|
||||
created_time: new Date(),
|
||||
id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP',
|
||||
name: 'Franklin Buckridge',
|
||||
name_username_vector: "'buckridg':2,4 'franklin':1,3",
|
||||
username: 'Franky_Buck'
|
||||
|
||||
};
|
||||
const mockApiResponse = {
|
||||
created_time: '2025-11-11T16:42:05.188Z',
|
||||
data: { link: {}, avatarUrl: "", isBannedFromPosting: false },
|
||||
id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP',
|
||||
name: 'Franklin Buckridge',
|
||||
username: 'Franky_Buck'
|
||||
};
|
||||
|
||||
// mockPg.oneOrNone.mockImplementation((query: any, params: any, callback: any) => {
|
||||
// return Promise.resolve(callback(mockDbUser))
|
||||
// })
|
||||
|
||||
// (convertUser as jest.Mock).mockReturnValue(mockConvertedUser);
|
||||
// ( toUserAPIResponse as jest.Mock).mockReturnValue(mockApiResponse);
|
||||
|
||||
// const result = await getUser({id: 'feUaIfcxVmJZHJOVVfawLTTPgZiP'})
|
||||
|
||||
// console.log(result);
|
||||
|
||||
})
|
||||
})
|
||||
14
backend/api/tsconfig.test.json
Normal file
14
backend/api/tsconfig.test.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"api/*": ["src/*"],
|
||||
"shared/*": ["../shared/src/*"],
|
||||
"common/*": ["../../common/src/*"],
|
||||
"email/*": ["../email/emails/*"]
|
||||
}
|
||||
},
|
||||
"include": ["tests/**/*.ts", "src/**/*.ts"]
|
||||
}
|
||||
0
backend/email/tests/integration/.keep
Normal file
0
backend/email/tests/integration/.keep
Normal file
0
backend/email/tests/unit/.keep
Normal file
0
backend/email/tests/unit/.keep
Normal file
0
backend/shared/tests/integration/.keep
Normal file
0
backend/shared/tests/integration/.keep
Normal file
1
backend/shared/tests/integration/README.md
Normal file
1
backend/shared/tests/integration/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Note: may not be needed. `shared` rarely needs integration tests.
|
||||
0
backend/shared/tests/unit/.keep
Normal file
0
backend/shared/tests/unit/.keep
Normal file
0
common/tests/integration/.keep
Normal file
0
common/tests/integration/.keep
Normal file
0
common/tests/unit/.keep
Normal file
0
common/tests/unit/.keep
Normal file
@@ -1,4 +1,4 @@
|
||||
import {jsonToMarkdown} from "../src/md";
|
||||
import {jsonToMarkdown} from "../../src/md";
|
||||
|
||||
describe('JSON to Markdown', () => {
|
||||
it('', () => {
|
||||
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./backend/api" },
|
||||
{ "path": "./backend/api/tsconfig.test.json" }
|
||||
]
|
||||
}
|
||||
0
web/tests/integration/.keep
Normal file
0
web/tests/integration/.keep
Normal file
0
web/tests/unit/.keep
Normal file
0
web/tests/unit/.keep
Normal file
Reference in New Issue
Block a user