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' }
|
||||
|
||||
@@ -51,7 +51,7 @@ export function CfdmIntegrationForm({
|
||||
values: {
|
||||
cfdmApiUrl: settings?.cfdmApiUrl ?? '',
|
||||
integrationToken: '',
|
||||
integrationEnabled: settings?.integrationEnabled === true,
|
||||
integrationEnabled: Boolean(settings?.integrationEnabled),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -79,10 +79,9 @@ export function CfdmIntegrationForm({
|
||||
})
|
||||
}
|
||||
|
||||
// Только сохранённые credentials — без ввода токена и без «сначала сохранить форму».
|
||||
const canSync =
|
||||
settings?.integrationEnabled === true &&
|
||||
Boolean(settings?.cfdmApiUrl?.trim()) &&
|
||||
settings?.integrationTokenSet === true
|
||||
Boolean(settings?.cfdmApiUrl?.trim()) && Boolean(settings?.integrationTokenSet)
|
||||
|
||||
return (
|
||||
<form
|
||||
@@ -99,7 +98,7 @@ export function CfdmIntegrationForm({
|
||||
name="integrationEnabled"
|
||||
render={({ field }) => (
|
||||
<Switch
|
||||
checked={field.value}
|
||||
checked={Boolean(field.value)}
|
||||
onCheckedChange={field.onChange}
|
||||
aria-label="Принимать синхронизацию"
|
||||
/>
|
||||
@@ -172,7 +171,12 @@ export function CfdmIntegrationForm({
|
||||
variant="outline"
|
||||
size="sm"
|
||||
loading={syncMut.isPending}
|
||||
disabled={!canSync || form.formState.isDirty}
|
||||
disabled={!canSync}
|
||||
title={
|
||||
canSync
|
||||
? 'Запустить sync по сохранённым URL и токену'
|
||||
: 'Сначала сохраните URL API CFDM и integration token'
|
||||
}
|
||||
onClick={() => syncMut.mutate()}
|
||||
>
|
||||
<RefreshCwIcon data-icon="inline-start" aria-hidden="true" />
|
||||
|
||||
Reference in New Issue
Block a user