-
Notifications
You must be signed in to change notification settings - Fork 17
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
Event Tests #122
Draft
AydanPirani
wants to merge
9
commits into
main
Choose a base branch
from
dev/aydan/events-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Event Tests #122
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
49d4213
Initial event get tests
AydanPirani ea97224
probably not a good idea for test events to have the same id...
AydanPirani cdff6f3
removed extra error handler
AydanPirani 155f37c
Added tests for metadata get
AydanPirani 3923a2c
Formatter changes
AydanPirani b2aa837
Added tests for get endpoint
AydanPirani cde3cf2
Formatter changes
AydanPirani 5c5caae
added event delete tests
AydanPirani 11149e2
Added metadata put tests
AydanPirani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,4 +124,6 @@ export class EventAttendance { | |
}, | ||
}) | ||
public attendees: string[]; | ||
|
||
public isStaff = true; | ||
} |
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,244 @@ | ||
import { describe, expect, it, beforeEach } from "@jest/globals"; | ||
import { StatusCode } from "status-code-enum"; | ||
import Models from "../../database/models.js"; | ||
import { | ||
delAsAdmin, | ||
delAsAttendee, | ||
delAsStaff, | ||
getAsAttendee, | ||
getAsStaff, | ||
putAsAdmin, | ||
putAsAttendee, | ||
putAsStaff, | ||
} from "../../testTools.js"; | ||
|
||
const EXTERNAL_PUBLIC_EVENT = { | ||
eventId: "11111c072182654f163f5f0f9a621d72", | ||
name: "Example Pub Event 10", | ||
description: "This is a description", | ||
startTime: 1532202702, | ||
endTime: 1532212702, | ||
locations: [ | ||
{ | ||
description: "Example Location", | ||
tags: ["SIEBEL0", "ECEB1"], | ||
latitude: 40.1138, | ||
longitude: -88.2249, | ||
}, | ||
], | ||
sponsor: "Example sponsor", | ||
eventType: "OTHER", | ||
points: 0, | ||
}; | ||
|
||
const INTERNAL_PUBLIC_EVENT = { | ||
...EXTERNAL_PUBLIC_EVENT, | ||
displayOnStaffCheckIn: false, | ||
isPrivate: false, | ||
isAsync: false, | ||
}; | ||
|
||
const EXTERNAL_STAFF_EVENT = { | ||
eventId: "00000c072182654f163f5f0f9a621d72", | ||
name: "Example Staff Event 10", | ||
description: "This is a description", | ||
startTime: 1532202702, | ||
endTime: 1532212702, | ||
locations: [], | ||
eventType: "OTHER", | ||
}; | ||
|
||
const INTERNAL_STAFF_EVENT = { | ||
...EXTERNAL_STAFF_EVENT, | ||
sponsor: "Example sponsor", | ||
displayOnStaffCheckIn: false, | ||
isPrivate: false, | ||
isAsync: false, | ||
isStaff: true, | ||
}; | ||
|
||
const PUBLIC_METADATA = { | ||
eventId: "11111c072182654f163f5f0f9a621d72", | ||
isStaff: false, | ||
exp: 1234567890, | ||
}; | ||
|
||
const STAFF_METADATA = { | ||
eventId: "00000c072182654f163f5f0f9a621d72", | ||
isStaff: true, | ||
exp: 1234567890, | ||
}; | ||
|
||
beforeEach(async () => { | ||
Models.initialize(); | ||
await Models.StaffEvent.create(INTERNAL_STAFF_EVENT); | ||
await Models.PublicEvent.create(INTERNAL_PUBLIC_EVENT); | ||
await Models.EventMetadata.create(PUBLIC_METADATA); | ||
await Models.EventMetadata.create(STAFF_METADATA); | ||
}); | ||
|
||
describe("GET /event/", () => { | ||
it("returns only filtered attendee events for attendees", async () => { | ||
const response = await getAsAttendee("/event/").expect(StatusCode.SuccessOK); | ||
|
||
expect(JSON.parse(response.text)).toMatchObject({ | ||
events: [EXTERNAL_PUBLIC_EVENT], | ||
}); | ||
}); | ||
|
||
it("returns all attendee events for staff", async () => { | ||
const response = await getAsStaff("/event/").expect(StatusCode.SuccessOK); | ||
|
||
expect(JSON.parse(response.text)).toMatchObject({ | ||
events: [INTERNAL_PUBLIC_EVENT], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("GET /event/staff/", () => { | ||
it("cannot be accessed by a non-staff user", async () => { | ||
const response = await getAsAttendee("/event/staff/").expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("returns staff events for staff endpoint", async () => { | ||
const response = await getAsStaff("/event/staff/").expect(StatusCode.SuccessOK); | ||
expect(JSON.parse(response.text)).toMatchObject({ | ||
events: [EXTERNAL_STAFF_EVENT], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("GET /event/:EVENTID", () => { | ||
it("throws an error if the event doesn't exist", async () => { | ||
const eventId = "00000"; | ||
const response = await getAsAttendee(`/event/${eventId}`).expect(StatusCode.ClientErrorBadRequest); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("throws an error if attendees try to access staff events", async () => { | ||
const eventId = STAFF_METADATA.eventId; | ||
const response = await getAsAttendee(`/event/${eventId}`).expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("throws an error if it cannot find a staff event", async () => { | ||
const eventId = STAFF_METADATA.eventId; | ||
await Models.StaffEvent.deleteOne({ eventId: eventId }); | ||
const response = await getAsStaff(`/event/${eventId}`).expect(StatusCode.ServerErrorInternal); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("throws an error if it cannot find a public event", async () => { | ||
const eventId = PUBLIC_METADATA.eventId; | ||
await Models.PublicEvent.deleteOne({ eventId: eventId }); | ||
const response = await getAsAttendee(`/event/${eventId}`).expect(StatusCode.ServerErrorInternal); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("successfully returns staff events", async () => { | ||
const eventId = STAFF_METADATA.eventId; | ||
const response = await getAsStaff(`/event/${eventId}`).expect(StatusCode.SuccessOK); | ||
expect(JSON.parse(response.text)).toMatchObject(EXTERNAL_STAFF_EVENT); | ||
}); | ||
|
||
it("successfully filters and returns a public event for staff", async () => { | ||
const eventId = PUBLIC_METADATA.eventId; | ||
const response = await getAsStaff(`/event/${eventId}`).expect(StatusCode.SuccessOK); | ||
expect(JSON.parse(response.text)).toMatchObject(INTERNAL_PUBLIC_EVENT); | ||
}); | ||
|
||
it("successfully filters and returns a public event for attendees", async () => { | ||
const eventId = PUBLIC_METADATA.eventId; | ||
const response = await getAsAttendee(`/event/${eventId}`).expect(StatusCode.SuccessOK); | ||
expect(JSON.parse(response.text)).toMatchObject(EXTERNAL_PUBLIC_EVENT); | ||
}); | ||
}); | ||
|
||
describe("GET /event/metadata/:EVENTID", () => { | ||
it("cannot be accessed by a non-staff user", async () => { | ||
const eventId = PUBLIC_METADATA.eventId; | ||
const response = await getAsAttendee(`/event/metadata/${eventId}`).expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("returns metadata for a particular eventId", async () => { | ||
const eventId = PUBLIC_METADATA.eventId; | ||
const response = await getAsStaff(`/event/metadata/${eventId}`).expect(StatusCode.SuccessOK); | ||
expect(JSON.parse(response.text)).toMatchObject(PUBLIC_METADATA); | ||
}); | ||
|
||
it("throws an error if a bad eventId is passed in", async () => { | ||
const eventId = "badEventId"; | ||
const response = await getAsStaff(`/event/metadata/${eventId}`).expect(StatusCode.ClientErrorBadRequest); | ||
expect(JSON.parse(response.text)).toHaveProperty("error"); | ||
}); | ||
}); | ||
|
||
describe("DELETE /event/:EVENTID", () => { | ||
it("cannot be accessed by an attendee", async () => { | ||
const eventId = "deleteEventId"; | ||
const response = await delAsAttendee(`/event/${eventId}`).expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("cannot be accessed by staff", async () => { | ||
const eventId = "deleteEventId"; | ||
const response = await delAsStaff(`/event/${eventId}`).expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("deletes the events correctly from both tables", async () => { | ||
const eventId = "deleteEventId"; | ||
await delAsAdmin(`/event/${eventId}`).expect(StatusCode.SuccessNoContent); | ||
|
||
const metadata = await Models.EventMetadata.findOne({ eventId: eventId }); | ||
const event = await Models.PublicEvent.findOne({ eventId: eventId }); | ||
|
||
expect(metadata).toBeNull(); | ||
expect(event).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("PUT /event/metadata/", () => { | ||
it("cannot be accessed by attendee", async () => { | ||
const response = await putAsAttendee(`/event/metadata/`).expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("cannot be accessed by staff", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need to test for every level - just test the level below what is expect (staff for admin only, attendee for staff only, etc) |
||
const response = await putAsStaff(`/event/metadata/`).expect(StatusCode.ClientErrorForbidden); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("throws an error if an invalid input is passed in", async () => { | ||
const mockInput = { | ||
eventId: EXTERNAL_PUBLIC_EVENT.eventId, | ||
}; | ||
|
||
const response = await putAsAdmin(`/event/metadata/`).send(mockInput).expect(StatusCode.ClientErrorBadRequest); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("throws an error if an event does not exist", async () => { | ||
const mockInput = { | ||
eventId: "0".repeat(32), | ||
exp: 100, | ||
}; | ||
|
||
const response = await putAsAdmin(`/event/metadata/`).send(mockInput).expect(StatusCode.ClientErrorBadRequest); | ||
expect(response).toHaveProperty("error"); | ||
}); | ||
|
||
it("modifies the event expiration dates", async () => { | ||
const eventId = EXTERNAL_PUBLIC_EVENT.eventId; | ||
const mockInput = { | ||
eventId: eventId, | ||
exp: 100, | ||
}; | ||
|
||
const response = await putAsAdmin(`/event/metadata/`).send(mockInput).expect(StatusCode.SuccessOK); | ||
expect(JSON.parse(response.text)); | ||
expect(await Models.EventMetadata.findOne({ eventId })).toMatchObject(mockInput); | ||
}); | ||
}); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: Use satisfies to verify correctness