-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Events Following/Unfollowing (#137)
* event-favorites * revert yarn.lock and package.json * revert package.json + yarn.lock * fix format * added event-favorites test * change /event/favorites/ to /event/followers/ * change from EventFollowing to EventFollowers * Finished up event favorites * Fixed build issues * Made code more consistent * Update user-router.ts --------- Co-authored-by: npunati27 <nikhitapunati@gmail.com>
- Loading branch information
1 parent
e1817b0
commit 630f942
Showing
8 changed files
with
7,233 additions
and
6,792 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { describe, expect, it, beforeEach } from "@jest/globals"; | ||
import { EventFollowers } from "database/event-db.js"; | ||
import { AttendeeFollowing } from "database/attendee-db.js"; | ||
import Models from "../../database/models.js"; | ||
import { StatusCode } from "status-code-enum"; | ||
import { TESTER, getAsAttendee, getAsStaff } from "../../testTools.js"; | ||
|
||
const TESTER_EVENT_FOLLOWERS = { | ||
eventId: "other-event", | ||
followers: ["user5", "user8"], | ||
} satisfies EventFollowers; | ||
|
||
const TESTER_ATTENDEE_FOLLOWING = { | ||
userId: TESTER.id, | ||
events: ["event3", "event9"], | ||
} satisfies AttendeeFollowing; | ||
|
||
// Before each test, initialize database with tester & other users | ||
beforeEach(async () => { | ||
Models.initialize(); | ||
await Models.EventFollowers.create(TESTER_EVENT_FOLLOWERS); | ||
await Models.AttendeeFollowing.create(TESTER_ATTENDEE_FOLLOWING); | ||
}); | ||
|
||
describe("GET /event/followers/:EVENTID", () => { | ||
it("gives an forbidden error for a non-staff user", async () => { | ||
const response = await getAsAttendee(`/event/followers/${TESTER_EVENT_FOLLOWERS.eventId}/`).expect( | ||
StatusCode.ClientErrorForbidden, | ||
); | ||
|
||
expect(JSON.parse(response.text)).toHaveProperty("error", "Forbidden"); | ||
}); | ||
|
||
it("gives an not found error for a non-existent event", async () => { | ||
await Models.EventFollowers.deleteOne({ | ||
eventId: TESTER_EVENT_FOLLOWERS.eventId, | ||
}); | ||
|
||
const response = await getAsStaff(`/event/followers/${TESTER_EVENT_FOLLOWERS.eventId}/`).expect( | ||
StatusCode.ClientErrorNotFound, | ||
); | ||
|
||
expect(JSON.parse(response.text)).toHaveProperty("error", "EventNotFound"); | ||
}); | ||
|
||
it("works for a staff user", async () => { | ||
const response = await getAsStaff(`/event/followers/${TESTER_EVENT_FOLLOWERS.eventId}/`).expect(StatusCode.SuccessOK); | ||
|
||
expect(JSON.parse(response.text)).toMatchObject({ | ||
eventId: TESTER_EVENT_FOLLOWERS.eventId, | ||
followers: TESTER_EVENT_FOLLOWERS.followers, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.