Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
e62ea91
setting up test structure
O-Bots Nov 7, 2025
0add06b
.
O-Bots Nov 7, 2025
ae75bdb
added playwright config file, deleted original playwright folder and …
O-Bots Nov 7, 2025
b3a6b31
continued test structure setup
O-Bots Nov 7, 2025
d91d2af
Updating test folder structure
O-Bots Nov 7, 2025
68011f8
Merge branch 'main' into main
O-Bots Nov 7, 2025
8671300
Merge branch 'CompassConnections:main' into main
O-Bots Nov 8, 2025
b13b8d4
Merge branch 'CompassConnections:main' into main
O-Bots Nov 11, 2025
266a2b4
Added database seeding script and backend testing folder structure
O-Bots Nov 11, 2025
062b6f2
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots Nov 11, 2025
18f24e2
removed the database test
O-Bots Nov 11, 2025
c949891
Replaced db seeding script
O-Bots Nov 11, 2025
dfd5b6f
Updated userInformation.ts to use values from choices.tsx
O-Bots Nov 11, 2025
8bd9f45
merge prep
O-Bots Nov 15, 2025
834c433
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots Nov 15, 2025
7115c22
removing extra unit test, moving api test to correct folder
O-Bots Nov 15, 2025
c039a10
Merge branch 'CompassConnections:main' into main
O-Bots Nov 15, 2025
750d7c9
Pushing to get help with sql Unit test
O-Bots Nov 17, 2025
a7f36c5
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots Nov 17, 2025
e30eac9
Merge branch 'main' into main
O-Bots Nov 17, 2025
f3f2ebf
Updating get-profiles unit tests
O-Bots Nov 19, 2025
48ef836
Added more unit tests
O-Bots Nov 19, 2025
ea7ef9c
.
O-Bots Nov 20, 2025
443996a
Added more unit tests
O-Bots Nov 21, 2025
10f17af
Added getSupabaseToken unit test
O-Bots Nov 21, 2025
a0e48aa
.
O-Bots Nov 21, 2025
f96c122
excluding supabase token test so ci can pass
O-Bots Nov 22, 2025
2a4b002
.
O-Bots Nov 22, 2025
f9bebe3
Seperated the seedDatabase func into its own file so it can be access…
O-Bots Nov 29, 2025
4cd3327
Fixed failing test
O-Bots Nov 29, 2025
25e4d91
.
O-Bots Nov 29, 2025
6f014bb
.
O-Bots Nov 29, 2025
da0a911
Merge branch 'refs/heads/main' into fork/O-Bots/main
MartinBraquet Nov 29, 2025
d658211
Fix tests
MartinBraquet Nov 29, 2025
d76fd2a
Fix lint
MartinBraquet Nov 29, 2025
0359742
Clean
MartinBraquet Nov 29, 2025
8a6f95e
Merge branch 'CompassConnections:main' into main
O-Bots Nov 30, 2025
5ec1aeb
Fixed module paths in compute-score unit test
O-Bots Nov 30, 2025
87c7db0
Updated root tsconfig to recognise backend/shared
O-Bots Nov 30, 2025
9e45f0e
Merge branch 'CompassConnections:main' into main
O-Bots Dec 5, 2025
269f6b2
Added create comment unit test
O-Bots Dec 5, 2025
d7f6d2f
Merge tag '1.7.0'
O-Bots Dec 5, 2025
053aac6
Merge branch 'CompassConnections:main' into main
O-Bots Dec 5, 2025
108ac05
Added some unit tests
O-Bots Dec 11, 2025
581449b
Merge branch 'CompassConnections:main' into main
O-Bots Dec 11, 2025
c8a5d42
Working on createProfile return issue
O-Bots Dec 11, 2025
8668f7c
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots Dec 11, 2025
302aebd
.
O-Bots Dec 11, 2025
d12cbf4
Fixes
MartinBraquet Dec 11, 2025
90e0ed4
Merge branch 'main' into main
O-Bots Dec 11, 2025
bdda4de
Merge branch 'main' into main
MartinBraquet Dec 12, 2025
430e005
Merge branch 'CompassConnections:main' into main
O-Bots Dec 12, 2025
0ddda31
Updated Create profile unit test
O-Bots Dec 14, 2025
7c7a345
Updating create user unit test
O-Bots Dec 21, 2025
83fae05
Add create-user unit tests
O-Bots Dec 27, 2025
866e266
.
O-Bots Dec 28, 2025
e9d73d0
Added more unit tests
O-Bots Jan 3, 2026
f0bcaf3
Merge branch 'CompassConnections:main' into main
O-Bots Jan 4, 2026
cf10408
Added more unit tests
O-Bots Jan 4, 2026
d97001d
.
O-Bots Jan 5, 2026
a7f74fa
Merge branch 'main' into main
O-Bots Jan 5, 2026
77b1f71
Apply suggestion from @MartinBraquet
MartinBraquet Jan 6, 2026
f7dba49
.
O-Bots Jan 6, 2026
de76ce4
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots Jan 6, 2026
e4c877e
Added unit tests
O-Bots Jan 7, 2026
db5bfd0
Added unit tests
O-Bots Jan 7, 2026
904322e
Merge branch 'CompassConnections:main' into main
O-Bots Jan 8, 2026
f8d1bb1
Added unit tests
O-Bots Jan 8, 2026
d751757
Add api unit tests
O-Bots Jan 8, 2026
5a740e2
Added api unit tests | updated set-last-online-time test
O-Bots Jan 10, 2026
d2be1d3
Added api unit tests
O-Bots Jan 11, 2026
c8804b2
Added api unit tests
O-Bots Jan 12, 2026
68e05cd
Updated older unit tests
O-Bots Jan 14, 2026
a18f56c
Updated older unit tests
O-Bots Jan 14, 2026
91846e1
Merge branch 'CompassConnections:main' into main
O-Bots Jan 14, 2026
800a56a
Merge branch 'main' into main
MartinBraquet Jan 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions backend/api/tests/unit/ban-user.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { throwErrorIfNotMod } from "shared/helpers/auth";
import * as constants from "common/envs/constants";
import * as supabaseUsers from "shared/supabase/users";
import * as sharedAnalytics from "shared/analytics";
import { } from "shared/helpers/auth";
import { APIError, AuthedUser } from "api/helpers/endpoint"
import { AuthedUser } from "api/helpers/endpoint"


describe('banUser', () => {
Expand All @@ -24,13 +23,13 @@ describe('banUser', () => {
(supabaseInit.createSupabaseDirectClient as jest.Mock)
.mockReturnValue(mockPg);
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('should', () => {
it('ban a user successfully', async () => {

describe('when given valid input', () => {
it('should ban a user successfully', async () => {
const mockUser = {
userId: '123',
unban: false
Expand All @@ -42,15 +41,25 @@ describe('banUser', () => {

await banUser(mockUser, mockAuth, mockReq);

expect(throwErrorIfNotMod).toBeCalledTimes(1);
expect(throwErrorIfNotMod).toBeCalledWith(mockAuth.uid);
expect(constants.isAdminId).toBeCalledTimes(1);
expect(constants.isAdminId).toBeCalledWith(mockUser.userId);
expect(sharedAnalytics.trackPublicEvent)
.toBeCalledWith(mockAuth.uid, 'ban user', {userId: mockUser.userId});
expect(supabaseUsers.updateUser)
.toBeCalledWith(mockPg, mockUser.userId, {isBannedFromPosting: true});
expect(sharedAnalytics.trackPublicEvent).toBeCalledTimes(1);
expect(sharedAnalytics.trackPublicEvent).toBeCalledWith(
mockAuth.uid,
'ban user',
{userId: mockUser.userId}
);
expect(supabaseUsers.updateUser).toBeCalledTimes(1);
expect(supabaseUsers.updateUser).toBeCalledWith(
mockPg,
mockUser.userId,
{isBannedFromPosting: true}
);
});

it('unban a user successfully', async () => {
it('should unban a user successfully', async () => {
const mockUser = {
userId: '123',
unban: true
Expand All @@ -64,13 +73,20 @@ describe('banUser', () => {

expect(throwErrorIfNotMod).toBeCalledWith(mockAuth.uid);
expect(constants.isAdminId).toBeCalledWith(mockUser.userId);
expect(sharedAnalytics.trackPublicEvent)
.toBeCalledWith(mockAuth.uid, 'ban user', {userId: mockUser.userId});
expect(supabaseUsers.updateUser)
.toBeCalledWith(mockPg, mockUser.userId, {isBannedFromPosting: false});
expect(sharedAnalytics.trackPublicEvent).toBeCalledWith(
mockAuth.uid,
'ban user',
{userId: mockUser.userId}
);
expect(supabaseUsers.updateUser).toBeCalledWith(
mockPg,
mockUser.userId,
{isBannedFromPosting: false}
);
});

it('throw and error if the ban requester is not a mod or admin', async () => {
});
describe('when an error occurs', () => {
it('throw if the ban requester is not a mod or admin', async () => {
const mockUser = {
userId: '123',
unban: false
Expand All @@ -79,21 +95,16 @@ describe('banUser', () => {
const mockReq = {} as any;

(throwErrorIfNotMod as jest.Mock).mockRejectedValue(
new APIError(
403,
`User ${mockAuth.uid} must be an admin or trusted to perform this action.`
)
new Error(`User ${mockAuth.uid} must be an admin or trusted to perform this action.`)
);

await expect(banUser(mockUser, mockAuth, mockReq))
.rejects
.toThrowError(`User ${mockAuth.uid} must be an admin or trusted to perform this action.`);
expect(throwErrorIfNotMod).toBeCalledWith(mockAuth.uid);
expect(sharedAnalytics.trackPublicEvent).toBeCalledTimes(0);
expect(supabaseUsers.updateUser).toBeCalledTimes(0);
});

it('throw an error if the ban target is an admin', async () => {
it('throw if the ban target is an admin', async () => {
const mockUser = {
userId: '123',
unban: false
Expand All @@ -108,8 +119,6 @@ describe('banUser', () => {
.toThrowError('Cannot ban admin');
expect(throwErrorIfNotMod).toBeCalledWith(mockAuth.uid);
expect(constants.isAdminId).toBeCalledWith(mockUser.userId);
expect(sharedAnalytics.trackPublicEvent).toBeCalledTimes(0);
expect(supabaseUsers.updateUser).toBeCalledTimes(0);
});
});
});
76 changes: 34 additions & 42 deletions backend/api/tests/unit/block-user.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,45 @@ describe('blockUser', () => {
(supabaseInit.createSupabaseDirectClient as jest.Mock)
.mockReturnValue(mockPg)
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('should', () => {
describe('when given valid input', () => {
it('block the user successfully', async () => {
const mockParams = { id: '123' }
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;

(supabaseUsers.updatePrivateUser as jest.Mock).mockResolvedValue(null);

await blockUserModule.blockUser(mockParams, mockAuth, mockReq)

expect(mockPg.tx).toHaveBeenCalledTimes(1)

expect(supabaseUsers.updatePrivateUser)
.toHaveBeenCalledWith(
expect.any(Object),
mockAuth.uid,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockParams.id)}
);
expect(supabaseUsers.updatePrivateUser)
.toHaveBeenCalledWith(
expect.any(Object),
mockParams.id,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockAuth.uid)}
);
expect(mockPg.tx).toHaveBeenCalledTimes(1);
expect(supabaseUsers.updatePrivateUser).toBeCalledTimes(2);
expect(supabaseUsers.updatePrivateUser).toHaveBeenNthCalledWith(
1,
expect.any(Object),
mockAuth.uid,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockParams.id)}
);
expect(supabaseUsers.updatePrivateUser).toHaveBeenNthCalledWith(
2,
expect.any(Object),
mockParams.id,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockAuth.uid)}
);
});

});
describe('when an error occurs', () => {
it('throw an error if the user tries to block themselves', async () => {
const mockParams = { id: '123' }
const mockAuth = {uid: '123'} as AuthedUser;
const mockReq = {} as any;

expect(blockUserModule.blockUser(mockParams, mockAuth, mockReq))
.rejects
.toThrowError('You cannot block yourself')

expect(mockPg.tx).toHaveBeenCalledTimes(0)
.toThrowError('You cannot block yourself');
});
});

});

describe('unblockUser', () => {
Expand All @@ -84,35 +79,32 @@ describe('unblockUser', () => {
(supabaseInit.createSupabaseDirectClient as jest.Mock)
.mockReturnValue(mockPg)
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('should', () => {
it('block the user successfully', async () => {
describe('when given valid input', () => {
it('should block the user successfully', async () => {
const mockParams = { id: '123' }
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;

(supabaseUsers.updatePrivateUser as jest.Mock).mockResolvedValue(null);

await blockUserModule.unblockUser(mockParams, mockAuth, mockReq)

expect(mockPg.tx).toHaveBeenCalledTimes(1)

expect(supabaseUsers.updatePrivateUser)
.toHaveBeenCalledWith(
expect.any(Object),
mockAuth.uid,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockParams.id)}
);
expect(supabaseUsers.updatePrivateUser)
.toHaveBeenCalledWith(
expect.any(Object),
mockParams.id,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockAuth.uid)}
);
expect(mockPg.tx).toHaveBeenCalledTimes(1);
expect(supabaseUsers.updatePrivateUser).toBeCalledTimes(2);
expect(supabaseUsers.updatePrivateUser).toHaveBeenNthCalledWith(
1,
expect.any(Object),
mockAuth.uid,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockParams.id)}
);
expect(supabaseUsers.updatePrivateUser).toHaveBeenNthCalledWith(
2,
expect.any(Object),
mockParams.id,
{ blockedByUserIds: supabaseUtils.FieldVal.arrayConcat(mockAuth.uid)}
);
});
});

Expand Down
39 changes: 24 additions & 15 deletions backend/api/tests/unit/compatible-profiles.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
import * as supabaseInit from "shared/supabase/init";
jest.mock('shared/supabase/init');

import {getCompatibleProfiles} from "api/compatible-profiles";
import * as supabaseInit from "shared/supabase/init";

jest.mock('shared/supabase/init')

describe('getCompatibleProfiles', () => {
let mockPg = {} as any;
beforeEach(() => {
jest.resetAllMocks();
const mockPg = {
none: jest.fn().mockResolvedValue(null),
one: jest.fn().mockResolvedValue(null),
oneOrNone: jest.fn().mockResolvedValue(null),
any: jest.fn().mockResolvedValue([]),
map: jest.fn().mockResolvedValue([["abc", {score: 0.69}]]),
} as any;
mockPg = {
map: jest.fn().mockResolvedValue([]),
};
(supabaseInit.createSupabaseDirectClient as jest.Mock)
.mockReturnValue(mockPg);
});

afterEach(() => {
jest.restoreAllMocks();
});

describe('should', () => {
it('successfully get compatible profiles when supplied with a valid user Id', async () => {
const results = await getCompatibleProfiles("123");
describe('when given valid input', () => {
it('should successfully get compatible profiles', async () => {
const mockProps = '123';
const mockScores = ["abc", { score: 0.69 }];
const mockScoresFromEntries = {"abc": { score: 0.69 }};

(mockPg.map as jest.Mock).mockResolvedValue([mockScores]);

const results = await getCompatibleProfiles(mockProps);
const [sql, param, fn] = mockPg.map.mock.calls[0];

expect(results.status).toEqual('success');
expect(results.profileCompatibilityScores).toEqual({"abc": {score: 0.69}});
expect(results.profileCompatibilityScores).toEqual(mockScoresFromEntries);
expect(mockPg.map).toBeCalledTimes(1);
expect(sql).toContain('select *');
expect(sql).toContain('from compatibility_scores');
expect(param).toStrictEqual([mockProps]);
expect(fn).toEqual(expect.any(Function));
});

});
});
Loading
Loading