Skip to content

Commit

Permalink
test(problem-generators): Fix tests for problem controller
Browse files Browse the repository at this point in the history
- Updated the `generateProblem` tests to reflect changes in problem path structure and options handling.
- Changed test cases to use more specific topic paths, including "math/algebra/linear-equations/withFractions."
- Modified the options parameter in request queries to be stringified objects for consistency.
- Ensured proper assertions are in place for successful generation, not found cases, and internal server errors.

Related to issue #4
  • Loading branch information
TKanX committed Oct 14, 2024
1 parent 2510936 commit 7f3d0d6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/controllers/problemController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe("ProblemController - getIndex", () => {
describe("ProblemController - generateProblem", () => {
it("should generate a problem successfully", () => {
const req = {
params: { 0: "topic1/topic2" },
query: { options: "someOptions" },
params: { 0: "math/algebra/linear-equations/withFractions" },
query: { options: JSON.stringify({}) },
};
const res = {
success: jest.fn(),
Expand All @@ -43,8 +43,8 @@ describe("ProblemController - generateProblem", () => {
problemController.generateProblem(req, res);

expect(ProblemGenerator.prototype.generateOne).toHaveBeenCalledWith({
path: ["topic1", "topic2"],
options: "someOptions",
path: ["math", "algebra", "linear-equations", "withFractions"],
options: {},
});
expect(res.success).toHaveBeenCalledWith(
generatedProblem,
Expand All @@ -55,7 +55,7 @@ describe("ProblemController - generateProblem", () => {
it("should return 404 if generator is not found", () => {
const req = {
params: { 0: "invalidTopic" },
query: { options: "someOptions" },
query: { options: JSON.stringify({}) },
};
const res = {
success: jest.fn(),
Expand All @@ -77,7 +77,7 @@ describe("ProblemController - generateProblem", () => {
it("should return 500 if there is an error generating the problem", () => {
const req = {
params: { 0: "topic1/topic2" },
query: { options: "someOptions" },
query: { options: JSON.stringify({}) },
};
const res = {
success: jest.fn(),
Expand Down

0 comments on commit 7f3d0d6

Please sign in to comment.