mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-05 03:20:59 -05:00
* setting up test structure * . * added playwright config file, deleted original playwright folder and moved "some.test" file * continued test structure setup * Updating test folder structure * Added database seeding script and backend testing folder structure * removed the database test * Replaced db seeding script * Updated userInformation.ts to use values from choices.tsx * merge prep * removing extra unit test, moving api test to correct folder
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
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";
|
|
import { APIError } from "common/src/api/utils";
|
|
|
|
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);
|
|
|
|
})
|
|
}) |