fix(auth): initialize Google Identity once

This commit is contained in:
cesnimda
2026-08-30 22:16:59 +02:00
parent 058d13de47
commit 9ad812e9ba
4 changed files with 63 additions and 31 deletions
+3 -1
View File
@@ -155,8 +155,9 @@ describe('LoginPage', () => {
it('completes a Google credential return without account-linking copy', async () => {
process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID = 'google-client';
let callback: ((response: { credential: string }) => void) | undefined;
const initialize = jest.fn((options: any) => { callback = options.callback; });
(window as any).google = { accounts: { id: {
initialize: jest.fn((options: any) => { callback = options.callback; }),
initialize,
renderButton: jest.fn((host: HTMLElement) => {
const button = document.createElement('button');
button.textContent = 'Continue with Google';
@@ -172,6 +173,7 @@ describe('LoginPage', () => {
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledWith('/auth/google/exchange', { token: 'synthetic-google-token', rememberMe: true }));
await waitFor(() => expect(mockNavigate).toHaveBeenCalledWith('/dashboard', { replace: true }));
expect(initialize).toHaveBeenCalledTimes(1);
expect(screen.queryByText(/create your account automatically/i)).not.toBeInTheDocument();
});