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

Add AdminController Test Suite #187

Merged
merged 26 commits into from
Aug 2, 2021
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cba950b
Add tests for "/bonus" and "/emails" routes
StormFireFox1 May 16, 2021
11c362c
nit: "proxyUser" -> "adminUser" for admin tests
StormFireFox1 May 27, 2021
fdbbd08
Adjust array equality checks on admin tests
StormFireFox1 May 27, 2021
3a27e7f
Remove test for non-present emails
StormFireFox1 May 27, 2021
5fc6a9a
Inline functions and variables in admin tests
StormFireFox1 May 27, 2021
5fe3084
Modify test to check bonus points for all users
StormFireFox1 May 27, 2021
1e37dd2
Combine both bonus points tests into one
StormFireFox1 May 27, 2021
5ad4381
Rearrange asserts to suffix response calls
StormFireFox1 May 27, 2021
df1a901
Rename adminUser to admin in admin test suite
StormFireFox1 Jun 9, 2021
aca6574
Adjust order of assertions in admin test
StormFireFox1 Jun 9, 2021
2afef57
Adjust name of extraneous user in admin test
StormFireFox1 Jun 9, 2021
acdf94a
Make variable for UserController in admin test
StormFireFox1 Jun 9, 2021
aa286ee
Merge branch 'master' into add-admin-test-suite
StormFireFox1 Jun 20, 2021
2c591a5
Fix nits and check attendance response details
StormFireFox1 Jul 3, 2021
6688e90
Check for correct activities in admin test suite
StormFireFox1 Jul 3, 2021
da3210a
Add points field of ActivityModel in test suite
StormFireFox1 Jul 3, 2021
747b44d
Port EventFactory code from #181
Jul 16, 2021
a9834d4
Adjust test suite to account for factory bug
Jul 16, 2021
94e1113
Revert event factory code changes
StormFireFox1 Jul 22, 2021
b5f03dc
Adjust transaction order when saving factory state
StormFireFox1 Jul 22, 2021
f5832f5
Merge branch 'master' into add-admin-test-suite
StormFireFox1 Jul 22, 2021
54c65b8
Revert transaction order adjustment
StormFireFox1 Jul 22, 2021
fe8f65b
Guarantee correct activity order in failed tests
StormFireFox1 Jul 22, 2021
b41e0da
Merge user creation methods to have optional args
StormFireFox1 Jul 22, 2021
4c3f0fc
Adjust user creation method to have set timestamp
StormFireFox1 Jul 22, 2021
b7ab295
Fix argument call for creating users in test suite
StormFireFox1 Jul 22, 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
81 changes: 81 additions & 0 deletions tests/admin.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CreateBonusRequest } from 'api/validators/AdminControllerRequests';
import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType } from '../types';
import { ControllerFactory } from './controllers';
import { DatabaseConnection, EventFactory, UserFactory, PortalState } from './data';
Expand Down Expand Up @@ -117,3 +118,83 @@ describe('retroactive attendance submission', () => {
expect(staffActivityResponse.activity[1].type).toEqual(ActivityType.ATTEND_EVENT_AS_STAFF);
});
});

describe('email retrieval', () => {
test('gets all the emails of stored users', async () => {
const conn = await DatabaseConnection.get();
const users = UserFactory.create(5);
const emails = users.map((user) => user.email.toLowerCase());
const [proxyUser] = UserFactory.with({ accessType: UserAccessType.ADMIN });
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved

await new PortalState()
.createUsers([...users, proxyUser])
.write();

const adminController = ControllerFactory.admin(conn);
const response = await adminController.getAllEmails(proxyUser);
expect([...emails, proxyUser.email].sort()).toEqual(response.emails.sort());
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
});

test('no other emails present asides from registered users', async () => {
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
const conn = await DatabaseConnection.get();
const users = UserFactory.create(5);
const [proxyUser] = UserFactory.with({ accessType: UserAccessType.ADMIN });
const [extraneousUser] = UserFactory.create(1);

await new PortalState()
.createUsers([...users, proxyUser])
.write();

const adminController = ControllerFactory.admin(conn);
const response = await adminController.getAllEmails(proxyUser);
expect(response.emails).not.toContain(extraneousUser.email.toLowerCase());
});
});

describe('bonus points submission', () => {
test('updates points and activity to the users in the bonus request', async () => {
const conn = await DatabaseConnection.get();
const users = UserFactory.create(5);
const emails = users.map((user) => user.email.toLowerCase());
const [proxyUser] = UserFactory.with({ accessType: UserAccessType.ADMIN });
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved

await new PortalState()
.createUsers([...users, proxyUser])
.write();

const adminController = ControllerFactory.admin(conn);
const userController = ControllerFactory.user(conn);
const request: CreateBonusRequest = { bonus: { description: 'Test addition of bonus points',
users: emails,
points: 200 } };
const bonusResponse = await adminController.addBonus(request, proxyUser);
const userResponse = await userController.getUser({ uuid: users[0].uuid }, proxyUser);
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved

expect(userResponse.user.points).toEqual(200);
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
expect(bonusResponse.emails.sort()).toEqual(emails.sort());
});

test("Does not update points and activity to the users who aren't in the bonus request", async () => {
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
const conn = await DatabaseConnection.get();
const users = UserFactory.create(5);
const emails = users.map((user) => user.email.toLowerCase());
const [proxyUser] = UserFactory.with({ accessType: UserAccessType.ADMIN });
const [extraneousUser] = UserFactory.create(1);

await new PortalState()
.createUsers([...users, extraneousUser, proxyUser])
.write();

const adminController = ControllerFactory.admin(conn);
const userController = ControllerFactory.user(conn);
StormFireFox1 marked this conversation as resolved.
Show resolved Hide resolved
const request: CreateBonusRequest = { bonus: { description: 'Test addition of bonus points',
users: emails,
points: 200 } };

await adminController.addBonus(request, proxyUser);

const userResponse = await userController.getUser({ uuid: extraneousUser.uuid }, proxyUser);

expect(userResponse.user.points).toEqual(0);
});
});