forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB0069847Burak Boduroğlu2 months ago552 commits

builder.test.ts44 lines, 1.4 KiBHistoryRawDownload
1import { afterEach, describe, expect, it, vi } from "vitest";
2import { getBuilderMe } from "../../builder";
3import { postBuilderLogin } from "../../builder";
4import { postBuilderLogout } from "../../builder";
5import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
6
7describe("builder API", () => {
8 afterEach(() => {
9 vi.restoreAllMocks();
10 });
11
12 it("postBuilderLogin posts credentials to /builder/login", async () => {
13 const builder = { id: "b1", username: "operator" };
14 mockFetchSuccess(builder);
15
16 const result = await postBuilderLogin({ username: "operator", password: "correct horse" });
17 expect(result).toEqual(builder);
18
19 const [url, init] = lastFetchCall();
20 expect(url).toBe("/api/builder/login");
21 expect(init?.method).toBe("POST");
22 expect(init?.body).toBe(JSON.stringify({ username: "operator", password: "correct horse" }));
23 });
24
25 it("postBuilderLogout posts to /builder/logout", async () => {
26 mockFetch204();
27
28 await postBuilderLogout();
29
30 const [url, init] = lastFetchCall();
31 expect(url).toBe("/api/builder/logout");
32 expect(init?.method).toBe("POST");
33 });
34
35 it("getBuilderMe reads /builder/me", async () => {
36 mockFetchSuccess({ id: "b1", username: "operator" });
37
38 await getBuilderMe();
39
40 const [url, init] = lastFetchCall();
41 expect(url).toBe("/api/builder/me");
42 expect(init?.method).toBe("GET");
43 });
44});