11import  {  afterAll ,  expect ,  test ,  beforeEach ,  vi ,  describe  }  from  "vitest" ; 
22import  { 
33  AttributeValue , 
4+   ConditionalCheckFailedException , 
45  DynamoDBClient , 
56  QueryCommand , 
67  ScanCommand , 
@@ -204,10 +205,19 @@ describe("Test ticket purchase verification", async () => {
204205    } ) ; 
205206  } ) ; 
206207  test ( "Sad path: fulfilling an already-fulfilled ticket item fails" ,  async  ( )  =>  { 
207-     ddbMock 
208-       . on ( UpdateItemCommand ) 
209-       . resolvesOnce ( {  Attributes : fulfilledMerchItem1  } ) 
210-       . resolvesOnce ( { } ) ; 
208+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
209+       message : "The conditional request failed" , 
210+       $metadata : { } , 
211+     } ) ; 
212+     ( conditionalError  as  any ) . Item  =  { 
213+       ticket_id : { 
214+         S : "975b4470cf37d7cf20fd404a711513fd1d1e68259ded27f10727d1384961843d" , 
215+       } , 
216+       used : {  BOOL : true  } , 
217+       refunded : {  BOOL : false  } , 
218+     } ; 
219+ 
220+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
211221
212222    const  testJwt  =  createJwt ( ) ; 
213223    await  app . ready ( ) ; 
@@ -228,6 +238,68 @@ describe("Test ticket purchase verification", async () => {
228238      name : "TicketNotValidError" , 
229239    } ) ; 
230240  } ) ; 
241+ 
242+   test ( "Sad path: ticket was refunded" ,  async  ( )  =>  { 
243+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
244+       message : "The conditional request failed" , 
245+       $metadata : { } , 
246+     } ) ; 
247+     ( conditionalError  as  any ) . Item  =  { 
248+       ticket_id : { 
249+         S : "975b4470cf37d7cf20fd404a711513fd1d1e68259ded27f10727d1384961843d" , 
250+       } , 
251+       used : {  BOOL : false  } , 
252+       refunded : {  BOOL : true  } , 
253+     } ; 
254+ 
255+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
256+ 
257+     const  testJwt  =  createJwt ( ) ; 
258+     await  app . ready ( ) ; 
259+     const  response  =  await  supertest ( app . server ) 
260+       . post ( "/api/v1/tickets/checkIn" ) 
261+       . set ( "authorization" ,  `Bearer ${ testJwt }  ` ) 
262+       . send ( { 
263+         type : "ticket" , 
264+         ticketId :
265+           "975b4470cf37d7cf20fd404a711513fd1d1e68259ded27f10727d1384961843d" , 
266+       } ) ; 
267+     const  responseDataJson  =  response . body ; 
268+     expect ( response . statusCode ) . toEqual ( 400 ) ; 
269+     expect ( responseDataJson ) . toEqual ( { 
270+       error : true , 
271+       id : 109 , 
272+       message : "Ticket was already refunded." , 
273+       name : "TicketNotValidError" , 
274+     } ) ; 
275+   } ) ; 
276+ 
277+   test ( "Sad path: ticket does not exist" ,  async  ( )  =>  { 
278+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
279+       message : "The conditional request failed" , 
280+       $metadata : { } , 
281+     } ) ; 
282+ 
283+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
284+ 
285+     const  testJwt  =  createJwt ( ) ; 
286+     await  app . ready ( ) ; 
287+     const  response  =  await  supertest ( app . server ) 
288+       . post ( "/api/v1/tickets/checkIn" ) 
289+       . set ( "authorization" ,  `Bearer ${ testJwt }  ` ) 
290+       . send ( { 
291+         type : "ticket" , 
292+         ticketId : "nonexistentticketid123456789" , 
293+       } ) ; 
294+     const  responseDataJson  =  response . body ; 
295+     expect ( response . statusCode ) . toEqual ( 400 ) ; 
296+     expect ( responseDataJson ) . toEqual ( { 
297+       error : true , 
298+       id : 108 , 
299+       message : "Ticket does not exist." , 
300+       name : "TicketNotFoundError" , 
301+     } ) ; 
302+   } ) ; 
231303} ) ; 
232304
233305describe ( "Test merch purchase verification" ,  async  ( )  =>  { 
@@ -287,10 +359,18 @@ describe("Test merch purchase verification", async () => {
287359    } ) ; 
288360  } ) ; 
289361  test ( "Sad path: fulfilling a refunded merch item fails" ,  async  ( )  =>  { 
290-     ddbMock 
291-       . on ( UpdateItemCommand ) 
292-       . resolvesOnce ( {  Attributes : refundedMerchItem  } ) 
293-       . resolvesOnce ( { } ) ; 
362+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
363+       message : "The conditional request failed" , 
364+       $metadata : { } , 
365+     } ) ; 
366+     ( conditionalError  as  any ) . Item  =  { 
367+       stripe_pi : {  S : "pi_6T9QvUwR2IOj4CyF35DsXK7P"  } , 
368+       email : 
{  S : 
"[email protected] "  } ,  369+       fulfilled : {  BOOL : false  } , 
370+       refunded : {  BOOL : true  } , 
371+     } ; 
372+ 
373+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
294374
295375    const  testJwt  =  createJwt ( ) ; 
296376    await  app . ready ( ) ; 
@@ -312,10 +392,18 @@ describe("Test merch purchase verification", async () => {
312392    } ) ; 
313393  } ) ; 
314394  test ( "Sad path: fulfilling an already-fulfilled merch item fails" ,  async  ( )  =>  { 
315-     ddbMock 
316-       . on ( UpdateItemCommand ) 
317-       . resolvesOnce ( {  Attributes : fulfilledMerchItem1  } ) 
318-       . resolvesOnce ( { } ) ; 
395+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
396+       message : "The conditional request failed" , 
397+       $metadata : { } , 
398+     } ) ; 
399+     ( conditionalError  as  any ) . Item  =  { 
400+       stripe_pi : {  S : "pi_3Q5GewDiGOXU9RuS16txRR5D"  } , 
401+       email : 
{  S : 
"[email protected] "  } ,  402+       fulfilled : {  BOOL : true  } , 
403+       refunded : {  BOOL : false  } , 
404+     } ; 
405+ 
406+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
319407
320408    const  testJwt  =  createJwt ( ) ; 
321409    await  app . ready ( ) ; 
@@ -336,6 +424,68 @@ describe("Test merch purchase verification", async () => {
336424      name : "TicketNotValidError" , 
337425    } ) ; 
338426  } ) ; 
427+ 
428+   test ( "Sad path: merch item does not exist" ,  async  ( )  =>  { 
429+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
430+       message : "The conditional request failed" , 
431+       $metadata : { } , 
432+     } ) ; 
433+ 
434+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
435+ 
436+     const  testJwt  =  createJwt ( ) ; 
437+     await  app . ready ( ) ; 
438+     const  response  =  await  supertest ( app . server ) 
439+       . post ( "/api/v1/tickets/checkIn" ) 
440+       . set ( "authorization" ,  `Bearer ${ testJwt }  ` ) 
441+       . send ( { 
442+         type : "merch" , 
443+ 444+         stripePi : "pi_nonexistent123456" , 
445+       } ) ; 
446+     const  responseDataJson  =  response . body ; 
447+     expect ( response . statusCode ) . toEqual ( 400 ) ; 
448+     expect ( responseDataJson ) . toEqual ( { 
449+       error : true , 
450+       id : 108 , 
451+       message : "Ticket does not exist." , 
452+       name : "TicketNotFoundError" , 
453+     } ) ; 
454+   } ) ; 
455+ 
456+   test ( "Sad path: wrong email for merch item" ,  async  ( )  =>  { 
457+     const  conditionalError  =  new  ConditionalCheckFailedException ( { 
458+       message : "The conditional request failed" , 
459+       $metadata : { } , 
460+     } ) ; 
461+     ( conditionalError  as  any ) . Item  =  { 
462+       stripe_pi : {  S : "pi_8J4NrYdA3S7cW8Ty92FnGJ6L"  } , 
463+       email : 
{  S : 
"[email protected] "  } ,  464+       fulfilled : {  BOOL : false  } , 
465+       refunded : {  BOOL : false  } , 
466+     } ; 
467+ 
468+     ddbMock . on ( UpdateItemCommand ) . rejects ( conditionalError ) ; 
469+ 
470+     const  testJwt  =  createJwt ( ) ; 
471+     await  app . ready ( ) ; 
472+     const  response  =  await  supertest ( app . server ) 
473+       . post ( "/api/v1/tickets/checkIn" ) 
474+       . set ( "authorization" ,  `Bearer ${ testJwt }  ` ) 
475+       . send ( { 
476+         type : "merch" , 
477+ 478+         stripePi : "pi_8J4NrYdA3S7cW8Ty92FnGJ6L" , 
479+       } ) ; 
480+     const  responseDataJson  =  response . body ; 
481+     expect ( response . statusCode ) . toEqual ( 400 ) ; 
482+     expect ( responseDataJson ) . toEqual ( { 
483+       error : true , 
484+       id : 108 , 
485+       message : "Ticket does not exist." , 
486+       name : "TicketNotFoundError" , 
487+     } ) ; 
488+   } ) ; 
339489} ) ; 
340490
341491describe ( "Test getting all issued tickets" ,  async  ( )  =>  { 
0 commit comments