Skip to content

Commit 49d2fa4

Browse files
test: align oneshot upload unit test with token validation flow
Co-authored-by: MinecraftFuns <25814618+MinecraftFuns@users.noreply.github.com> Agent-Logs-Url: https://github.com/BTreeMap/OneShot/sessions/9608e356-3f93-462c-8250-5a88f68f2acf
1 parent beb0df4 commit 49d2fa4

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

web/src/pages/OneShotUpload.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export function OneShotUpload() {
3030

3131
useEffect(() => {
3232
if (!token) {
33-
setUploadState("ERROR_INVALID_TOKEN");
3433
return;
3534
}
3635
let isMounted = true;

web/src/pages/__tests__/OneShotUpload.test.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ describe("OneShotUpload", () => {
99
});
1010

1111
it("extracts token from hash and sends Authorization bearer header", async () => {
12-
const mockFetch = vi.spyOn(window, "fetch").mockResolvedValue(
13-
new Response(JSON.stringify({ file_id: "f123" }), {
14-
status: 200,
15-
headers: { "Content-Type": "application/json" },
16-
}),
17-
);
12+
const mockFetch = vi
13+
.spyOn(window, "fetch")
14+
.mockResolvedValueOnce(
15+
new Response(JSON.stringify({ valid: true }), {
16+
status: 200,
17+
headers: { "Content-Type": "application/json" },
18+
}),
19+
)
20+
.mockResolvedValueOnce(
21+
new Response(JSON.stringify({ file_id: "f123" }), {
22+
status: 200,
23+
headers: { "Content-Type": "application/json" },
24+
}),
25+
);
1826

1927
render(<OneShotUpload />);
2028

21-
const input = screen.getByLabelText("File") as HTMLInputElement;
29+
const input = await screen.findByLabelText("Upload File");
2230
const file = new File(["hello"], "hello.txt", { type: "text/plain" });
2331
fireEvent.change(input, { target: { files: [file] } });
2432
fireEvent.click(screen.getByRole("button", { name: "Upload" }));
@@ -27,7 +35,7 @@ describe("OneShotUpload", () => {
2735
expect(mockFetch).toHaveBeenCalled();
2836
});
2937

30-
const [, init] = mockFetch.mock.calls[0]!;
38+
const [, init] = mockFetch.mock.calls[1]!;
3139
const headers = (init?.headers ?? {}) as Record<string, string>;
3240
expect(headers.Authorization).toBe("Bearer t12345");
3341
});

0 commit comments

Comments
 (0)