Skip to content

Commit

Permalink
Handle invalid ticketState and add new test.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosuma committed Feb 19, 2023
1 parent 528db9d commit b2867ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion web/controllers/__tests__/reports.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ require("dotenv").config();
describe("Controller", () => {
const mockResponse = () => {
const res = {};
res.status = jest.fn().mockReturnValue(res);
res.status = jest.fn().mockImplementation((code) => {
res.code = code;
return res;
});
res.send = jest.fn().mockReturnValue(res);
res.json = jest.fn().mockReturnValue(res);
return res;
Expand Down Expand Up @@ -72,4 +75,16 @@ describe("Controller", () => {

expect(ReportModel.getReports).toBeCalled();
});

it("it returns 400 when ticketState is invalid", async () => {
res = await controller.updateReport(
{
params: { reportId: "mock-id" },
body: { ticketState: "WRONG_REQUEST" },
},
mockResponse()
);

expect(res.code).toBe(400);
});
});
3 changes: 3 additions & 0 deletions web/controllers/reports.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const UPDATE_HANDLER = {
};

exports.updateReport = (req, res) => {
if (UPDATE_HANDLER[req.body.ticketState] === undefined) {
return res.status(400).send();
}
UPDATE_HANDLER[req.body.ticketState].execute(
DataModel.getReportModel(),
req,
Expand Down

0 comments on commit b2867ac

Please sign in to comment.