Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
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
2 changes: 1 addition & 1 deletion backend/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
"^email/(.*)$": "<rootDir>/../email/emails/$1"
},

moduleFileExtensions: ["ts", "js", "json"],
moduleFileExtensions: ["tsx","ts", "js", "json"],
clearMocks: true,

globals: {
Expand Down
327 changes: 324 additions & 3 deletions backend/api/tests/unit/create-comment.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
jest.mock('shared/supabase/init');
jest.mock('shared/supabase/notifications');
jest.mock('email/functions/helpers');
jest.mock('common/supabase/comment');
jest.mock('shared/utils');
jest.mock('common/user-notification-preferences');
jest.mock('shared/websockets/helpers');

import * as supabaseInit from "shared/supabase/init";
import { AuthedUser } from "api/helpers/endpoint";
import * as sharedUtils from "shared/utils";
import { createComment } from "api/create-comment";
import * as notificationPrefs from "common/user-notification-preferences";
import * as supabaseNotifications from "shared/supabase/notifications";
import * as emailHelpers from "email/functions/helpers";
import * as websocketHelpers from "shared/websockets/helpers";
import { convertComment } from "common/supabase/comment";

describe('createComment', () => {
let mockPg: any;
Expand All @@ -14,6 +27,12 @@ describe('createComment', () => {

(supabaseInit.createSupabaseDirectClient as jest.Mock)
.mockReturnValue(mockPg);
(supabaseNotifications.insertNotificationToSupabase as jest.Mock)
.mockResolvedValue(null);
(emailHelpers.sendNewEndorsementEmail as jest.Mock)
.mockResolvedValue(null);
(convertComment as jest.Mock)
.mockResolvedValue(null);
});

afterEach(() => {
Expand All @@ -22,13 +41,17 @@ describe('createComment', () => {

describe('should', () => {
it('successfully create a comment with information provided', async () => {
const mockUserId = {userId: '123'}
const mockUserId = {
userId: '123',
blockedUserIds: ['111']
}
const mockOnUser = {id: '123'}
const mockCreator = {
id: '123',
id: '1234',
name: 'Mock Creator',
username: 'mock.creator.username',
avatarUrl: 'mock.creator.avatarurl'
avatarUrl: 'mock.creator.avatarurl',
isBannedFromPosting: false
}
const mockContent = {
content: {
Expand All @@ -48,9 +71,307 @@ describe('createComment', () => {
userId: '123'
};
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockComment = {id: 12};
const mockNotificationDestination = {} as any;
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(mockCreator)
.mockResolvedValueOnce(mockOnUser);
(sharedUtils.getPrivateUser as jest.Mock)
.mockResolvedValueOnce(mockUserId)
.mockResolvedValueOnce(mockOnUser);
(mockPg.one as jest.Mock).mockResolvedValue(mockComment);
(notificationPrefs.getNotificationDestinationsForUser as jest.Mock)
.mockReturnValue(mockNotificationDestination);

const results = await createComment(mockProps, mockAuth, mockReq);

expect(results.status).toBe('success');
expect(sharedUtils.getUser).toBeCalledTimes(2);
expect(sharedUtils.getUser).toBeCalledWith(mockUserId.userId);
expect(sharedUtils.getUser).toBeCalledWith(mockAuth.uid);
expect(sharedUtils.getPrivateUser).toBeCalledTimes(2);
expect(mockPg.one).toBeCalledTimes(1);
expect(mockPg.one).toBeCalledWith(
expect.stringContaining('insert into profile_comments'),
expect.arrayContaining([mockCreator.id])
);
expect(websocketHelpers.broadcastUpdatedComment).toBeCalledTimes(1)

});

it('throw an error if there is no user matching the userId', async () => {
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockUserId = {
userId: '123',
blockedUserIds: ['111']
};
const mockCreator = {
id: '1234',
name: 'Mock Creator',
username: 'mock.creator.username',
avatarUrl: 'mock.creator.avatarurl',
isBannedFromPosting: false
};
const mockContent = {
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is the comment text'
}
]
}
]
},
userId: '123'
};
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(mockCreator)
.mockResolvedValueOnce(null);
(sharedUtils.getPrivateUser as jest.Mock)
.mockResolvedValue(mockUserId);

expect(createComment( mockProps, mockAuth, mockReq )).rejects.toThrowError('User not found');
});

it('throw an error if there is no account associated with the authId', async () => {
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockUserId = {
userId: '123',
blockedUserIds: ['111']
};
const mockContent = {
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is the comment text'
}
]
}
]
},
userId: '123'
};
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(null);

expect(createComment( mockProps, mockAuth, mockReq )).rejects.toThrowError('Your account was not found');
});

it('throw an error if the account is banned from posting', async () => {
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockUserId = {
userId: '123',
blockedUserIds: ['111']
};
const mockCreator = {
id: '1234',
name: 'Mock Creator',
username: 'mock.creator.username',
avatarUrl: 'mock.creator.avatarurl',
isBannedFromPosting: true
};
const mockContent = {
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is the comment text'
}
]
}
]
},
userId: '123'
};
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(mockCreator);

expect(createComment( mockProps, mockAuth, mockReq )).rejects.toThrowError('You are banned');
});

it('throw an error if the other user is not found', async () => {
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockUserId = {
userId: '123',
blockedUserIds: ['111']
};
const mockCreator = {
id: '1234',
name: 'Mock Creator',
username: 'mock.creator.username',
avatarUrl: 'mock.creator.avatarurl',
isBannedFromPosting: false
};
const mockContent = {
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is the comment text'
}
]
}
]
},
userId: '123'
};
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(mockCreator);
(sharedUtils.getPrivateUser as jest.Mock)
.mockResolvedValue(null);

expect(createComment( mockProps, mockAuth, mockReq )).rejects.toThrowError('Other user not found');
});

it('throw an error if the user has blocked you', async () => {
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockUserId = {
userId: '123',
blockedUserIds: ['321']
};
const mockCreator = {
id: '1234',
name: 'Mock Creator',
username: 'mock.creator.username',
avatarUrl: 'mock.creator.avatarurl',
isBannedFromPosting: false
};
const mockContent = {
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is the comment text'
}
]
}
]
},
userId: '123'
};
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(mockCreator);
(sharedUtils.getPrivateUser as jest.Mock)
.mockResolvedValue(mockUserId);

expect(createComment( mockProps, mockAuth, mockReq )).rejects.toThrowError('User has blocked you');
});

it('throw an error if the comment is too long', async () => {
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReplyToCommentId = {} as any;
const mockUserId = {
userId: '123',
blockedUserIds: ['111']
};
const mockCreator = {
id: '1234',
name: 'Mock Creator',
username: 'mock.creator.username',
avatarUrl: 'mock.creator.avatarurl',
isBannedFromPosting: false
};
const mockContent = {
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This '.repeat(30000),
}
]
}
]
},
userId: '123'
};
const mockProps = {
userId: mockUserId.userId,
content: mockContent.content,
replyToCommentId: mockReplyToCommentId
};

(sharedUtils.getUser as jest.Mock)
.mockResolvedValueOnce(mockCreator);
(sharedUtils.getPrivateUser as jest.Mock)
.mockResolvedValue(mockUserId);
console.log(JSON.stringify(mockContent.content).length);

expect(createComment( mockProps, mockAuth, mockReq )).rejects.toThrowError('Comment is too long');
});
});
});
Loading
Loading