Skip to content

Commit d1188d8

Browse files
Clean up & add mentor specification
1 parent edc9688 commit d1188d8

File tree

7 files changed

+230
-312
lines changed

7 files changed

+230
-312
lines changed

src/common/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ const Config = {
135135
DEFAULT_COIN_VALUE: 0,
136136
DEFAULT_AVATAR: Avatar.GOBLIN,
137137

138+
/* Rewards */
139+
MENTOR_OFFICE_HOURS_POINT_REWARD: 50,
140+
138141
/* Limits */
139142
LEADERBOARD_QUERY_LIMIT: 25,
140143
MAX_RESUME_SIZE_BYTES: 2 * 1024 * 1024,

src/database/mentor-db.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/database/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getModelForClass } from "@typegoose/typegoose";
44
import { AuthInfo } from "../services/auth/auth-schemas";
55
import { AttendeeProfile } from "../services/profile/profile-schemas";
66
import { AdmissionDecision } from "../services/admission/admission-schemas";
7-
import { MentorOfficeHours } from "./mentor-db";
7+
import { MentorOfficeHours } from "../services/mentor/mentor-schemas";
88
import { Event, EventAttendance, EventFollowers } from "../services/event/event-schemas";
99
import { NewsletterSubscription } from "../services/newsletter/newsletter-schemas";
1010
import { RegistrationApplication } from "../services/registration/registration-schemas";

src/services/mentor/mentor-formats.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

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

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
11
import { describe, expect, it } from "@jest/globals";
22
import Models from "../../database/models";
33
import { StatusCode } from "status-code-enum";
4-
import { OfficeHoursFormat } from "./mentor-formats";
5-
import { postAsAdmin, postAsAttendee, getAsAttendee, getAsAdmin, delAsAttendee, delAsAdmin } from "../../common/testTools";
4+
import { postAsAdmin, postAsAttendee, getAsAttendee, delAsAttendee, delAsAdmin, getAsStaff } from "../../common/testTools";
5+
import { MentorOfficeHours } from "./mentor-schemas";
66

77
const TESTER_OFFICE_HOURS_1 = {
88
mentorName: "asdf",
99
mentorId: "io213123012",
1010
attendees: [],
11-
} satisfies OfficeHoursFormat;
11+
} satisfies MentorOfficeHours;
1212

1313
const TESTER_OFFICE_HOURS_2 = {
1414
mentorName: "3211",
1515
mentorId: "2k2kk3mmn3",
1616
attendees: [],
17-
} satisfies OfficeHoursFormat;
17+
} satisfies MentorOfficeHours;
1818

1919
describe("POST /mentor", () => {
2020
it("gives an invalid perms error for a non-staff user", async () => {
2121
const response = await postAsAttendee(`/mentor/`)
2222
.send({ mentorName: "John Sanson" })
2323
.expect(StatusCode.ClientErrorForbidden);
2424

25-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidPermission");
26-
});
27-
28-
it("gives a bad request error for missing fields", async () => {
29-
const response = await postAsAttendee(`/mentor/`).send({}).expect(StatusCode.ClientErrorBadRequest);
30-
31-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidRequest");
25+
expect(JSON.parse(response.text)).toHaveProperty("error", "Forbidden");
3226
});
3327

3428
it("works for staff", async () => {
3529
const response = await postAsAdmin(`/mentor/`).send({ mentorName: "John Sanson" }).expect(StatusCode.SuccessCreated);
3630

3731
expect(JSON.parse(response.text)).toHaveProperty("mentorName", "John Sanson");
38-
//mentorId will be randomly generated, and attendees will be empty after initialization
3932
});
4033
});
4134

@@ -45,46 +38,39 @@ describe("GET /mentor", () => {
4538
.send({ mentorName: "John Sanson" })
4639
.expect(StatusCode.ClientErrorForbidden);
4740

48-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidPermission");
41+
expect(JSON.parse(response.text)).toHaveProperty("error", "Forbidden");
4942
});
5043

5144
it("works for staff", async () => {
5245
await Models.MentorOfficeHours.create(TESTER_OFFICE_HOURS_1);
5346
await Models.MentorOfficeHours.create(TESTER_OFFICE_HOURS_2);
5447

55-
const response = await getAsAdmin(`/mentor/`).expect(StatusCode.SuccessOK);
56-
57-
console.log(response);
58-
48+
const response = await getAsStaff(`/mentor/`).expect(StatusCode.SuccessOK);
5949
expect(JSON.parse(response.text)).toMatchObject([TESTER_OFFICE_HOURS_1, TESTER_OFFICE_HOURS_2]);
6050
});
6151
});
6252

63-
describe("DELETE /mentor", () => {
53+
describe("DELETE /mentor/id/", () => {
6454
it("gives an invalid perms error for a non-staff user", async () => {
65-
const response = await delAsAttendee(`/mentor/`).send({ mentorId: "12312312" }).expect(StatusCode.ClientErrorForbidden);
66-
67-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidPermission");
68-
});
69-
70-
it("gives a bad request error for missing fields", async () => {
71-
const response = await delAsAdmin(`/mentor/`).send({}).expect(StatusCode.ClientErrorBadRequest);
55+
const response = await delAsAttendee(`/mentor/${TESTER_OFFICE_HOURS_1.mentorId}/`).expect(
56+
StatusCode.ClientErrorForbidden,
57+
);
7258

73-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidRequest");
59+
expect(JSON.parse(response.text)).toHaveProperty("error", "Forbidden");
7460
});
7561

7662
it("gives a not found error for a nonexistent mentor", async () => {
77-
const response = await delAsAdmin(`/mentor/`).send({ mentorId: "dne" }).expect(StatusCode.ClientErrorBadRequest);
63+
const response = await delAsAdmin(`/mentor/${TESTER_OFFICE_HOURS_1.mentorId}/`).expect(StatusCode.ClientErrorNotFound);
7864

79-
expect(JSON.parse(response.text)).toHaveProperty("error", "MentorNotFound");
65+
expect(JSON.parse(response.text)).toHaveProperty("error", "NotFound");
8066
});
8167

8268
it("works for staff", async () => {
8369
await Models.MentorOfficeHours.create(TESTER_OFFICE_HOURS_1);
8470

85-
await delAsAdmin(`/mentor/`).send({ mentorId: "io213123012" }).expect(StatusCode.SuccessOK);
71+
await delAsAdmin(`/mentor/${TESTER_OFFICE_HOURS_1.mentorId}/`).expect(StatusCode.SuccessOK);
8672

87-
const officeHours: OfficeHoursFormat | null = await Models.MentorOfficeHours.findOne({ mentorId: "io213123012" });
73+
const officeHours = await Models.MentorOfficeHours.findOne({ mentorId: TESTER_OFFICE_HOURS_1.mentorId });
8874
expect(officeHours).toBeNull();
8975
});
9076
});
@@ -94,33 +80,29 @@ describe("POST /mentor/attendance", () => {
9480
await Models.MentorOfficeHours.create(TESTER_OFFICE_HOURS_1);
9581

9682
const response = await postAsAdmin(`/mentor/attendance`)
97-
.send({ mentorId: "io213123012" })
83+
.send({ mentorId: TESTER_OFFICE_HOURS_1.mentorId })
9884
.expect(StatusCode.ClientErrorForbidden);
9985

100-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidPermission");
101-
});
102-
103-
it("gives a bad request error for missing fields", async () => {
104-
const response = await postAsAttendee(`/mentor/attendance`).send({}).expect(StatusCode.ClientErrorBadRequest);
105-
106-
expect(JSON.parse(response.text)).toHaveProperty("error", "InvalidRequest");
86+
expect(JSON.parse(response.text)).toHaveProperty("error", "Forbidden");
10787
});
10888

10989
it("gives a not found error for a nonexistent mentor", async () => {
11090
const response = await postAsAttendee(`/mentor/attendance`)
11191
.send({ mentorId: "dne" })
112-
.expect(StatusCode.ClientErrorBadRequest);
92+
.expect(StatusCode.ClientErrorNotFound);
11393

114-
expect(JSON.parse(response.text)).toHaveProperty("error", "MentorNotFound");
94+
expect(JSON.parse(response.text)).toHaveProperty("error", "NotFound");
11595
});
11696

11797
it("gives an already checked in error if an attendee tries to check in twice", async () => {
11898
await Models.MentorOfficeHours.create(TESTER_OFFICE_HOURS_1);
11999

120-
await postAsAttendee(`/mentor/attendance`).send({ mentorId: "io213123012" }).expect(StatusCode.SuccessOK);
100+
await postAsAttendee(`/mentor/attendance`)
101+
.send({ mentorId: TESTER_OFFICE_HOURS_1.mentorId })
102+
.expect(StatusCode.SuccessOK);
121103

122104
const response = await postAsAttendee(`/mentor/attendance`)
123-
.send({ mentorId: "io213123012" })
105+
.send({ mentorId: TESTER_OFFICE_HOURS_1.mentorId })
124106
.expect(StatusCode.ClientErrorBadRequest);
125107

126108
expect(JSON.parse(response.text)).toHaveProperty("error", "AlreadyCheckedIn");
@@ -129,9 +111,11 @@ describe("POST /mentor/attendance", () => {
129111
it("works for attendee", async () => {
130112
await Models.MentorOfficeHours.create(TESTER_OFFICE_HOURS_1);
131113

132-
await postAsAttendee(`/mentor/attendance/`).send({ mentorId: "io213123012" }).expect(StatusCode.SuccessOK);
114+
await postAsAttendee(`/mentor/attendance/`)
115+
.send({ mentorId: TESTER_OFFICE_HOURS_1.mentorId })
116+
.expect(StatusCode.SuccessOK);
133117

134-
const officeHours: OfficeHoursFormat | null = await Models.MentorOfficeHours.findOne({ mentorId: "io213123012" });
118+
const officeHours = await Models.MentorOfficeHours.findOne({ mentorId: TESTER_OFFICE_HOURS_1.mentorId });
135119

136120
expect(officeHours?.attendees).toContain("bob-the-tester101010101011");
137121
});

0 commit comments

Comments
 (0)