Files
Compass/backend/api/tests/unit/get-notifications.unit.test.ts
Okechi Jones-Williams 7b61c70f6d Add more API endoints unit tests (#25)
* 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

* Pushing to get help with sql Unit test

* Updating get-profiles unit tests

* Added more unit tests

* .

* Added more unit tests

* Added getSupabaseToken unit test

* .

* excluding supabase token test so ci can pass

* .

* Seperated the seedDatabase func into its own file so it can be accessed seperatly

* Fixed failing test

* .

* .

* Fix tests

* Fix lint

* Clean

* Fixed module paths in compute-score unit test

* Updated root tsconfig to recognise backend/shared

* Added create comment unit test

* Added some unit tests

* Working on createProfile return issue

* .

* Fixes

* Updated Create profile unit test

* Updating create user unit test

* Add create-user unit tests

* .

* Added more unit tests

* Added more unit tests

* .

* Apply suggestion from @MartinBraquet

* .

* Added unit tests

* Added unit tests

---------

Co-authored-by: MartinBraquet <martin.braquet@gmail.com>
2026-01-08 12:52:49 +02:00

44 lines
1.4 KiB
TypeScript

jest.mock('shared/supabase/init');
import { getNotifications } from "api/get-notifications";
import { AuthedUser } from "api/helpers/endpoint";
import * as supabaseInit from "shared/supabase/init";
describe('getNotifications', () => {
let mockPg = {} as any;
beforeEach(() => {
jest.resetAllMocks();
mockPg = {
map: jest.fn()
};
(supabaseInit.createSupabaseDirectClient as jest.Mock)
.mockReturnValue(mockPg);
});
afterEach(() => {
jest.restoreAllMocks();
});
describe('when given valid input', () => {
it('should user notifications', async () => {
const mockProps = {
limit: 10,
after: 2
};
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockNotifications = {} as any;
(mockPg.map as jest.Mock).mockResolvedValue(mockNotifications);
const result = await getNotifications(mockProps, mockAuth, mockReq);
expect(result).toBe(mockNotifications);
expect(mockPg.map).toBeCalledTimes(1);
expect(mockPg.map).toBeCalledWith(
expect.stringContaining('select data from user_notifications'),
[mockAuth.uid, mockProps.limit, mockProps.after],
expect.any(Function)
);
});
});
});