Skip to content

Commit

Permalink
test: fix definer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omermecitoglu committed Oct 23, 2024
1 parent 0b9413d commit b48588f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/core/definer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ describe("defineRoute", () => {
mockAction.mockResolvedValue(new Response("Success"));

const nextJsRouteHandler = route.GET;
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
const response = await nextJsRouteHandler(mockRequest as unknown as Request);

expect(mockAction).toHaveBeenCalledWith({
pathParams: null,
queryParams: null,
body: null,
});
}, mockRequest);

expect(response).toBeInstanceOf(Response);
expect(response.status).toBe(200);
Expand Down Expand Up @@ -72,7 +72,7 @@ describe("defineRoute", () => {
pathParams: { id: "123" },
queryParams: null,
body: { name: "Test" },
});
}, mockRequest);

expect(response).toBeInstanceOf(Response);
expect(response.status).toBe(201);
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("defineRoute", () => {
});

const nextJsRouteHandler = route.POST;
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
const response = await nextJsRouteHandler(mockRequest as unknown as Request);

expect(response).toBeInstanceOf(Response);
expect(response.status).toBe(400);
Expand Down Expand Up @@ -133,7 +133,7 @@ describe("defineRoute", () => {
});

const nextJsRouteHandler = route.PUT;
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
const response = await nextJsRouteHandler(mockRequest as unknown as Request);

expect(response).toBeInstanceOf(Response);
expect(response.status).toBe(400);
Expand All @@ -149,15 +149,19 @@ describe("defineRoute", () => {
description: "Fetches example data",
tags: ["example"],
action: () => {
throw new Error("Internal Error");
// eslint-disable-next-line no-constant-condition
if (1 + 1 === 2) {
throw new Error("Internal Error");
}
return Response.json({ message: "Internal Error" }, { status: 500 });
},
responses: {
200: { description: "OK" },
},
});

const nextJsRouteHandler = route.GET;
const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
const response = await nextJsRouteHandler(mockRequest as unknown as Request);

expect(response).toBeInstanceOf(Response);
expect(response.status).toBe(500);
Expand Down Expand Up @@ -238,7 +242,7 @@ describe("defineRoute", () => {

const nextJsRouteHandler = route.GET;

await nextJsRouteHandler(mockRequest as unknown as Request, {});
await nextJsRouteHandler(mockRequest as unknown as Request);

expect(console.log).toHaveBeenCalledWith(expect.stringContaining("You tried to add pathParams to a route"));

Expand Down Expand Up @@ -267,7 +271,7 @@ describe("defineRoute", () => {

const nextJsRouteHandler = route.POST;

const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
const bodyText = await response.text();

expect(response).toBeInstanceOf(Response);
Expand Down Expand Up @@ -300,7 +304,7 @@ describe("defineRoute", () => {

const nextJsRouteHandler = route.GET;

const response = await nextJsRouteHandler(mockRequest as unknown as Request, {});
const response = await nextJsRouteHandler(mockRequest as unknown as Request);
const bodyText = await response.text();

expect(response).toBeInstanceOf(Response);
Expand Down

0 comments on commit b48588f

Please sign in to comment.