Skip to content

Commit 54ede41

Browse files
committed
Fix tests
1 parent e1bc35b commit 54ede41

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/app/api/invites/route.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ test("check existing user", async () => {
9393
type: UserType.ADMIN,
9494
passwordHash: "abc",
9595
partnerDetails: null,
96+
enabled: true,
9697
});
9798

9899
const formData = new FormData();
@@ -131,7 +132,7 @@ test("test email html", async () => {
131132
expect(sendEmailMock).toHaveBeenCalledWith(
132133
expect.any(String),
133134
expect.any(String),
134-
expect.stringMatching(new RegExp(`register\\?token=${mockToken}`)),
135+
expect.stringMatching(new RegExp(`register\\?token=${mockToken}`))
135136
);
136137
},
137138
});
@@ -160,7 +161,7 @@ test("UserInvite expires in one day", async () => {
160161

161162
expect(expirationDate.getTime() - currentDate.getTime()).toBeCloseTo(
162163
oneDayInMilliseconds,
163-
-2,
164+
-2
164165
);
165166
},
166167
});
@@ -225,7 +226,7 @@ test("error when invalid partner details for partner invite", async () => {
225226
"partnerDetails",
226227
JSON.stringify({
227228
siteName: 8,
228-
}),
229+
})
229230
);
230231
const res = await fetch({ method: "POST", body: formData });
231232
expect(res.status).toBe(400);

src/app/api/items/route.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as appHandler from "./route";
66
import { expect, test } from "@jest/globals";
77
import { dbMock } from "@/test/dbMock";
88
import { invalidateSession, validateSession } from "@/test/util/authMockUtils";
9-
import { UserType } from "@prisma/client";
9+
import { Prisma, UserType } from "@prisma/client";
1010

1111
const item = {
1212
title: "Some item",
@@ -17,8 +17,10 @@ const item = {
1717
unitType: "bunches",
1818
datePosted: new Date(1000),
1919
lotNumber: 2,
20+
palletNumber: 3,
21+
boxNumber: 4,
2022
donorName: "John Doe",
21-
unitPrice: 7,
23+
unitPrice: new Prisma.Decimal(1234),
2224
maxRequestLimit: "5",
2325
};
2426
const invalidItem = {

src/app/api/items/route.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { auth } from "@/auth";
77
import { db } from "@/db";
88
import { NextResponse, NextRequest } from "next/server";
9-
import { UserType } from "@prisma/client";
9+
import { Prisma, UserType } from "@prisma/client";
1010
import { z } from "zod";
1111
import { zfd } from "zod-form-data";
1212

@@ -24,9 +24,12 @@ const ItemFormSchema = zfd.formData({
2424
unitType: zfd.text(),
2525
datePosted: z.coerce.date(),
2626
lotNumber: zfd.numeric(z.number().int().min(0)),
27+
palletNumber: zfd.numeric(z.number().int().min(0)),
28+
boxNumber: zfd.numeric(z.number().int().min(0)),
2729
donorName: zfd.text(),
2830
unitPrice: zfd.numeric(z.number().min(0)),
2931
maxRequestLimit: zfd.text(),
32+
visible: zfd.checkbox(),
3033
});
3134

3235
interface ItemResponse {
@@ -37,10 +40,13 @@ interface ItemResponse {
3740
unitSize: number;
3841
datePosted: Date;
3942
lotNumber: number;
43+
palletNumber: number;
44+
boxNumber: number;
4045
donorName: string;
41-
unitPrice: number;
46+
unitPrice: Prisma.Decimal;
4247
unitType: string;
4348
maxRequestLimit: string;
49+
visible: boolean;
4450
}
4551

4652
/**

src/app/api/partnerDetails/[userId]/route.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ test("returns 200 and correct details on success when partner + id matches", asy
259259
email: "test_email@test.com",
260260
name: "tester",
261261
passwordHash: "test_hash",
262+
enabled: true,
262263
});
263264

264265
const res = await fetch({ method: "GET", body: null });
@@ -286,6 +287,7 @@ test("returns 200 and correct details on success when staff matches", async () =
286287
email: "test_email@test.com",
287288
name: "tester",
288289
passwordHash: "test_hash",
290+
enabled: true,
289291
});
290292

291293
const res = await fetch({ method: "GET", body: null });
@@ -384,6 +386,7 @@ describe("POST /api/partnerDetails/[userId]", () => {
384386
passwordHash: "test_hash",
385387
type: UserType.SUPER_ADMIN,
386388
partnerDetails: updatedPartnerDetails,
389+
enabled: true,
387390
};
388391

389392
dbMock.user.update.mockResolvedValueOnce(updatedUser);

0 commit comments

Comments
 (0)