Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write events test suite #181

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c12ac20
Add skeleton event tests
shravanhariharan2 Apr 18, 2021
ef89fa3
Add missing await to EventService::createEvent
shravanhariharan2 Apr 18, 2021
bc43ff9
Add rest of CRUD operation tests
shravanhariharan2 Apr 18, 2021
ce6dcb8
Add storage utils for mocking images to upload
shravanhariharan2 Apr 20, 2021
290c828
Add event feedback fakes
shravanhariharan2 Apr 24, 2021
159d169
Add empty file check for storage test utils
shravanhariharan2 Apr 24, 2021
bbaedc2
Refactor EventFactory to fake past, ongoing, and future events easily
shravanhariharan2 Apr 24, 2021
6a9b5ae
Remove unused validator in feedback
shravanhariharan2 Apr 24, 2021
74db6ba
Finish writing preliminary event tests
shravanhariharan2 Apr 24, 2021
d2fd439
Merge branch 'master' into tests/events
shravanhariharan2 Apr 24, 2021
8d7623d
Update tests/event.test.ts
shravanhariharan2 May 4, 2021
a264273
Refactor EventFactory fake methods
shravanhariharan2 May 4, 2021
caa4f92
Inline all error messages that are only used once
shravanhariharan2 May 4, 2021
a33bcd0
Fix small event test nits
shravanhariharan2 May 4, 2021
fcc0e4a
Merge branch 'master' into tests/events
shravanhariharan2 May 6, 2021
e56e157
Change controller params in test to match updated validation format
shravanhariharan2 May 6, 2021
cc6f83b
Move asserts next to data fetches
shravanhariharan2 May 6, 2021
8ef3ea1
Refactor EventFactory random time generation
shravanhariharan2 May 6, 2021
5b3fa0c
Merge branch 'master' into tests/events
shravanhariharan2 May 18, 2021
6e55d48
Switch to non-deprecated hexadecimal generation
shravanhariharan2 May 18, 2021
2f8c3b4
mocking with jest sucks
shravanhariharan2 May 21, 2021
2529a86
Add 'update event' tests
shravanhariharan2 May 27, 2021
28a55ca
Make event patches fields explicitly optional in validation (they wer…
shravanhariharan2 May 27, 2021
ede38bf
Allow mocked services to be injected into controllers
shravanhariharan2 May 27, 2021
539d35e
Remove redundant type
shravanhariharan2 May 27, 2021
18a952c
Switch mocking aws-sdk to StorageService using ts-mockito
shravanhariharan2 May 27, 2021
342dcb5
Merge branch 'master' into tests/events
shravanhariharan2 Jul 17, 2021
a70a68e
Move ts-mockito from dep to devDep
shravanhariharan2 Jul 17, 2021
cc1694b
Remove singleton behavior from ControllerFactory
shravanhariharan2 Jul 17, 2021
9b51a89
Move controllers/index.ts -> ControllerFactory.ts
shravanhariharan2 Jul 17, 2021
3ecb774
Move createEventFeedback from FeedbackFactory to EventFactory
shravanhariharan2 Jul 17, 2021
2c5ca2a
Move fakeOngoingEvent start duration forward 30 minutes
shravanhariharan2 Jul 17, 2021
a88706e
Tighten error handling to match constraint in test
shravanhariharan2 Jul 17, 2021
98023da
Lint
shravanhariharan2 Jul 17, 2021
298f5f3
Add get call to event cover test to ensure cover is persisted
shravanhariharan2 Jul 17, 2021
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 services/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class EventService {
const currentEvent = await eventRepository.findByUuid(uuid);
if (!currentEvent) throw new NotFoundError('Event not found');
if (changes.attendanceCode !== currentEvent.attendanceCode) {
const isUnusedAttendanceCode = eventRepository.isUnusedAttendanceCode(changes.attendanceCode);
const isUnusedAttendanceCode = await eventRepository.isUnusedAttendanceCode(changes.attendanceCode);
if (!isUnusedAttendanceCode) throw new UserError('Attendance code has already been used');
Comment on lines 63 to 65
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

}
return eventRepository.upsertEvent(currentEvent, changes);
Expand Down
42 changes: 41 additions & 1 deletion tests/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,46 @@ describe('event CRUD operations', () => {
expect(eventsResponse.events).toHaveLength(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert that the response is only the first event.

expect(eventsResponse.events[0]).toStrictEqual(event1.getPublicEvent(true));
});

test('events can be updated by an admin', async () => {
const conn = await DatabaseConnection.get();
const [event] = EventFactory.with({ attendanceCode: 'code' });
const [admin] = UserFactory.with({ accessType: UserAccessType.ADMIN });

await new PortalState()
.createEvents([event])
.createUsers([admin])
.write();

const eventChanges = {
title: 'new title',
description: 'new description',
};

const updateEventResponse = await ControllerFactory
.event(conn)
.updateEvent({ uuid: event.uuid }, { event: eventChanges }, admin);

expect(updateEventResponse.event).toMatchObject({ ...event.getPublicEvent(), ...eventChanges });
});

test('event attendance code cannot be updated to a duplicate one', async () => {
const conn = await DatabaseConnection.get();
const [event1] = EventFactory.with({ attendanceCode: 'code' });
const [event2] = EventFactory.with({ attendanceCode: 'another-code' });
const [admin] = UserFactory.with({ accessType: UserAccessType.ADMIN });

await new PortalState()
.createEvents([event1, event2])
.createUsers([admin])
.write();

event1.attendanceCode = event2.attendanceCode;

await expect(
ControllerFactory.event(conn).updateEvent({ uuid: event1.uuid }, { event: event1 }, admin),
).rejects.toThrow('Attendance code has already been used');
});
});

describe('event covers', () => {
Expand All @@ -125,7 +165,7 @@ describe('event covers', () => {
});

test('rejects upload if file size too large', async () => {
// TODO: implement once API wrappers exist (since multer validation can't be mocked with function calls)
// TODO: implement once API wrappers exist (since multer validation can't be verified with function calls)
});
});

Expand Down