[feat] Integrate header registry with all HTTP clients

- Replace direct fetch() with fetchWithHeaders across entire codebase
- Replace axios.create() with createAxiosWithHeaders in all services
- Update tests to properly mock network client adapters
- Fix hoisting issues in test mocks for axios instances
- Ensure all network calls now support header injection

This completes Step 2: integrating the header registry infrastructure with all existing HTTP clients in the codebase.
This commit is contained in:
bymyself
2025-08-16 14:13:21 -07:00
parent d6695ea66e
commit d05153a0dc
19 changed files with 192 additions and 89 deletions

View File

@@ -6,19 +6,27 @@ import * as vuefire from 'vuefire'
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
// Mock axios before any imports that use it
vi.mock('axios', () => {
const mockAxiosInstance = {
get: vi.fn().mockResolvedValue({
data: { balance: { credits: 0 } },
status: 200
}),
post: vi.fn().mockResolvedValue({
data: { id: 'test-customer-id' },
status: 201
})
// Hoist the mock to avoid hoisting issues
const mockAxiosInstance = vi.hoisted(() => ({
get: vi.fn().mockResolvedValue({
data: { balance: { credits: 0 } },
status: 200
}),
post: vi.fn().mockResolvedValue({
data: { id: 'test-customer-id' },
status: 201
}),
interceptors: {
request: {
use: vi.fn()
},
response: {
use: vi.fn()
}
}
}))
vi.mock('axios', () => {
return {
default: {
create: vi.fn().mockReturnValue(mockAxiosInstance),
@@ -27,8 +35,12 @@ vi.mock('axios', () => {
}
})
// Mock networkClientAdapter
vi.mock('@/services/networkClientAdapter', () => ({
createAxiosWithHeaders: vi.fn(() => mockAxiosInstance)
}))
const mockedAxios = vi.mocked(axios)
const mockAxiosInstance = mockedAxios.create() as any
// Mock fetch
const mockFetch = vi.fn()