Skip to content

Commit dd4fa56

Browse files
committed
resolved comments
1 parent 22077bf commit dd4fa56

File tree

5 files changed

+34
-52
lines changed

5 files changed

+34
-52
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ build/Release
4242
node_modules/
4343
jspm_packages/
4444

45-
# Snowpack d:
46-
ependency directory (https://snowpack.dev/)
45+
# Snowpack dependency directory (https://snowpack.dev/)
4746
web_modules/
4847

4948
# TypeScript cache

src/database/decision-db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { prop } from "@typegoose/typegoose";
22

3-
enum DecisionStatus {
3+
export enum DecisionStatus {
44
TBD = "TBD",
55
ACCEPTED = "ACCEPTED",
66
REJECTED = "REJECTED",
77
WAITLISTED = "WAITLISTED",
88
}
99

10-
enum DecisionResponse {
10+
export enum DecisionResponse {
1111
PENDING = "PENDING",
1212
ACCEPTED = "ACCEPTED",
1313
DECLINED = "DECLINED",
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1+
import { DecisionStatus } from "database/decision-db.js";
2+
13
export interface ApplicantDecisionFormat {
24
_id?: string;
35
userId: string;
46
name: string;
57
status: DecisionStatus;
68
}
7-
8-
export enum DecisionStatus {
9-
TBD = "TBD",
10-
ACCEPTED = "ACCEPTED",
11-
REJECTED = "REJECTED",
12-
WAITLISTED = "WAITLISTED",
13-
}
14-
export enum DecisionResponse {
15-
PENDING = "PENDING",
16-
ACCEPTED = "ACCEPTED",
17-
DECLINED = "DECLINED",
18-
}
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { beforeEach, describe, expect, it } from "@jest/globals";
22
import Models from "../../database/models.js";
3-
import { DecisionStatus, DecisionResponse } from "./admission-formats.js";
4-
import { getAsAttendee, getAsStaff, getAsUser, putAsAttendee, putAsStaff, putAsUser, TESTER } from "../../testTools.js";
3+
import { DecisionStatus, DecisionResponse } from "../../database/decision-db.js";
4+
import { getAsAttendee, getAsStaff, getAsUser, putAsStaff, putAsUser, TESTER } from "../../testTools.js";
55
import { DecisionInfo } from "../../database/decision-db.js";
66
import { StatusCode } from "status-code-enum";
7+
import { ApplicantDecisionFormat } from "./admission-formats.js";
78

89
const TESTER_USER = {
910
userId: TESTER.id,
@@ -21,6 +22,19 @@ const OTHER_USER = {
2122
reviewer: "other-reviewer",
2223
} satisfies DecisionInfo;
2324

25+
const updateData = [
26+
{
27+
userId: TESTER.id,
28+
name: TESTER.name,
29+
status: DecisionStatus.WAITLISTED,
30+
},
31+
{
32+
userId: "other-user",
33+
name: "other-name",
34+
status: DecisionStatus.ACCEPTED,
35+
},
36+
] satisfies ApplicantDecisionFormat[];
37+
2438
beforeEach(async () => {
2539
Models.initialize();
2640
await Models.DecisionInfo.create(TESTER_USER);
@@ -30,11 +44,11 @@ beforeEach(async () => {
3044
describe("GET /admission", () => {
3145
it("gives forbidden error for user without elevated perms", async () => {
3246
const responseUser = await getAsUser("/admission/").expect(StatusCode.ClientErrorForbidden);
33-
expect(JSON.parse(responseUser.text)).toHaveProperty("error", "InvalidToken");
47+
expect(JSON.parse(responseUser.text)).toHaveProperty("error", "Forbidden");
3448
});
3549
it("gives forbidden error for user without elevated perms - attendee", async () => {
3650
const responseAttendee = await getAsAttendee("/admission/").expect(StatusCode.ClientErrorForbidden);
37-
expect(JSON.parse(responseAttendee.text)).toHaveProperty("error", "InvalidToken");
51+
expect(JSON.parse(responseAttendee.text)).toHaveProperty("error", "Forbidden");
3852
});
3953
it("should return a list of applicants without email sent", async () => {
4054
const response = await getAsStaff("/admission/").expect(StatusCode.SuccessOK);
@@ -43,25 +57,9 @@ describe("GET /admission", () => {
4357
});
4458

4559
describe("PUT /admission", () => {
46-
const updateData = [
47-
{
48-
userId: TESTER.id,
49-
name: TESTER.name,
50-
status: DecisionStatus.WAITLISTED,
51-
},
52-
{
53-
userId: "other-user",
54-
name: "other-name",
55-
status: DecisionStatus.ACCEPTED,
56-
},
57-
];
58-
it("gives forbidden error for user without elevated perms (As User)", async () => {
59-
const responseAttendee = await putAsAttendee("/admission/").send(updateData).expect(StatusCode.ClientErrorForbidden);
60-
expect(JSON.parse(responseAttendee.text)).toHaveProperty("error", "InvalidToken");
61-
});
6260
it("gives forbidden error for user without elevated perms (As Attendee)", async () => {
6361
const responseUser = await putAsUser("/admission/").send(updateData).expect(StatusCode.ClientErrorForbidden);
64-
expect(JSON.parse(responseUser.text)).toHaveProperty("error", "InvalidToken");
62+
expect(JSON.parse(responseUser.text)).toHaveProperty("error", "Forbidden");
6563
});
6664
it("should update application status of applicants", async () => {
6765
const response = await putAsStaff("/admission/").send(updateData).expect(StatusCode.SuccessOK);
@@ -70,10 +68,10 @@ describe("PUT /admission", () => {
7068
return Models.DecisionInfo.findOne({ userId: entry.userId });
7169
});
7270
const retrievedEntries = await Promise.all(ops);
73-
updateData.forEach((entry) => {
74-
expect(retrievedEntries).toMatchObject(
75-
expect.arrayContaining([expect.objectContaining({ status: entry.status, userId: entry.userId })]),
76-
);
77-
});
71+
expect(retrievedEntries).toMatchObject(
72+
expect.arrayContaining(
73+
updateData.map((item) => expect.objectContaining({ status: item.status, userId: item.userId })),
74+
),
75+
);
7876
});
7977
});

src/services/admission/admission-router.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,35 @@ const admissionRouter: Router = Router();
2020
* HTTP/1.1 200 OK
2121
* [
2222
* {
23-
* "_id": "652c2f0f923bd80603c992f9",
2423
* "userId": "user1",
2524
* "status": "ACCEPTED",
2625
* "response": "ACCEPTED",
2726
* "reviewer": "reviewer1",
2827
* "emailSent": false
2928
* },
3029
* {
31-
* "_id": "652c2f4a4e5cf39082bbaad8",
3230
* "userId": "user3",
3331
* "status": "WAITLISTED",
3432
* "response": "PENDING",
3533
* "reviewer": "reviewer1",
3634
* "emailSent": false
3735
* },
3836
* {
39-
* "_id": "652c2f65867cc5b6728ee48c",
4037
* "userId": "user4",
4138
* "status": "WAITLISTED",
4239
* "response": "PENDING",
4340
* "reviewer": "reviewer1",
4441
* "emailSent": false
4542
* }
46-
* ]
43+
* ]
4744
* @apiUser strongVerifyErrors
4845
* @apiError (500: Internal Server Error) {String} InternalError occurred on the server.
4946
* @apiError (403: Forbidden) {String} Forbidden API accessed by user without valid perms.
5047
* */
5148
admissionRouter.get("/", strongJwtVerification, async (_: Request, res: Response) => {
5249
const token: JwtPayload = res.locals.payload as JwtPayload;
5350
if (!hasElevatedPerms(token)) {
54-
return res.status(StatusCode.ClientErrorForbidden).send({ error: "InvalidToken" });
51+
return res.status(StatusCode.ClientErrorForbidden).send({ error: "Forbidden" });
5552
}
5653
try {
5754
const filteredEntries: DecisionInfo[] = await Models.DecisionInfo.find({ emailSent: false });
@@ -72,8 +69,7 @@ admissionRouter.get("/", strongJwtVerification, async (_: Request, res: Response
7269
*
7370
* @apiParamExample Example Request (Staff):
7471
* HTTP/1.1 PUT /admission/
75-
* {
76-
* "entries": [
72+
* [
7773
* {
7874
* "userId": "user1",
7975
* "name": "Jason",
@@ -89,8 +85,7 @@ admissionRouter.get("/", strongJwtVerification, async (_: Request, res: Response
8985
* "name": "John",
9086
* "status": "WAITLISTED"
9187
* }
92-
* ]
93-
* }
88+
* ]
9489
*
9590
* @apiSuccess (200: Success) {String} StatusSuccess
9691
*
@@ -101,7 +96,7 @@ admissionRouter.get("/", strongJwtVerification, async (_: Request, res: Response
10196
admissionRouter.put("/", strongJwtVerification, async (req: Request, res: Response) => {
10297
const token: JwtPayload = res.locals.payload as JwtPayload;
10398
if (!hasElevatedPerms(token)) {
104-
return res.status(StatusCode.ClientErrorForbidden).send({ error: "InvalidToken" });
99+
return res.status(StatusCode.ClientErrorForbidden).send({ error: "Forbidden" });
105100
}
106101
const updateEntries: ApplicantDecisionFormat[] = req.body as ApplicantDecisionFormat[];
107102
const ops = updateEntries.map((entry) => {

0 commit comments

Comments
 (0)