Skip to content

Commit 0a301bd

Browse files
committed
Update err handling
1 parent f884dfe commit 0a301bd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/services/subscription/subscription-router.test.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ describe("POST /subscription/", () => {
7575
expect(response.body).toEqual(SUBSCRIPTION_1);
7676
const { data } = await SupabaseDB.SUBSCRIPTIONS.select()
7777
.eq("userId", USER_ID_1)
78-
.eq("mailingList", VALID_mailingList);
78+
.eq("mailingList", VALID_mailingList)
79+
.throwOnError();
7980
const dbEntry = data?.[0];
8081
expect(dbEntry).toMatchObject({
8182
userId: USER_ID_1,
@@ -90,7 +91,8 @@ describe("POST /subscription/", () => {
9091
expect(response.body).toEqual(SUBSCRIPTION_2);
9192
const { data } = await SupabaseDB.SUBSCRIPTIONS.select()
9293
.eq("userId", USER_ID_2)
93-
.eq("mailingList", VALID_mailingList);
94+
.eq("mailingList", VALID_mailingList)
95+
.throwOnError();
9496
const dbEntry = data?.[0];
9597
expect(dbEntry).toMatchObject({
9698
userId: USER_ID_2,
@@ -102,14 +104,15 @@ describe("POST /subscription/", () => {
102104
await SupabaseDB.SUBSCRIPTIONS.insert({
103105
userId: USER_ID_1,
104106
mailingList: VALID_mailingList,
105-
});
107+
}).throwOnError();
106108
const response = await post("/subscription/")
107109
.send(SUBSCRIPTION_1)
108110
.expect(StatusCodes.CREATED);
109111
expect(response.body).toEqual(SUBSCRIPTION_1);
110112
const { data } = await SupabaseDB.SUBSCRIPTIONS.select()
111113
.eq("userId", USER_ID_1)
112-
.eq("mailingList", VALID_mailingList);
114+
.eq("mailingList", VALID_mailingList)
115+
.throwOnError();
113116
expect(data?.length).toBe(1);
114117
});
115118

@@ -148,7 +151,8 @@ describe("POST /subscription/", () => {
148151
expect(response.body).toEqual(SUBSCRIPTION_1);
149152
const { data } = await SupabaseDB.SUBSCRIPTIONS.select()
150153
.eq("userId", USER_ID_1)
151-
.eq("mailingList", VALID_mailingList);
154+
.eq("mailingList", VALID_mailingList)
155+
.throwOnError();
152156
const dbEntry = data?.[0];
153157
expect(dbEntry?.mailingList).toEqual(VALID_mailingList);
154158
});
@@ -166,7 +170,7 @@ describe("GET /subscription/", () => {
166170
await SupabaseDB.SUBSCRIPTIONS.insert([
167171
{ userId: USER_ID_1, mailingList: VALID_mailingList },
168172
{ userId: USER_ID_2, mailingList: VALID_mailingList },
169-
]);
173+
]).throwOnError();
170174
const response = await getAsAdmin("/subscription/").expect(
171175
StatusCodes.OK
172176
);
@@ -191,7 +195,7 @@ describe("POST /subscription/send-email", () => {
191195
await SupabaseDB.SUBSCRIPTIONS.insert([
192196
{ userId: USER_ID_1, mailingList: mailingList },
193197
{ userId: USER_ID_2, mailingList: mailingList },
194-
]);
198+
]).throwOnError();
195199

196200
const emailPayload = {
197201
mailingList: mailingList,
@@ -260,7 +264,7 @@ describe("GET /subscription/:mailingList", () => {
260264
await SupabaseDB.SUBSCRIPTIONS.insert([
261265
{ userId: USER_ID_1, mailingList: VALID_mailingList },
262266
{ userId: USER_ID_2, mailingList: VALID_mailingList },
263-
]);
267+
]).throwOnError();
264268

265269
const response = await getAsAdmin(
266270
`/subscription/${VALID_mailingList}`
@@ -296,7 +300,7 @@ describe("GET /subscription/user/:userId", () => {
296300
it("should return a user's subscriptions", async () => {
297301
await SupabaseDB.SUBSCRIPTIONS.insert([
298302
{ userId: USER_ID_1, mailingList: VALID_mailingList },
299-
]);
303+
]).throwOnError();
300304

301305
const response = await getAsAdmin(
302306
`/subscription/user/${USER_ID_1}`
@@ -319,7 +323,7 @@ describe("DELETE /subscription/", () => {
319323
it("should unsubscribe a user from a mailing list", async () => {
320324
await SupabaseDB.SUBSCRIPTIONS.insert([
321325
{ userId: USER_ID_1, mailingList: VALID_mailingList },
322-
]);
326+
]).throwOnError();
323327

324328
const response = await delAsAdmin("/subscription/")
325329
.send({
@@ -331,16 +335,17 @@ describe("DELETE /subscription/", () => {
331335
expect(response.body).toEqual({ status: "success" });
332336

333337
// Verify the subscription was removed
334-
const { data: remainingSubs } =
335-
await SupabaseDB.SUBSCRIPTIONS.select().eq("userId", USER_ID_1);
338+
const { data: remainingSubs } = await SupabaseDB.SUBSCRIPTIONS.select()
339+
.eq("userId", USER_ID_1)
340+
.throwOnError();
336341
expect(remainingSubs?.length).toBe(0);
337342
});
338343

339344
it("should delete the subscription record", async () => {
340345
await SupabaseDB.SUBSCRIPTIONS.insert({
341346
userId: USER_ID_1,
342347
mailingList: VALID_mailingList,
343-
});
348+
}).throwOnError();
344349

345350
const response = await delAsAdmin("/subscription/")
346351
.send({
@@ -355,7 +360,8 @@ describe("DELETE /subscription/", () => {
355360
const { data } = await SupabaseDB.SUBSCRIPTIONS.select()
356361
.eq("userId", USER_ID_1)
357362
.eq("mailingList", VALID_mailingList)
358-
.maybeSingle();
363+
.maybeSingle()
364+
.throwOnError();
359365
expect(data).toBeNull();
360366
});
361367

0 commit comments

Comments
 (0)