Skip to content

Commit

Permalink
updated tests for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinogwanz committed Oct 21, 2024
1 parent 100834e commit 29a4c51
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nodejs_api/__tests__/integration/tickets.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,9 @@ describe("Integration Tests - /tickets", () => {
const mockRequestBody = {
comment: "This is a test comment without an image.",
ticket_id: "ticket123",
user_id: "user456"
user_id: "user456",
user_role: "CITIZEN",
date_created: "2022-01-01T12:00:00Z"
};

const mockServiceResponse = {
Expand All @@ -684,11 +686,7 @@ describe("Integration Tests - /tickets", () => {

expect(response.body).toEqual(mockServiceResponse);

expect(ticketsService.addTicketCommentWithoutImage).toHaveBeenCalledWith(
mockRequestBody.comment,
mockRequestBody.ticket_id,
mockRequestBody.user_id
);
expect(ticketsService.addTicketCommentWithoutImage).toHaveBeenCalledWith(mockRequestBody);
});

test("should return 400 if required fields are missing", async () => {
Expand All @@ -703,14 +701,16 @@ describe("Integration Tests - /tickets", () => {

expect(response.statusCode).toBe(400);

expect(response.body.error).toBe("Missing parameter(s): comment");
expect(response.body.error).toBe("Missing parameter(s): comment, date_created, user_role");
});

test("should return 500 if there is an internal server error", async () => {
const mockRequestBody = {
comment: "This is a test comment without an image.",
ticket_id: "ticket123",
user_id: "user456"
user_id: "user456",
user_role: "CITIZEN",
date_created: "2022-01-01T12:00:00Z"
};

jest.spyOn(ticketsService, "addTicketCommentWithoutImage").mockRejectedValue(new Error("Internal Server Error"));
Expand Down

0 comments on commit 29a4c51

Please sign in to comment.