Skip to content
Merged
Changes from all commits
Commits
Show all changes
56 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
f0bcaf3
Merge branch 'CompassConnections:main' into main
O-Bots Jan 4, 2026
a7f74fa
Merge branch 'main' into main
O-Bots Jan 5, 2026
77b1f71
Apply suggestion from @MartinBraquet
MartinBraquet Jan 6, 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
268 changes: 264 additions & 4 deletions backend/api/tests/unit/create-profile.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ jest.mock('shared/supabase/utils');
jest.mock('common/util/try-catch');
jest.mock('shared/analytics');
jest.mock('common/discord/core');
jest.mock('common/util/time', () => {
const actual = jest.requireActual('common/util/time');
return{ ...actual, sleep: () => Promise.resolve()}
});

import { createProfile } from "api/create-profile";
import * as supabaseInit from "shared/supabase/init";
Expand Down Expand Up @@ -52,7 +56,7 @@ describe('createProfile', () => {
};
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;
const mockExistingUser = {id: "mockExistingUserId"};
const mockNProfiles = 10
const mockData = {
age: 30,
city: "mockCity"
Expand All @@ -68,12 +72,268 @@ describe('createProfile', () => {
(supabaseUsers.updateUser as jest.Mock).mockReturnValue(null);
(supabaseUtils.insert as jest.Mock).mockReturnValue(null);
(tryCatch as jest.Mock).mockResolvedValueOnce({data: mockData, error: null});

const results: any = await createProfile(mockBody, mockAuth, mockReq);

expect(results.result).toEqual(mockData);
expect(removePinnedUrlFromPhotoUrls).toBeCalledTimes(1)
expect(removePinnedUrlFromPhotoUrls).toBeCalledWith(mockBody);
expect(sharedUtils.getUser).toBeCalledTimes(1);
expect(sharedUtils.getUser).toBeCalledWith(mockAuth.uid);

(sharedAnalytics.track as jest.Mock).mockResolvedValue(null);
(sendDiscordMessage as jest.Mock).mockResolvedValueOnce(null);
(mockPg.one as jest.Mock).mockReturnValue(10);
(sendDiscordMessage as jest.Mock)
.mockResolvedValueOnce(null)
.mockResolvedValueOnce(null);
(mockPg.one as jest.Mock).mockReturnValue(mockNProfiles);

await results.continue();

expect(sharedAnalytics.track).toBeCalledTimes(1);
expect(sharedAnalytics.track).toBeCalledWith(
mockAuth.uid,
'create profile',
{username: mockUser.username}
);
expect(sendDiscordMessage).toBeCalledTimes(1);
expect(sendDiscordMessage).toBeCalledWith(
expect.stringContaining(mockUser.name && mockUser.username),
'members'
);
});

it('successfully create milestone profile', async () => {
const mockBody = {
city: "mockCity",
gender: "mockGender",
looking_for_matches: true,
photo_urls: ["mockPhotoUrl1"],
pinned_url: "mockPinnedUrl",
pref_gender: ["mockPrefGender"],
pref_relation_styles: ["mockPrefRelationStyles"],
visibility: 'public' as "public" | "member",
wants_kids_strength: 2,
};
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;
const mockNProfiles = 15
const mockData = {
age: 30,
city: "mockCity"
};
const mockUser = {
createdTime: Date.now() - 2 * 60 * 60 * 1000, //2 hours ago
name: "mockName",
username: "mockUserName"
};

(tryCatch as jest.Mock).mockResolvedValueOnce({data: null, error: null});
(sharedUtils.getUser as jest.Mock).mockResolvedValue(mockUser);
(supabaseUsers.updateUser as jest.Mock).mockReturnValue(null);
(supabaseUtils.insert as jest.Mock).mockReturnValue(null);
(tryCatch as jest.Mock).mockResolvedValueOnce({data: mockData, error: null});

const results: any = await createProfile(mockBody, mockAuth, mockReq);
expect(results.result).toEqual(mockData)

expect(results.result).toEqual(mockData);
expect(removePinnedUrlFromPhotoUrls).toBeCalledTimes(1)
expect(removePinnedUrlFromPhotoUrls).toBeCalledWith(mockBody);
expect(sharedUtils.getUser).toBeCalledTimes(1);
expect(sharedUtils.getUser).toBeCalledWith(mockAuth.uid);

(sharedAnalytics.track as jest.Mock).mockResolvedValue(null);
(sendDiscordMessage as jest.Mock)
.mockResolvedValueOnce(null)
.mockResolvedValueOnce(null);
(mockPg.one as jest.Mock).mockReturnValue(mockNProfiles);

await results.continue();

expect(sharedAnalytics.track).toBeCalledTimes(1);
expect(sharedAnalytics.track).toBeCalledWith(
mockAuth.uid,
'create profile',
{username: mockUser.username}
);
expect(sendDiscordMessage).toBeCalledTimes(2);
expect(sendDiscordMessage).toHaveBeenNthCalledWith(
1,
expect.stringContaining(mockUser.name && mockUser.username),
'members'
);
expect(sendDiscordMessage).toHaveBeenNthCalledWith(
2,
expect.stringContaining(String(mockNProfiles)),
'general'
);

});

it('throws an error if it failed to track create profile', async () => {
const mockBody = {
city: "mockCity",
gender: "mockGender",
looking_for_matches: true,
photo_urls: ["mockPhotoUrl1"],
pinned_url: "mockPinnedUrl",
pref_gender: ["mockPrefGender"],
pref_relation_styles: ["mockPrefRelationStyles"],
visibility: 'public' as "public" | "member",
wants_kids_strength: 2,
};
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;
const mockData = {
age: 30,
city: "mockCity"
};
const mockUser = {
createdTime: Date.now() - 2 * 60 * 60 * 1000, //2 hours ago
name: "mockName",
username: "mockUserName"
};

(tryCatch as jest.Mock).mockResolvedValueOnce({data: null, error: null});
(sharedUtils.getUser as jest.Mock).mockResolvedValue(mockUser);
(supabaseUsers.updateUser as jest.Mock).mockReturnValue(null);
(supabaseUtils.insert as jest.Mock).mockReturnValue(null);
(tryCatch as jest.Mock).mockResolvedValueOnce({data: mockData, error: null});

const results: any = await createProfile(mockBody, mockAuth, mockReq);

expect(results.result).toEqual(mockData);
expect(removePinnedUrlFromPhotoUrls).toBeCalledTimes(1)
expect(removePinnedUrlFromPhotoUrls).toBeCalledWith(mockBody);
expect(sharedUtils.getUser).toBeCalledTimes(1);
expect(sharedUtils.getUser).toBeCalledWith(mockAuth.uid);

const errorSpy = jest.spyOn(console , 'error').mockImplementation(() => {});

(sharedAnalytics.track as jest.Mock).mockRejectedValue(null);

await results.continue();
expect(errorSpy).toBeCalledWith('Failed to track create profile', null)
});

it('throws an error if it failed to send discord new profile', async () => {
const mockBody = {
city: "mockCity",
gender: "mockGender",
looking_for_matches: true,
photo_urls: ["mockPhotoUrl1"],
pinned_url: "mockPinnedUrl",
pref_gender: ["mockPrefGender"],
pref_relation_styles: ["mockPrefRelationStyles"],
visibility: 'public' as "public" | "member",
wants_kids_strength: 2,
};
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;
const mockData = {
age: 30,
city: "mockCity"
};
const mockUser = {
createdTime: Date.now() - 2 * 60 * 60 * 1000, //2 hours ago
name: "mockName",
username: "mockUserName"
};

(tryCatch as jest.Mock).mockResolvedValueOnce({data: null, error: null});
(sharedUtils.getUser as jest.Mock).mockResolvedValue(mockUser);
(supabaseUsers.updateUser as jest.Mock).mockReturnValue(null);
(supabaseUtils.insert as jest.Mock).mockReturnValue(null);
(tryCatch as jest.Mock).mockResolvedValueOnce({data: mockData, error: null});

const results: any = await createProfile(mockBody, mockAuth, mockReq);

expect(results.result).toEqual(mockData);
expect(removePinnedUrlFromPhotoUrls).toBeCalledTimes(1)
expect(removePinnedUrlFromPhotoUrls).toBeCalledWith(mockBody);
expect(sharedUtils.getUser).toBeCalledTimes(1);
expect(sharedUtils.getUser).toBeCalledWith(mockAuth.uid);

const errorSpy = jest.spyOn(console , 'error').mockImplementation(() => {});

(sharedAnalytics.track as jest.Mock).mockResolvedValue(null);
(sendDiscordMessage as jest.Mock).mockRejectedValue(null);

await results.continue();
expect(sharedAnalytics.track).toBeCalledTimes(1);
expect(sharedAnalytics.track).toBeCalledWith(
mockAuth.uid,
'create profile',
{username: mockUser.username}
);
expect(errorSpy).toBeCalledWith('Failed to send discord new profile', null);
});

it('throws an error if it failed to send discord user milestone', async () => {
const mockBody = {
city: "mockCity",
gender: "mockGender",
looking_for_matches: true,
photo_urls: ["mockPhotoUrl1"],
pinned_url: "mockPinnedUrl",
pref_gender: ["mockPrefGender"],
pref_relation_styles: ["mockPrefRelationStyles"],
visibility: 'public' as "public" | "member",
wants_kids_strength: 2,
};
const mockAuth = {uid: '321'} as AuthedUser;
const mockReq = {} as any;
const mockNProfiles = 15
const mockData = {
age: 30,
city: "mockCity"
};
const mockUser = {
createdTime: Date.now() - 2 * 60 * 60 * 1000, //2 hours ago
name: "mockName",
username: "mockUserName"
};

(tryCatch as jest.Mock).mockResolvedValueOnce({data: null, error: null});
(sharedUtils.getUser as jest.Mock).mockResolvedValue(mockUser);
(supabaseUsers.updateUser as jest.Mock).mockReturnValue(null);
(supabaseUtils.insert as jest.Mock).mockReturnValue(null);
(tryCatch as jest.Mock).mockResolvedValueOnce({data: mockData, error: null});

const results: any = await createProfile(mockBody, mockAuth, mockReq);

expect(results.result).toEqual(mockData);
expect(removePinnedUrlFromPhotoUrls).toBeCalledTimes(1)
expect(removePinnedUrlFromPhotoUrls).toBeCalledWith(mockBody);
expect(sharedUtils.getUser).toBeCalledTimes(1);
expect(sharedUtils.getUser).toBeCalledWith(mockAuth.uid);

const errorSpy = jest.spyOn(console , 'error').mockImplementation(() => {});

(sharedAnalytics.track as jest.Mock).mockResolvedValue(null);
(sendDiscordMessage as jest.Mock)
.mockResolvedValueOnce(null)
.mockRejectedValueOnce(null);
(mockPg.one as jest.Mock).mockReturnValue(mockNProfiles);

await results.continue();
expect(sharedAnalytics.track).toBeCalledTimes(1);
expect(sharedAnalytics.track).toBeCalledWith(
mockAuth.uid,
'create profile',
{username: mockUser.username}
);
expect(sendDiscordMessage).toBeCalledTimes(2);
expect(sendDiscordMessage).toHaveBeenNthCalledWith(
1,
expect.stringContaining(mockUser.name && mockUser.username),
'members'
);
expect(sendDiscordMessage).toHaveBeenNthCalledWith(
2,
expect.stringContaining(String(mockNProfiles)),
'general'
);
expect(errorSpy).toBeCalledWith('Failed to send discord user milestone', null);
});

it('throws an error if the profile already exists', async () => {
Expand Down
Loading