fix(web): null-guard в мутациях (no active project), AuthContext различает 401 и ошибки сервера

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwxdSt4reTm7Dj1oxRvpP3
This commit is contained in:
2026-07-03 21:07:48 +07:00
parent b5d9e8f7ab
commit 222d6c0453
4 changed files with 103 additions and 16 deletions
+12
View File
@@ -67,6 +67,18 @@ describe("AuthContext", () => {
expect(screen.getByTestId("project").textContent).toBe(PROJECT.name)
})
it("treats a non-401 error from api.auth.me() as logged-out but logs it for diagnostics", async () => {
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
const err = new Error("network down")
vi.spyOn(api.auth, "me").mockRejectedValue(err)
renderProbe()
await waitFor(() => expect(screen.getByTestId("loading").textContent).toBe("false"))
expect(screen.getByTestId("user").textContent).toBe("none")
expect(screen.getByTestId("project").textContent).toBe("none")
expect(consoleErrorSpy).toHaveBeenCalledWith(err)
})
it("logout clears user/project from context", async () => {
vi.spyOn(api.auth, "me").mockResolvedValue({ user: USER, project: PROJECT })
vi.spyOn(api.auth, "logout").mockResolvedValue(undefined)