test(#411): QA-015 — add credentials fallback test + fix refreshSession test name

Add test for non-string error.message fallback in handleCredentialsLogin.
Rename misleading refreshSession test to match actual behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-02-16 14:05:30 -06:00
parent e0d6d585b3
commit b675db1324
2 changed files with 32 additions and 15 deletions

View File

@@ -411,7 +411,7 @@ describe("AuthContext", (): void => {
consoleErrorSpy.mockRestore();
});
it("should clear authError after successful session refresh", async (): Promise<void> => {
it("should persist authError across re-renders when no new session check occurs", async (): Promise<void> => {
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {
// Intentionally empty
});
@@ -429,26 +429,16 @@ describe("AuthContext", (): void => {
expect(screen.getByTestId("auth-error")).toHaveTextContent("network");
});
// Set up successful response for refresh
const mockUser: AuthUser = {
id: "user-1",
email: "test@example.com",
name: "Test User",
};
vi.mocked(apiGet).mockResolvedValueOnce({
user: mockUser,
session: { id: "session-1", token: "token123", expiresAt: futureExpiry() },
});
// Trigger a rerender (simulating refreshSession being called)
// Re-render does NOT trigger a new session check, so authError persists
rerender(
<AuthProvider>
<TestComponent />
</AuthProvider>
);
// The initial render will have checked session once, error should still be there
// A real refresh would need to call refreshSession
// authError should still be "network" — re-render alone does not clear it
expect(screen.getByTestId("auth-error")).toHaveTextContent("network");
consoleErrorSpy.mockRestore();
});
});