Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3c599b5
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 3, 2024
f8eee4b
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 5, 2024
e0639af
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 5, 2024
5a8d139
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 6, 2024
b538a07
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 19, 2024
dd7902e
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 21, 2024
f7e1419
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 23, 2024
bf512e5
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 23, 2024
2eb9066
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 4, 2025
503b1d7
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 11, 2025
d61f71c
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 15, 2025
ff14d05
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 27, 2025
eae99e0
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Mar 3, 2025
e246c65
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Mar 7, 2025
eb03763
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Mar 11, 2025
2ec1e9f
Implemented autochecker should fail if a user has coffeechatted last …
JasonMun7 Mar 12, 2025
53bf9cb
added in the approved status and updated the memberMeetsCategory as well
JasonMun7 Mar 24, 2025
f5d21b3
Updated the test cases
JasonMun7 Mar 24, 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
14 changes: 14 additions & 0 deletions backend/src/API/coffeeChatAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ export const runAutoChecker = async (uuid: string, user: IdolMember): Promise<Co
throw new BadRequestError(`Coffee chat with uuid: ${uuid} does not exist`);
}

const archivedChats = await coffeeChatDao.getCoffeeChatsByUser(
coffeeChat.submitter.email,
undefined,
coffeeChat.otherMember
);

const hasArchivedChat = archivedChats.some((chat) => chat.isArchived);

if (hasArchivedChat) {
throw new BadRequestError(
`Coffee chat with uuid: ${uuid} has an archived chat with the same submitter and other member`
);
}

const result = await checkMemberMeetsCategory(
coffeeChat.otherMember.email,
coffeeChat.submitter.email,
Expand Down
62 changes: 58 additions & 4 deletions backend/tests/CoffeeChatAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
updateCoffeeChat,
deleteCoffeeChat,
clearAllCoffeeChats,
checkMemberMeetsCategory
checkMemberMeetsCategory,
runAutoChecker
} from '../src/API/coffeeChatAPI';
import { setMember, deleteMember } from '../src/API/memberAPI';
import { PermissionError } from '../src/utils/errors';
import { BadRequestError, PermissionError } from '../src/utils/errors';

const user = fakeIdolMember();
const user2 = fakeIdolMember();
Expand Down Expand Up @@ -188,11 +189,64 @@ describe('User is lead or admin', () => {
});
});

describe('runAutoChecker tests', () => {
const adminUser = fakeIdolLead();
const submitter = fakeIdolMember();
const otherMember = fakeIdolMember();
const coffeeChat = { ...fakeCoffeeChat(), submitter, otherMember };

beforeAll(() => {
const mockIsLeadOrAdmin = jest.fn().mockResolvedValue(true);
PermissionsManager.isLeadOrAdmin = mockIsLeadOrAdmin;
});

afterAll(() => {
jest.clearAllMocks();
});

test('runAutoChecker should throw error if coffee chat does not exist', async () => {
const mockGetCoffeeChat = jest.fn().mockResolvedValue(null);
CoffeeChatDao.prototype.getCoffeeChat = mockGetCoffeeChat;

await expect(runAutoChecker('fake-uuid', adminUser)).rejects.toThrow(
new BadRequestError(`Coffee chat with uuid: fake-uuid does not exist`)
);
});

test('runAutoChecker should throw error if archived chat exists with same submitter and other member', async () => {
const mockGetCoffeeChat = jest.fn().mockResolvedValue(coffeeChat);
const mockGetCoffeeChatsByUser = jest
.fn()
.mockResolvedValue([{ ...coffeeChat, isArchived: true }]);
CoffeeChatDao.prototype.getCoffeeChat = mockGetCoffeeChat;
CoffeeChatDao.prototype.getCoffeeChatsByUser = mockGetCoffeeChatsByUser;

await expect(runAutoChecker(coffeeChat.uuid, adminUser)).rejects.toThrow(
new BadRequestError(
`Coffee chat with uuid: ${coffeeChat.uuid} has an archived chat with the same submitter and other member`
)
);
});

test('runAutoChecker should update coffee chat if no archived chat exists', async () => {
const mockGetCoffeeChat = jest.fn().mockResolvedValue(coffeeChat);
const mockGetCoffeeChatsByUser = jest.fn().mockResolvedValue([]);
const mockUpdateCoffeeChat = jest.fn().mockResolvedValue(coffeeChat);
CoffeeChatDao.prototype.getCoffeeChat = mockGetCoffeeChat;
CoffeeChatDao.prototype.getCoffeeChatsByUser = mockGetCoffeeChatsByUser;
CoffeeChatDao.prototype.updateCoffeeChat = mockUpdateCoffeeChat;

const result = await runAutoChecker(coffeeChat.uuid, adminUser);
expect(result).toBeDefined();
expect(CoffeeChatDao.prototype.updateCoffeeChat).toBeCalled();
});
});

describe('More complicated member meets category checks', () => {
const admin = { ...fakeIdolLead() };
const user1 = fakeIdolMember();
const user2 = { ...fakeIdolMember(), role: 'dev-advisor' as Role };
const user3 = { ...fakeIdolMember(), role: 'tpm' as Role };
const user2 = { ...fakeIdolMember(), role: 'dev-advisor' };
const user3 = { ...fakeIdolMember(), role: 'tpm' };
const user4 = { ...fakeIdolMember(), semesterJoined: 'Spring 2025' };

beforeAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/CoffeeChatDao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { coffeeChatsCollection } from '../src/firebase';
const user = fakeIdolMember();
const user2 = fakeIdolMember();
const mockCC = { ...fakeCoffeeChat(), submitter: user };
const mockCC2 = { ...fakeCoffeeChat(), status: 'accepted' as Status, submitter: user };
const mockCC2 = { ...fakeCoffeeChat(), status: 'accepted', submitter: user };
const mockCC3 = { ...fakeCoffeeChat(), submitter: user, otherMember: user2 };

const coffeeChatDao = new CoffeeChatDao();
Expand All @@ -31,7 +31,7 @@ test('Get coffee chat by user', () =>
}));

test('Get coffee chat by user with status', () =>
coffeeChatDao.getCoffeeChatsByUser(user.email, 'accepted' as Status).then((coffeeChats) => {
coffeeChatDao.getCoffeeChatsByUser(user.email, 'accepted').then((coffeeChats) => {
expect(coffeeChats.some((submission) => submission === mockCC)).toBe(false);
expect(coffeeChats.some((submission) => submission === mockCC2));
expect(coffeeChats.some((submission) => submission === mockCC3)).toBe(false);
Expand Down
Loading