mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +00:00
[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:
@@ -2,6 +2,7 @@ import { flushPromises } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { useTemplateWorkflows } from '@/composables/useTemplateWorkflows'
|
||||
import { fetchWithHeaders } from '@/services/networkClientAdapter'
|
||||
import { useWorkflowTemplatesStore } from '@/stores/workflowTemplatesStore'
|
||||
|
||||
// Mock the store
|
||||
@@ -41,6 +42,11 @@ vi.mock('@/stores/dialogStore', () => ({
|
||||
// Mock fetch
|
||||
global.fetch = vi.fn()
|
||||
|
||||
// Mock fetchWithHeaders
|
||||
vi.mock('@/services/networkClientAdapter', () => ({
|
||||
fetchWithHeaders: vi.fn()
|
||||
}))
|
||||
|
||||
describe('useTemplateWorkflows', () => {
|
||||
let mockWorkflowTemplatesStore: any
|
||||
|
||||
@@ -100,6 +106,11 @@ describe('useTemplateWorkflows', () => {
|
||||
vi.mocked(fetch).mockResolvedValue({
|
||||
json: vi.fn().mockResolvedValue({ workflow: 'data' })
|
||||
} as unknown as Response)
|
||||
|
||||
// Also mock fetchWithHeaders
|
||||
vi.mocked(fetchWithHeaders).mockResolvedValue({
|
||||
json: vi.fn().mockResolvedValue({ workflow: 'data' })
|
||||
} as unknown as Response)
|
||||
})
|
||||
|
||||
it('should load templates from store', async () => {
|
||||
@@ -258,7 +269,9 @@ describe('useTemplateWorkflows', () => {
|
||||
await flushPromises()
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(fetch).toHaveBeenCalledWith('mock-file-url/templates/template1.json')
|
||||
expect(vi.mocked(fetchWithHeaders)).toHaveBeenCalledWith(
|
||||
'mock-file-url/templates/template1.json'
|
||||
)
|
||||
expect(loadingTemplateId.value).toBe(null) // Should reset after loading
|
||||
})
|
||||
|
||||
@@ -273,7 +286,9 @@ describe('useTemplateWorkflows', () => {
|
||||
await flushPromises()
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(fetch).toHaveBeenCalledWith('mock-file-url/templates/template1.json')
|
||||
expect(vi.mocked(fetchWithHeaders)).toHaveBeenCalledWith(
|
||||
'mock-file-url/templates/template1.json'
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle errors when loading templates', async () => {
|
||||
@@ -282,8 +297,10 @@ describe('useTemplateWorkflows', () => {
|
||||
// Set the store as loaded
|
||||
mockWorkflowTemplatesStore.isLoaded = true
|
||||
|
||||
// Mock fetch to throw an error
|
||||
vi.mocked(fetch).mockRejectedValueOnce(new Error('Failed to fetch'))
|
||||
// Mock fetchWithHeaders to throw an error
|
||||
vi.mocked(fetchWithHeaders).mockRejectedValueOnce(
|
||||
new Error('Failed to fetch')
|
||||
)
|
||||
|
||||
// Spy on console.error
|
||||
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
|
||||
Reference in New Issue
Block a user