Skip to content

Commit

Permalink
Scope get event id endpoint to admins only (#817)
Browse files Browse the repository at this point in the history
* Scope get event id endpoint to admins only

* Updated endpoint

* Updated interfaces

* Updated tests

* Generate swagger

* Regenerate schema and update endpoint in controller and tests

* Update tests to use admin jwt
  • Loading branch information
jeffplays2005 authored Nov 2, 2024
1 parent 84b1c9c commit def9819
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 155 deletions.
44 changes: 21 additions & 23 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 41 additions & 40 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 47 additions & 43 deletions server/src/middleware/__generated__/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions server/src/middleware/tests/AdminController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,35 @@ describe("AdminController endpoint tests", () => {
).toEqual(newDate)
})
})
describe("GET /admin/events/:id", () => {
const event1: Event = {
title: "UASC New event",
physical_start_date: dateToFirestoreTimeStamp(new Date()),
location: "UASC",
sign_up_start_date: dateToFirestoreTimeStamp(new Date()),
sign_up_end_date: dateToFirestoreTimeStamp(new Date())
}
const eventService = new EventService()

it("should return the event details for a valid event ID", async () => {
const { id: id1 } = await eventService.createEvent(event1)
const res = await request
.get(`/admin/events/${id1}`)
.set("Authorization", `Bearer ${adminToken}`)
.send()
expect(res.status).toEqual(200)
expect(res.body.data).toBeDefined()
expect(res.body.data.title).toEqual("UASC New event")
expect(res.body.data.location).toEqual("UASC")
})

it("should return 404 if the event does not exist", async () => {
const res = await request
.get("/admin/events/random-event")
.set("Authorization", `Bearer ${adminToken}`)
.send()
expect(res.status).toEqual(404)
expect(res.body.error).toEqual("Event not found.")
})
})
})
17 changes: 0 additions & 17 deletions server/src/middleware/tests/EventController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,4 @@ describe("EventController endpoint tests", () => {
)
})
})

describe("GET /events/:id", () => {
it("should return the event details for a valid event ID", async () => {
const { id: id1 } = await eventService.createEvent(event1)
const res = await request.get(`/events/${id1}`).send()
expect(res.status).toEqual(200)
expect(res.body.data).toBeDefined()
expect(res.body.data.title).toEqual("UASC New event")
expect(res.body.data.location).toEqual("UASC")
})

it("should return 404 if the event does not exist", async () => {
const res = await request.get("/events/random-event").send()
expect(res.status).toEqual(404)
expect(res.body.error).toEqual("Event not found.")
})
})
})
Loading

0 comments on commit def9819

Please sign in to comment.