41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('@/shared/config/env', () => ({
|
|
getEnv: () => ({
|
|
CONUSAI_API_URL: 'https://console.example.com',
|
|
CONUSAI_API_TOKEN: 'dt_fixture',
|
|
}),
|
|
}))
|
|
|
|
// The platform answering 403 (a deployment token the catalog routes reject)
|
|
// throws inside the SDK call when throwOnError is set.
|
|
vi.mock('@conusai-sdk/api', () => ({
|
|
getPlatformInfo: vi.fn(async () => {
|
|
throw Object.assign(new Error('forbidden'), { status: 403 })
|
|
}),
|
|
getServiceType: vi.fn(async () => {
|
|
throw Object.assign(new Error('forbidden'), { status: 403 })
|
|
}),
|
|
}))
|
|
|
|
describe('platform reads when the platform refuses them', () => {
|
|
it('serviceCatalogEntry returns null on a 403 instead of throwing during render', async () => {
|
|
const { serviceCatalogEntry } = await import('@/shared/api/platform/server')
|
|
await expect(serviceCatalogEntry('redis')).resolves.toBeNull()
|
|
})
|
|
|
|
it('platformInfo returns null on a 403 instead of throwing during render', async () => {
|
|
const { platformInfo } = await import('@/shared/api/platform/server')
|
|
await expect(platformInfo()).resolves.toBeNull()
|
|
})
|
|
|
|
it('logs the failure once per read, not once per request', async () => {
|
|
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
const { serviceCatalogEntry } = await import('@/shared/api/platform/server')
|
|
await serviceCatalogEntry('qdrant')
|
|
await serviceCatalogEntry('qdrant')
|
|
expect(warn).toHaveBeenCalledTimes(1)
|
|
warn.mockRestore()
|
|
})
|
|
})
|