@@ -291,6 +291,159 @@ describe("Registration route", () => {
291291 } ) ;
292292 } ) ;
293293
294+ describe ( "GET /v1/events/:eventId/registrations" , ( ) => {
295+ beforeEach ( async ( ) => {
296+ await db . insert ( usersTable ) . values ( [
297+ { id :
"user-1" , email :
"[email protected] " , firstName :
"U" , lastName :
"1" } , 298+ { id :
"user-2" , email :
"[email protected] " , firstName :
"U" , lastName :
"2" } , 299+ ] ) ;
300+
301+ await db . insert ( eventsTable ) . values ( {
302+ id : "test-event" ,
303+ title : "Test Event" ,
304+ state : "published" ,
305+ aboutMarkdown : "markdown" ,
306+ organiser : "projectShare" ,
307+ date : new Date ( ) ,
308+ } ) ;
309+
310+ await db . insert ( registrationsTable ) . values ( [
311+ { userId : "user-1" , eventId : "test-event" , status : "accepted" } ,
312+ { userId : "user-2" , eventId : "test-event" , status : "pending" } ,
313+ ] ) ;
314+ } ) ;
315+
316+ it ( "should filter registrations by status query param" , async ( ) => {
317+ setMockAuth ( {
318+ userId : "committee-user" ,
319+ sessionClaims : { metadata : { role : "committee" } } ,
320+ } ) ;
321+
322+ const response = await app . inject ( {
323+ method : "GET" ,
324+ url : "/v1/events/test-event/registrations" ,
325+ query : { status : "accepted" } ,
326+ } ) ;
327+
328+ expect ( response . statusCode ) . toBe ( 200 ) ;
329+ const data = response . json ( ) ;
330+ expect ( data ) . toHaveLength ( 1 ) ;
331+ expect ( data [ 0 ] . userId ) . toBe ( "user-1" ) ;
332+ expect ( data [ 0 ] . status ) . toBe ( "accepted" ) ;
333+ } ) ;
334+
335+ it ( "should filter registrations by userId query param" , async ( ) => {
336+ setMockAuth ( {
337+ userId : "committee-user" ,
338+ sessionClaims : { metadata : { role : "committee" } } ,
339+ } ) ;
340+
341+ const response = await app . inject ( {
342+ method : "GET" ,
343+ url : "/v1/events/test-event/registrations" ,
344+ query : { userId : "user-2" } ,
345+ } ) ;
346+
347+ expect ( response . statusCode ) . toBe ( 200 ) ;
348+ const data = response . json ( ) ;
349+ expect ( data ) . toHaveLength ( 1 ) ;
350+ expect ( data [ 0 ] . userId ) . toBe ( "user-2" ) ;
351+ } ) ;
352+
353+ it ( "should respect pagination limits" , async ( ) => {
354+ setMockAuth ( {
355+ userId : "committee-user" ,
356+ sessionClaims : { metadata : { role : "committee" } } ,
357+ } ) ;
358+
359+ const response = await app . inject ( {
360+ method : "GET" ,
361+ url : "/v1/events/test-event/registrations" ,
362+ query : { limit : "1" } ,
363+ } ) ;
364+
365+ expect ( response . statusCode ) . toBe ( 200 ) ;
366+ const data = response . json ( ) ;
367+ expect ( data . length ) . toBeLessThanOrEqual ( 1 ) ;
368+ } ) ;
369+
370+ it ( "should return empty array if event has no registrations" , async ( ) => {
371+ setMockAuth ( {
372+ userId : "committee-user" ,
373+ sessionClaims : { metadata : { role : "committee" } } ,
374+ } ) ;
375+
376+ await db . insert ( eventsTable ) . values ( {
377+ id : "empty-event" ,
378+ title : "Empty Event" ,
379+ state : "published" ,
380+ aboutMarkdown : "md" ,
381+ organiser : "projectShare" ,
382+ date : new Date ( ) ,
383+ } ) ;
384+
385+ const response = await app . inject ( {
386+ method : "GET" ,
387+ url : "/v1/events/empty-event/registrations" ,
388+ } ) ;
389+
390+ expect ( response . statusCode ) . toBe ( 200 ) ;
391+ expect ( response . json ( ) ) . toEqual ( [ ] ) ;
392+ } ) ;
393+ } ) ;
394+
395+ describe ( "GET /v1/events/:eventId/registrations/me" , ( ) => {
396+ beforeEach ( async ( ) => {
397+ await db . insert ( usersTable ) . values ( [
398+ { id :
"test-user" , email :
"[email protected] " , firstName :
"Test" , lastName :
"User" } , 399+ { id :
"other-user" , email :
"[email protected] " , firstName :
"Other" , lastName :
"User" } , 400+ ] ) ;
401+
402+ await db . insert ( eventsTable ) . values ( {
403+ id : "test-event" ,
404+ title : "Test Event" ,
405+ state : "published" ,
406+ aboutMarkdown : "markdown" ,
407+ organiser : "projectShare" ,
408+ date : new Date ( ) ,
409+ } ) ;
410+
411+ await db . insert ( registrationsTable ) . values ( {
412+ userId : "test-user" ,
413+ eventId : "test-event" ,
414+ status : "pending" ,
415+ } ) ;
416+ } ) ;
417+
418+ it ( "should return 401 if user is not authenticated" , async ( ) => {
419+ setMockAuth ( { userId : null , sessionClaims : null } ) ;
420+
421+ const response = await app . inject ( {
422+ method : "GET" ,
423+ url : "/v1/events/test-event/registrations/me" ,
424+ } ) ;
425+
426+ expect ( response . statusCode ) . toBe ( 401 ) ;
427+ } ) ;
428+
429+ it ( "should allow a user to fetch their own registration" , async ( ) => {
430+ setMockAuth ( {
431+ userId : "test-user" ,
432+ sessionClaims : { metadata : { role : "member" } } ,
433+ } ) ;
434+
435+ const response = await app . inject ( {
436+ method : "GET" ,
437+ url : "/v1/events/test-event/registrations/me" ,
438+ } ) ;
439+
440+ expect ( response . statusCode ) . toBe ( 200 ) ;
441+ const data = response . json ( ) ;
442+ expect ( data . userId ) . toBe ( "test-user" ) ;
443+ expect ( data . eventId ) . toBe ( "test-event" ) ;
444+ } ) ;
445+ } ) ;
446+
294447 describe ( "DELETE /v1/events/:eventId/registrations/:targetUserId" , ( ) => {
295448 beforeEach ( async ( ) => {
296449 await db . insert ( usersTable ) . values ( [
0 commit comments