diff --git a/apps/api/src/routes/settings.test.ts b/apps/api/src/routes/settings.test.ts index 4f47a6e..36e4865 100644 --- a/apps/api/src/routes/settings.test.ts +++ b/apps/api/src/routes/settings.test.ts @@ -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 }) diff --git a/apps/api/src/services/cfdm-sync.ts b/apps/api/src/services/cfdm-sync.ts index a821132..be7f413 100644 --- a/apps/api/src/services/cfdm-sync.ts +++ b/apps/api/src/services/cfdm-sync.ts @@ -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' } diff --git a/apps/web/src/components/integrations/cfdm-integration-card.tsx b/apps/web/src/components/integrations/cfdm-integration-card.tsx index 2385a30..07bed8b 100644 --- a/apps/web/src/components/integrations/cfdm-integration-card.tsx +++ b/apps/web/src/components/integrations/cfdm-integration-card.tsx @@ -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 (
( @@ -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()} >