From 81ddfc2f58d2371ad18b7042987e6d299b8f7080 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 15 Aug 2025 14:40:29 -0700 Subject: [PATCH] [fix] Update firebaseAuthStore tests to mock axios client - Move axios mock setup before store import to ensure client is mocked - Set up default successful responses for customer API endpoints - Fix TypeScript issues with isAxiosError mock type --- .../tests/store/firebaseAuthStore.test.ts | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests-ui/tests/store/firebaseAuthStore.test.ts b/tests-ui/tests/store/firebaseAuthStore.test.ts index 7d51685b4..e66389f5a 100644 --- a/tests-ui/tests/store/firebaseAuthStore.test.ts +++ b/tests-ui/tests/store/firebaseAuthStore.test.ts @@ -1,3 +1,4 @@ +import axios from 'axios' import * as firebaseAuth from 'firebase/auth' import { createPinia, setActivePinia } from 'pinia' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -5,6 +6,25 @@ import * as vuefire from 'vuefire' import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore' +// Mock axios before any imports that use it +vi.mock('axios') +const mockedAxios = vi.mocked(axios) + +// Set up axios mock with default instance +const mockAxiosInstance = { + get: vi.fn().mockResolvedValue({ + data: { balance: { credits: 0 } }, + status: 200 + }), + post: vi.fn().mockResolvedValue({ + data: { id: 'test-customer-id' }, + status: 201 + }) +} + +mockedAxios.create = vi.fn().mockReturnValue(mockAxiosInstance) +mockedAxios.isAxiosError = vi.fn().mockImplementation(() => false) as any + // Mock fetch const mockFetch = vi.fn() vi.stubGlobal('fetch', mockFetch) @@ -91,7 +111,18 @@ describe('useFirebaseAuthStore', () => { } beforeEach(() => { - vi.resetAllMocks() + vi.clearAllMocks() + + // Reset axios mock responses to defaults + mockAxiosInstance.get.mockResolvedValue({ + data: { balance: { credits: 0 } }, + status: 200 + }) + mockAxiosInstance.post.mockResolvedValue({ + data: { id: 'test-customer-id' }, + status: 201 + }) + mockedAxios.isAxiosError = vi.fn().mockImplementation(() => false) as any // Mock useFirebaseAuth to return our mock auth object vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(mockAuth as any)