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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user