Skip to content

Commit aa3cc6c

Browse files
Edit create_course test to reflect current functionality
1 parent 82e9bc0 commit aa3cc6c

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

__tests__/jest/slashCommands/slash_create_course.test.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ findCourseFromDb
2020
createCourseToDatabase.mockImplementation(() => {return { name: "nickname", id: Math.floor(Math.random() * 10) + 5 }; });
2121

2222
const { defaultTeacherInteraction, defaultStudentInteraction } = require("../../mocks/mockInteraction");
23+
24+
beforeEach(() => {
2325
defaultTeacherInteraction.options = {
2426
getString: jest.fn((name) => {
2527
const names = {
@@ -40,7 +42,7 @@ defaultStudentInteraction.options = {
4042
return names[name];
4143
}),
4244
};
43-
45+
});
4446
afterEach(() => {
4547
jest.clearAllMocks();
4648
});
@@ -65,19 +67,39 @@ describe("slash create command", () => {
6567
});
6668

6769
test("course code must be unique when nickname not given", async () => {
68-
const client = defaultStudentInteraction.client;
70+
defaultTeacherInteraction.options = {
71+
getString: jest.fn((name) => {
72+
const names = {
73+
coursecode: "TKT-100",
74+
full_name: "Long course name",
75+
nick_name: undefined,
76+
};
77+
return names[name];
78+
}),
79+
};
80+
const client = defaultTeacherInteraction.client;
6981
const response = "Course code must be unique.";
70-
await execute(defaultStudentInteraction, client, models);
82+
await execute(defaultTeacherInteraction, client, models);
7183
expect(findCourseFromDbWithFullName).toHaveBeenCalledTimes(1);
7284
expect(sendErrorEphemeral).toHaveBeenCalledTimes(1);
73-
expect(sendErrorEphemeral).toHaveBeenCalledWith(defaultStudentInteraction, response);
85+
expect(sendErrorEphemeral).toHaveBeenCalledWith(defaultTeacherInteraction, response);
7486
});
7587

7688
test("create course name without nick", async () => {
89+
defaultTeacherInteraction.options = {
90+
getString: jest.fn((name) => {
91+
const names = {
92+
coursecode: "TKT-100",
93+
full_name: "Long course name",
94+
nick_name: undefined,
95+
};
96+
return names[name];
97+
}),
98+
};
7799
const courseCode = "TKT-100";
78100
const fullName = "Long course name";
79-
const client = defaultStudentInteraction.client;
80-
await execute(defaultStudentInteraction, client, models);
101+
const client = defaultTeacherInteraction.client;
102+
await execute(defaultTeacherInteraction, client, models);
81103
expect(createCourseToDatabase).toHaveBeenCalledTimes(1);
82104
expect(createCourseToDatabase).toHaveBeenCalledWith(courseCode, fullName, courseCode.toLowerCase(), models.Course);
83105
});

0 commit comments

Comments
 (0)