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

Add AdminController Test Suite #187

merged 26 commits into from
Aug 2, 2021

Conversation

StormFireFox1
Copy link
Member

Closes #174.

@StormFireFox1 StormFireFox1 self-assigned this May 14, 2021
@sumeet-bansal
Copy link
Member

Heads up, you need to rebase (merge conflict).

Squashed set of commits for 6f51db8...c70e444. Merge conflict
was on package-lock, which was hard to fix, so I just redid the commits.
@StormFireFox1 StormFireFox1 force-pushed the add-admin-test-suite branch from c70e444 to cba950b Compare May 16, 2021 08:08
@StormFireFox1
Copy link
Member Author

Just did a squash on top of a rebase, since the merge conflict broke the lockfile pretty bad.

I'll keep this as a draft for another day or two, since I might be able to come up with more tests for the suite.

@StormFireFox1 StormFireFox1 marked this pull request as ready for review May 18, 2021 08:39
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
Test is not necessary due to lack of filtering in original controller.
Tests had basically the same boilerplate. Combine them to check both
conditions at once.

The test already checked if we were adding bonus point to _specifically_
the emails we passed in, so it's best to also check if an extra user
wasn't included at the same time.
Copy link
Collaborator

@shravanhariharan2 shravanhariharan2 left a comment

Choose a reason for hiding this comment

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

Small nitpicks on nomenclature/style for consistency, otherwise tests themselves LGTM

tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
Inlining UserController made one line too long.
Since it is used multiple times in the test, extract
variable to make its usage less verbose.
Copy link
Member

@sumeet-bansal sumeet-bansal left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple assertions to add.

tests/admin.test.ts Show resolved Hide resolved
tests/admin.test.ts Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Show resolved Hide resolved
ActivityModel is missing the `pointsEarned` field whenever creating
an Activity after attending an event. This only happens in our mock
tester.

Add a check for this field's presence, along with fixing the inherent
bug within the mock state.
tests/admin.test.ts Show resolved Hide resolved
@StormFireFox1
Copy link
Member Author

Due to a bug in the factory code causing events to randomly have start times before account creation times, it's possible for non-deterministic test suite failures because of account creation occurring after event attendance.

This bug is (supposedly) solved by PR #181 including the fakeOngoingEvent method. This PR is blocked until that one is merged.

@shravanhariharan2
Copy link
Collaborator

image

Here's an example - the event attendance timestamp occurs before the user creation since presumably, the event is randomly created in the past and has its timestamp set to a random time between start and end date. See https://github.com/acmucsd/membership-portal/blob/master/tests/data/PortalState.ts#L88

@sumeet-bansal
Copy link
Member

@StormFireFox1 That PR hasn't been updated in a month and has changes requested, so let's just copy those factory changes over to this PR and merge this. I don't think there shouldn't be any merge conflicts, but even if there are, #181 can handle them.

Matei-Alexandru Gardus added 2 commits July 16, 2021 17:03
Code from #181 adds ability to fake events in the past, future or present.
Taken verbatim from commit 18a952c.
Account creation can occur after event attendance, causing activities
to be out of order chronologically. Guarantee order in activities by
introducing retroactive attendance in a future event.

Bug in factory is not a reproducible issue in production, since account
creation will always occur before event attendance in real time.
@sumeet-bansal
Copy link
Member

Actually @StormFireFox1 this probably affects a bunch of other tests too. We could just set the timestamp of the account creation activity to like a month ago to ensure that activity always happens first.

@StormFireFox1
Copy link
Member Author

I figured yesterday explicitly setting account creation earlier is safer. I'll readjust all this tonight.

Mock factory `write` function incorrectly saves attendance before
any possible activities, typically causing event attendances to be
stored in the database prior to activities being stored. Adjust order
of flushing to database in order to consistently set smaller timestamps
for account-related activities, such as account creation.
This reverts commit b5f03dc.

Tests continue to be non-deterministic despite this change. My
assumption was wrong.
Create users at beginning of the Unix epoch to ensure guarantee
of event attendance activity being second is fulfilled.

Since Activities are sorted by timestamp, we need to guarantee account
creation does not occur before attendance of event. Fix issue with above
workaround, providing explicit method whenever necessary.
Rather than having two explicit methods, merge methods and use optional
timestamp argument to allow for custom creation of users at explicit times.
Use specified timestamp of 1 month before current time to place account
creation in time before most activities for testing.
@StormFireFox1 StormFireFox1 merged commit ca28168 into master Aug 2, 2021
@shravanhariharan2 shravanhariharan2 deleted the add-admin-test-suite branch May 8, 2022 21:22
nick-ls pushed a commit to nick-ls/membership-portal that referenced this pull request Aug 6, 2024
* Add tests for "/bonus" and "/emails" routes

Squashed set of commits for 6f51db8...c70e444. Merge conflict
was on package-lock, which was hard to fix, so I just redid the commits.

* nit: "proxyUser" -> "adminUser" for admin tests

* Adjust array equality checks on admin tests

* Remove test for non-present emails

Test is not necessary due to lack of filtering in original controller.

* Inline functions and variables in admin tests

* Modify test to check bonus points for all users

* Combine both bonus points tests into one

Tests had basically the same boilerplate. Combine them to check both
conditions at once.

The test already checked if we were adding bonus point to _specifically_
the emails we passed in, so it's best to also check if an extra user
wasn't included at the same time.

* Rearrange asserts to suffix response calls

* Rename adminUser to admin in admin test suite

* Adjust order of assertions in admin test

* Adjust name of extraneous user in admin test

* Make variable for UserController in admin test

Inlining UserController made one line too long.
Since it is used multiple times in the test, extract
variable to make its usage less verbose.

* Fix nits and check attendance response details

* Check for correct activities in admin test suite

* Add points field of ActivityModel in test suite

ActivityModel is missing the `pointsEarned` field whenever creating
an Activity after attending an event. This only happens in our mock
tester.

Add a check for this field's presence, along with fixing the inherent
bug within the mock state.

* Port EventFactory code from acmucsd#181

Code from acmucsd#181 adds ability to fake events in the past, future or present.
Taken verbatim from commit 18a952c.

* Adjust test suite to account for factory bug

Account creation can occur after event attendance, causing activities
to be out of order chronologically. Guarantee order in activities by
introducing retroactive attendance in a future event.

Bug in factory is not a reproducible issue in production, since account
creation will always occur before event attendance in real time.

* Revert event factory code changes

* Adjust transaction order when saving factory state

Mock factory `write` function incorrectly saves attendance before
any possible activities, typically causing event attendances to be
stored in the database prior to activities being stored. Adjust order
of flushing to database in order to consistently set smaller timestamps
for account-related activities, such as account creation.

* Revert transaction order adjustment

This reverts commit b5f03dc.

Tests continue to be non-deterministic despite this change. My
assumption was wrong.

* Guarantee correct activity order in failed tests

Create users at beginning of the Unix epoch to ensure guarantee
of event attendance activity being second is fulfilled.

Since Activities are sorted by timestamp, we need to guarantee account
creation does not occur before attendance of event. Fix issue with above
workaround, providing explicit method whenever necessary.

* Merge user creation methods to have optional args

Rather than having two explicit methods, merge methods and use optional
timestamp argument to allow for custom creation of users at explicit times.

* Adjust user creation method to have set timestamp

Use specified timestamp of 1 month before current time to place account
creation in time before most activities for testing.

* Fix argument call for creating users in test suite

Co-authored-by: Matei-Alexandru Gardus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write admin controller test suite
3 participants