Skip to content

Commit

Permalink
test: add invalid CSRF token test case (#5488)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Makowski <[email protected]>
  • Loading branch information
petermakowski authored Jun 26, 2024
1 parent f796cc5 commit e665732
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/api/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ it("should handle errors", async () => {
.mockResolvedValue({ ok: false, statusText: "Bad Request" });
await expect(fetchWithAuth(url)).rejects.toThrow("Bad Request");
});

it("should handle invalid CSRF token", async () => {
(getCookie as Mock).mockReturnValue(null);

const mockResponse = {
ok: false,
status: 403,
statusText: "Forbidden",
};
global.fetch = vi.fn().mockResolvedValue(mockResponse);

await expect(fetchWithAuth(url)).rejects.toThrow("Forbidden");
expect(fetch).toHaveBeenCalledWith(url, {
headers: { ...DEFAULT_HEADERS, "X-CSRFToken": "" },
});
});

0 comments on commit e665732

Please sign in to comment.