Skip to content

Commit e0a4fa5

Browse files
committed
add unit tests
1 parent 0c48705 commit e0a4fa5

File tree

5 files changed

+467
-7
lines changed

5 files changed

+467
-7
lines changed

src/routes/tickets.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import { zodToJsonSchema } from "zod-to-json-schema";
1818
const postMerchSchema = z.object({
1919
type: z.literal("merch"),
2020
email: z.string().email(),
21-
stripe_pi: z.string().min(1),
21+
stripePi: z.string().min(1),
2222
});
2323

2424
const postTicketSchema = z.object({
2525
type: z.literal("ticket"),
26-
ticket_id: z.string().min(1),
26+
ticketId: z.string().min(1),
2727
});
2828

2929
const purchaseSchema = z.object({
@@ -74,7 +74,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
7474
}
7575
switch (request.body.type) {
7676
case "merch":
77-
ticketId = request.body.stripe_pi;
77+
ticketId = request.body.stripePi;
7878
command = new UpdateItemCommand({
7979
TableName: genericConfig.MerchStorePurchasesTableName,
8080
Key: {
@@ -93,7 +93,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
9393
});
9494
break;
9595
case "ticket":
96-
ticketId = request.body.ticket_id;
96+
ticketId = request.body.ticketId;
9797
command = new UpdateItemCommand({
9898
TableName: genericConfig.TicketPurchasesTableName,
9999
Key: {
@@ -172,7 +172,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
172172
};
173173
switch (request.body.type) {
174174
case "merch":
175-
ticketId = request.body.stripe_pi;
175+
ticketId = request.body.stripePi;
176176
command = new UpdateItemCommand({
177177
TableName: genericConfig.MerchStorePurchasesTableName,
178178
Key: {
@@ -187,7 +187,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
187187
});
188188
break;
189189
case "ticket":
190-
ticketId = request.body.ticket_id;
190+
ticketId = request.body.ticketId;
191191
command = new UpdateItemCommand({
192192
TableName: genericConfig.TicketPurchasesTableName,
193193
Key: {

tests/unit/auth.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { mockClient } from "aws-sdk-client-mock";
77
import init from "../../src/index.js";
88
import { secretJson, secretObject, jwtPayload } from "./secret.testdata.js";
99
import jwt from "jsonwebtoken";
10+
import { allAppRoles } from "../../src/roles.js";
1011

1112
const ddbMock = mockClient(SecretsManagerClient);
1213

@@ -48,6 +49,6 @@ test("Test happy path", async () => {
4849
const jsonBody = await response.json();
4950
expect(jsonBody).toEqual({
5051
username: "[email protected]",
51-
roles: ["manage:events"],
52+
roles: allAppRoles,
5253
});
5354
});
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { unmarshall } from "@aws-sdk/util-dynamodb";
2+
const fulfilledMerchItem1 = {
3+
stripe_pi: {
4+
S: "pi_3Q5GewDiGOXU9RuS16txRR5D",
5+
},
6+
email: {
7+
8+
},
9+
fulfilled: {
10+
BOOL: true,
11+
},
12+
item_id: {
13+
S: "sigpwny_fallctf_2022_shirt",
14+
},
15+
quantity: {
16+
N: "1",
17+
},
18+
refunded: {
19+
BOOL: false,
20+
},
21+
scannerEmail: {
22+
23+
},
24+
size: {
25+
S: "M",
26+
},
27+
};
28+
29+
const unfulfilledMerchItem1 = {
30+
stripe_pi: {
31+
S: "pi_8J4NrYdA3S7cW8Ty92FnGJ6L",
32+
},
33+
email: {
34+
35+
},
36+
fulfilled: {
37+
BOOL: false,
38+
},
39+
item_id: {
40+
S: "2024_fa_barcrawl",
41+
},
42+
quantity: {
43+
N: "3",
44+
},
45+
refunded: {
46+
BOOL: false,
47+
},
48+
size: {
49+
S: "L",
50+
},
51+
};
52+
53+
const refundedMerchItem = {
54+
stripe_pi: {
55+
S: "pi_6T9QvUwR2IOj4CyF35DsXK7P",
56+
},
57+
email: {
58+
59+
},
60+
fulfilled: {
61+
BOOL: false,
62+
},
63+
item_id: {
64+
S: "2024_fa_barcrawl",
65+
},
66+
quantity: {
67+
N: "3",
68+
},
69+
refunded: {
70+
BOOL: true,
71+
},
72+
size: {
73+
S: "L",
74+
},
75+
};
76+
77+
const fulfilledMerchItem2 = {
78+
stripe_pi: {
79+
S: "pi_5L8SwOdN9PXu6RyV83FgQK1C",
80+
},
81+
email: {
82+
83+
},
84+
fulfilled: {
85+
BOOL: true,
86+
},
87+
item_id: {
88+
S: "2024_fa_barcrawl",
89+
},
90+
quantity: {
91+
N: "1",
92+
},
93+
refunded: {
94+
BOOL: false,
95+
},
96+
size: {
97+
S: "XS",
98+
},
99+
};
100+
101+
const dynamoTableData = [
102+
fulfilledMerchItem1,
103+
unfulfilledMerchItem1,
104+
refundedMerchItem,
105+
fulfilledMerchItem2,
106+
];
107+
108+
const dynamoTableDataUnmarshalled = dynamoTableData.map((x: any) => {
109+
const temp = unmarshall(x);
110+
delete temp.createdBy;
111+
return temp;
112+
});
113+
114+
export {
115+
dynamoTableData,
116+
fulfilledMerchItem1,
117+
unfulfilledMerchItem1,
118+
refundedMerchItem,
119+
fulfilledMerchItem2,
120+
dynamoTableDataUnmarshalled,
121+
};

tests/unit/mockTickets.testdata.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { unmarshall } from "@aws-sdk/util-dynamodb";
2+
const fulfilledTicket1 = {
3+
ticket_id: {
4+
S: "975b4470cf37d7cf20fd404a711513fd1d1e68259ded27f10727d1384961843d",
5+
},
6+
event_id: {
7+
S: "fa23_barcrawl",
8+
},
9+
payment_method: {
10+
S: "stripe_autocreate",
11+
},
12+
purchase_time: {
13+
N: "1702347952",
14+
},
15+
scannerEmail: {
16+
17+
},
18+
ticketholder_netid: {
19+
S: "dsingh14",
20+
},
21+
used: {
22+
BOOL: true,
23+
},
24+
};
25+
const unfulfilledTicket1 = {
26+
ticket_id: {
27+
S: "9d98e1e3c2138c93dd5a284239eddfa9c3037a0862972cd0f51ee1b54257a37e",
28+
},
29+
event_id: {
30+
S: "fa23_barcrawl",
31+
},
32+
payment_method: {
33+
S: "stripe_autocreate",
34+
},
35+
purchase_time: {
36+
N: "1702347952",
37+
},
38+
ticketholder_netid: {
39+
S: "dsingh14",
40+
},
41+
used: {
42+
BOOL: false,
43+
},
44+
};
45+
const unfulfilledTicket1WithEmail = {
46+
ticket_id: {
47+
S: "444ce3c3befe4a1f6b0ba940b8ff7dd91dda74e1a37ca8f5f16c8422a829d7f7",
48+
},
49+
event_id: {
50+
S: "fa22_barcrawl",
51+
},
52+
payment_method: {
53+
S: "stripe_autocreate",
54+
},
55+
purchase_time: {
56+
N: "1704347923",
57+
},
58+
ticketholder_netid: {
59+
60+
},
61+
used: {
62+
BOOL: false,
63+
},
64+
};
65+
66+
const dynamoTableData = [
67+
fulfilledTicket1,
68+
unfulfilledTicket1,
69+
unfulfilledTicket1WithEmail,
70+
];
71+
72+
const dynamoTableDataUnmarshalled = dynamoTableData.map((x: any) => {
73+
const temp = unmarshall(x);
74+
delete temp.createdBy;
75+
return temp;
76+
});
77+
78+
export {
79+
dynamoTableData,
80+
fulfilledTicket1,
81+
unfulfilledTicket1,
82+
unfulfilledTicket1WithEmail,
83+
dynamoTableDataUnmarshalled,
84+
};

0 commit comments

Comments
 (0)