Scaffolding baseline
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { fetchHealth, getApiBaseUrl } from './client'
|
||||
|
||||
describe('getApiBaseUrl', () => {
|
||||
it('defaults to localhost:8080 when unset', () => {
|
||||
expect(getApiBaseUrl()).toBe('http://localhost:8080')
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetchHealth', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('returns parsed health payload', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ status: 'ok' }),
|
||||
})
|
||||
|
||||
const health = await fetchHealth(fetchMock)
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('http://localhost:8080/health')
|
||||
expect(health).toEqual({ status: 'ok' })
|
||||
})
|
||||
|
||||
it('throws when the response is not ok', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 503,
|
||||
json: async () => ({}),
|
||||
})
|
||||
|
||||
await expect(fetchHealth(fetchMock)).rejects.toThrow(
|
||||
'health check failed: 503',
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user