11import { afterAll , expect , test , beforeEach , vi , describe } from "vitest" ;
2- import { DynamoDBClient , UpdateItemCommand } from "@aws-sdk/client-dynamodb" ;
2+ import {
3+ DynamoDBClient ,
4+ QueryCommand ,
5+ UpdateItemCommand ,
6+ } from "@aws-sdk/client-dynamodb" ;
37import { mockClient } from "aws-sdk-client-mock" ;
48import init from "../../src/index.js" ;
5- import { EventGetResponse } from "../../src/routes/events.js" ;
69import { secretObject } from "./secret.testdata.js" ;
710import {
11+ dynamoTableData ,
812 fulfilledMerchItem1 ,
913 refundedMerchItem ,
1014 unfulfilledMerchItem1 ,
@@ -39,7 +43,7 @@ describe("Test ticket purchase verification", async () => {
3943 ticketId :
4044 "9d98e1e3c2138c93dd5a284239eddfa9c3037a0862972cd0f51ee1b54257a37e" ,
4145 } ) ;
42- const responseDataJson = response . body as EventGetResponse ;
46+ const responseDataJson = response . body ;
4347 expect ( response . statusCode ) . toEqual ( 200 ) ;
4448 expect ( responseDataJson ) . toEqual ( {
4549 valid : true ,
@@ -69,7 +73,7 @@ describe("Test ticket purchase verification", async () => {
6973 ticketId :
7074 "9d98e1e3c2138c93dd5a284239eddfa9c3037a0862972cd0f51ee1b54257a37e" ,
7175 } ) ;
72- const responseDataJson = response . body as EventGetResponse ;
76+ const responseDataJson = response . body ;
7377 expect ( response . statusCode ) . toEqual ( 200 ) ;
7478 expect ( responseDataJson ) . toEqual ( {
7579 valid : true ,
@@ -99,7 +103,7 @@ describe("Test ticket purchase verification", async () => {
99103100104 stripePi : "pi_6T9QvUwR2IOj4CyF35DsXK7P" ,
101105 } ) ;
102- const responseDataJson = response . body as EventGetResponse ;
106+ const responseDataJson = response . body ;
103107 expect ( response . statusCode ) . toEqual ( 400 ) ;
104108 expect ( responseDataJson ) . toEqual ( {
105109 error : true ,
@@ -125,7 +129,7 @@ describe("Test ticket purchase verification", async () => {
125129 ticketId :
126130 "975b4470cf37d7cf20fd404a711513fd1d1e68259ded27f10727d1384961843d" ,
127131 } ) ;
128- const responseDataJson = response . body as EventGetResponse ;
132+ const responseDataJson = response . body ;
129133 expect ( response . statusCode ) . toEqual ( 400 ) ;
130134 expect ( responseDataJson ) . toEqual ( {
131135 error : true ,
@@ -153,7 +157,7 @@ describe("Test merch purchase verification", async () => {
153157154158 stripePi : "pi_8J4NrYdA3S7cW8Ty92FnGJ6L" ,
155159 } ) ;
156- const responseDataJson = response . body as EventGetResponse ;
160+ const responseDataJson = response . body ;
157161 expect ( response . statusCode ) . toEqual ( 200 ) ;
158162 expect ( responseDataJson ) . toEqual ( {
159163 valid : true ,
@@ -183,7 +187,7 @@ describe("Test merch purchase verification", async () => {
183187 ticketId :
184188 "975b4470cf37d7cf20fd404a711513fd1d1e68259ded27f10727d1384961843d" ,
185189 } ) ;
186- const responseDataJson = response . body as EventGetResponse ;
190+ const responseDataJson = response . body ;
187191 expect ( response . statusCode ) . toEqual ( 400 ) ;
188192 expect ( responseDataJson ) . toEqual ( {
189193 error : true ,
@@ -208,7 +212,7 @@ describe("Test merch purchase verification", async () => {
208212209213 stripePi : "pi_6T9QvUwR2IOj4CyF35DsXK7P" ,
210214 } ) ;
211- const responseDataJson = response . body as EventGetResponse ;
215+ const responseDataJson = response . body ;
212216 expect ( response . statusCode ) . toEqual ( 400 ) ;
213217 expect ( responseDataJson ) . toEqual ( {
214218 error : true ,
@@ -233,7 +237,7 @@ describe("Test merch purchase verification", async () => {
233237234238 stripePi : "pi_3Q5GewDiGOXU9RuS16txRR5D" ,
235239 } ) ;
236- const responseDataJson = response . body as EventGetResponse ;
240+ const responseDataJson = response . body ;
237241 expect ( response . statusCode ) . toEqual ( 400 ) ;
238242 expect ( responseDataJson ) . toEqual ( {
239243 error : true ,
@@ -244,6 +248,36 @@ describe("Test merch purchase verification", async () => {
244248 } ) ;
245249} ) ;
246250
251+ describe ( "Test getting all issued tickets" , async ( ) => {
252+ test ( "Happy path: get all tickets" , async ( ) => {
253+ ddbMock
254+ . on ( QueryCommand )
255+ . resolvesOnce ( { Items : dynamoTableData } )
256+ . resolvesOnce ( { } ) ;
257+
258+ const testJwt = createJwt ( ) ;
259+ await app . ready ( ) ;
260+ const response = await supertest ( app . server )
261+ . get ( "/api/v1/tickets/2024_fa_barcrawl?type=merch" )
262+ . set ( "authorization" , `Bearer ${ testJwt } ` ) ;
263+ const responseDataJson = response . body ;
264+ expect ( response . statusCode ) . toEqual ( 200 ) ;
265+ expect ( responseDataJson . tickets ) . toHaveLength ( 4 ) ;
266+ } ) ;
267+ test ( "Sad path: fail on type 'ticket'" , async ( ) => {
268+ ddbMock . on ( QueryCommand ) . rejects ( ) ;
269+
270+ const testJwt = createJwt ( ) ;
271+ await app . ready ( ) ;
272+ const response = await supertest ( app . server )
273+ . get ( "/api/v1/tickets/2024_fa_barcrawl?type=ticket" )
274+ . set ( "authorization" , `Bearer ${ testJwt } ` ) ;
275+ const responseDataJson = response . body ;
276+ expect ( response . statusCode ) . toEqual ( 400 ) ;
277+ expect ( responseDataJson . id ) . toEqual ( 110 ) ;
278+ } ) ;
279+ } ) ;
280+
247281afterAll ( async ( ) => {
248282 await app . close ( ) ;
249283 vi . useRealTimers ( ) ;
0 commit comments