Skip to content

Commit 24f08e3

Browse files
authored
Fix get purchases route to return amount paid (#413)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Ticket entries now display refunded and fulfilled status information. * Merch purchases now include total paid amount in purchase details. * **Tests** * Updated test cases to validate new ticket and merch purchase response fields. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e55abad commit 24f08e3

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

src/api/routes/tickets.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,38 @@ const purchaseSchema = z.object({
5555

5656
type PurchaseData = z.infer<typeof purchaseSchema>;
5757

58-
const ticketEntryZod = z.object({
59-
valid: z.boolean(),
60-
type: z.enum(["merch", "ticket"]),
61-
ticketId: z.string().min(1),
62-
purchaserData: purchaseSchema,
63-
totalPaid: z.optional(z.number()),
64-
});
65-
66-
const ticketInfoEntryZod = ticketEntryZod
67-
.extend({
68-
refunded: z.boolean(),
69-
fulfilled: z.boolean(),
58+
const ticketEntryZod = z
59+
.object({
60+
valid: z.boolean().meta({
61+
description:
62+
"Determines whether or not this ticket is still valid to be fulfilled.",
63+
}),
64+
type: z.enum(["merch", "ticket"]),
65+
ticketId: z.string().min(1).meta({
66+
description: "A string uniquely identifying the purchase.",
67+
}),
68+
purchaserData: purchaseSchema,
69+
totalPaid: z.optional(z.number()).meta({
70+
description:
71+
"The total amount paid by the customer, in cents, net of refunds.",
72+
}),
7073
})
7174
.meta({
7275
description: "An entry describing one merch or tickets transaction.",
76+
id: "StoreTicketEntryV1",
7377
});
7478

79+
const ticketInfoEntryZod = ticketEntryZod.extend({
80+
refunded: z.boolean().meta({
81+
description:
82+
"Determines whether or not this purchase has been fully refunded to the customer.",
83+
}),
84+
fulfilled: z.boolean().meta({
85+
description:
86+
"Determines whether or not this purchase's services/items has already been provided to the customer.",
87+
}),
88+
});
89+
7590
export type TicketInfoEntry = z.infer<typeof ticketInfoEntryZod>;
7691

7792
const baseItemMetadata = z.object({
@@ -273,6 +288,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
273288
quantity: unmarshalled.quantity,
274289
size: unmarshalled.size,
275290
},
291+
totalPaid: unmarshalled.total_paid,
276292
});
277293
}
278294
break;

tests/unit/mockMerchPurchases.testdata.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const fulfilledMerchItem2 = {
9696
size: {
9797
S: "XS",
9898
},
99+
total_paid: {
100+
N: 500,
101+
},
99102
};
100103

101104
const dynamoTableData = [

tests/unit/tickets.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,61 @@ describe("Test getting all issued tickets", async () => {
503503
const responseDataJson = response.body;
504504
expect(response.statusCode).toEqual(200);
505505
expect(responseDataJson.tickets).toHaveLength(4);
506+
expect(responseDataJson.tickets).toEqual([
507+
{
508+
fulfilled: true,
509+
purchaserData: {
510+
email: "testing0@illinois.edu",
511+
productId: "2024_fa_barcrawl",
512+
quantity: 1,
513+
size: "M",
514+
},
515+
refunded: false,
516+
ticketId: "pi_3Q5GewDiGOXU9RuS16txRR5D",
517+
type: "merch",
518+
valid: true,
519+
},
520+
{
521+
fulfilled: false,
522+
purchaserData: {
523+
email: "testing1@illinois.edu",
524+
productId: "2024_fa_barcrawl",
525+
quantity: 3,
526+
size: "L",
527+
},
528+
refunded: false,
529+
ticketId: "pi_8J4NrYdA3S7cW8Ty92FnGJ6L",
530+
type: "merch",
531+
valid: true,
532+
},
533+
{
534+
fulfilled: false,
535+
purchaserData: {
536+
email: "testing2@illinois.edu",
537+
productId: "2024_fa_barcrawl",
538+
quantity: 3,
539+
size: "L",
540+
},
541+
refunded: true,
542+
ticketId: "pi_6T9QvUwR2IOj4CyF35DsXK7P",
543+
type: "merch",
544+
valid: true,
545+
},
546+
{
547+
fulfilled: true,
548+
purchaserData: {
549+
email: "testing2@illinois.edu",
550+
productId: "2024_fa_barcrawl",
551+
quantity: 1,
552+
size: "XS",
553+
},
554+
refunded: false,
555+
ticketId: "pi_5L8SwOdN9PXu6RyV83FgQK1C",
556+
totalPaid: 500,
557+
type: "merch",
558+
valid: true,
559+
},
560+
]);
506561
});
507562
test("Sad path: fail on type 'ticket'", async () => {
508563
ddbMock.on(QueryCommand).rejects();
@@ -562,6 +617,7 @@ describe("Test getting user purchases", () => {
562617
quantity: 2,
563618
refunded: false,
564619
size: "L",
620+
total_paid: 500,
565621
}),
566622
],
567623
});
@@ -603,6 +659,7 @@ describe("Test getting user purchases", () => {
603659
},
604660
refunded: false,
605661
fulfilled: true,
662+
totalPaid: 500,
606663
});
607664
});
608665

0 commit comments

Comments
 (0)