fix(settings): update CFDM sync tests and improve error handling
Docker / build (push) Failing after 21s
Docker / build (push) Failing after 21s
Renamed test cases for clarity and added new tests for handling missing CFDM URL and token scenarios. Removed unnecessary checks in the sync request function to streamline the process. Updated integration form to ensure proper boolean handling for settings. Enhanced sync button behavior based on saved credentials.
This commit is contained in:
@@ -101,7 +101,7 @@ describe('settings cfdm sync', () => {
|
||||
closeDb()
|
||||
})
|
||||
|
||||
it('çàïðàøèâàåò ïîëíûé sync ó CFDM', async () => {
|
||||
it('requests full sync from CFDM', async () => {
|
||||
const fetchMock = vi.fn(async () => Response.json({ ok: true, count: 3 }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
@@ -116,12 +116,27 @@ describe('settings cfdm sync', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('âîçâðàùàåò îøèáêó åñëè ïðè¸ì âûêëþ÷åí', async () => {
|
||||
it('works with saved token even when accept toggle is off', async () => {
|
||||
settingsRepository.upsert('settings-main', {
|
||||
integrationEnabled: false,
|
||||
integrationToken: 'shared-token',
|
||||
cfdmApiUrl: 'http://cfdm.test',
|
||||
})
|
||||
const fetchMock = vi.fn(async () => Response.json({ ok: true, count: 1 }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
const res = await app.inject({ method: 'POST', url: '/api/settings/cfdm/sync' })
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(res.json()).toEqual({ ok: true, count: 1 })
|
||||
expect(fetchMock).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('returns error when CFDM URL is missing', async () => {
|
||||
settingsRepository.upsert('settings-main', {
|
||||
integrationEnabled: true,
|
||||
integrationToken: 'shared-token',
|
||||
cfdmApiUrl: '',
|
||||
})
|
||||
const res = await app.inject({ method: 'POST', url: '/api/settings/cfdm/sync' })
|
||||
expect(res.statusCode).toBe(502)
|
||||
expect(res.json()).toMatchObject({ ok: false })
|
||||
|
||||
@@ -14,11 +14,6 @@ export async function requestCfdmFullSync(): Promise<{
|
||||
count?: number
|
||||
error?: string
|
||||
}> {
|
||||
const row = settingsRepository.getBySpace()
|
||||
if (!row?.integrationEnabled) {
|
||||
return { ok: false, error: 'Включите приём синхронизации' }
|
||||
}
|
||||
|
||||
const token = settingsRepository.getIntegrationToken()
|
||||
const baseUrl = resolveCfdmApiBase()
|
||||
if (!baseUrl) return { ok: false, error: 'Укажите URL API CFDM' }
|
||||
|
||||
Reference in New Issue
Block a user