11import { expect , test } from "vitest" ;
22import { EventsGetResponse } from "../../src/api/routes/events.js" ;
33import { createJwt } from "./utils.js" ;
4+ import { describe } from "node:test" ;
45
56const baseEndpoint = `https://infra-core-api.aws.qa.acmuiuc.org` ;
6- let createdEventUuid ;
77test ( "getting events" , async ( ) => {
88 const response = await fetch ( `${ baseEndpoint } /api/v1/events` ) ;
99 expect ( response . status ) . toBe ( 200 ) ;
1010 const responseJson = ( await response . json ( ) ) as EventsGetResponse ;
1111 expect ( responseJson . length ) . greaterThan ( 0 ) ;
1212} ) ;
1313
14- test ( "creating an event" , async ( ) => {
15- const token = await createJwt ( ) ;
16- const response = await fetch ( `${ baseEndpoint } /api/v1/events` , {
17- method : "POST" ,
18- headers : {
19- Authorization : `Bearer ${ token } ` ,
20- "Content-Type" : "application/json" ,
21- } ,
22- body : JSON . stringify ( {
23- title : "Testing Event" ,
24- description : "An event of all time" ,
25- start : "2024-12-31T02:00:00" ,
26- end : "2024-12-31T03:30:00" ,
27- location : "ACM Room (Siebel 1104)" ,
28- host : "ACM" ,
29- featured : true ,
30- } ) ,
14+ describe ( "Event lifecycle tests" , async ( ) => {
15+ let createdEventUuid ;
16+ test ( "creating an event" , { timeout : 30000 } , async ( ) => {
17+ const token = await createJwt ( ) ;
18+ const response = await fetch ( `${ baseEndpoint } /api/v1/events` , {
19+ method : "POST" ,
20+ headers : {
21+ Authorization : `Bearer ${ token } ` ,
22+ "Content-Type" : "application/json" ,
23+ } ,
24+ body : JSON . stringify ( {
25+ title : "Testing Event" ,
26+ description : "An event of all time" ,
27+ start : "2024-12-31T02:00:00" ,
28+ end : "2024-12-31T03:30:00" ,
29+ location : "ACM Room (Siebel 1104)" ,
30+ host : "ACM" ,
31+ featured : true ,
32+ } ) ,
33+ } ) ;
34+ const responseJson = await response . json ( ) ;
35+ expect ( response . status ) . toBe ( 201 ) ;
36+ expect ( responseJson ) . toHaveProperty ( "id" ) ;
37+ expect ( responseJson ) . toHaveProperty ( "resource" ) ;
38+ createdEventUuid = responseJson . id ;
3139 } ) ;
32- expect ( response . status ) . toBe ( 201 ) ;
33- const responseJson = await response . json ( ) ;
34- expect ( responseJson ) . toHaveProperty ( "id" ) ;
35- expect ( responseJson ) . toHaveProperty ( "resource" ) ;
36- createdEventUuid = responseJson . id ;
37- } ) ;
3840
39- test . runIf ( createdEventUuid ) (
40- "deleting a previously-created event" ,
41- async ( ) => {
41+ test ( "deleting a previously-created event" , { timeout : 30000 } , async ( ) => {
42+ if ( ! createdEventUuid ) {
43+ throw new Error ( "Event UUID not found" ) ;
44+ }
4245 const token = await createJwt ( ) ;
4346 const response = await fetch (
4447 `${ baseEndpoint } /api/v1/events/${ createdEventUuid } ` ,
@@ -50,18 +53,18 @@ test.runIf(createdEventUuid)(
5053 } ,
5154 ) ;
5255 expect ( response . status ) . toBe ( 201 ) ;
53- } ,
54- ) ;
56+ } ) ;
5557
56- test . runIf ( createdEventUuid ) (
57- "check that deleted events cannot be found" ,
58- async ( ) => {
58+ test ( "check that deleted events cannot be found" , async ( ) => {
59+ if ( ! createdEventUuid ) {
60+ throw new Error ( "Event UUID not found" ) ;
61+ }
5962 const response = await fetch (
6063 `${ baseEndpoint } /api/v1/events/${ createdEventUuid } ` ,
6164 {
6265 method : "GET" ,
6366 } ,
6467 ) ;
6568 expect ( response . status ) . toBe ( 404 ) ;
66- } ,
67- ) ;
69+ } ) ;
70+ } ) ;
0 commit comments