diff --git a/frontend/src/components/admin/ErrorPassthroughRulesModal.vue b/frontend/src/components/admin/ErrorPassthroughRulesModal.vue index ce8d14424d..dad35922ea 100644 --- a/frontend/src/components/admin/ErrorPassthroughRulesModal.vue +++ b/frontend/src/components/admin/ErrorPassthroughRulesModal.vue @@ -621,8 +621,8 @@ const handleSubmit = async () => { const toggleEnabled = async (rule: ErrorPassthroughRule) => { try { - await adminAPI.errorPassthrough.toggleEnabled(rule.id, !rule.enabled) - rule.enabled = !rule.enabled + const updated = await adminAPI.errorPassthrough.toggleEnabled(rule.id, !rule.enabled) + rule.enabled = updated.enabled } catch (error: any) { appStore.showError(error.response?.data?.detail || t('admin.errorPassthrough.failedToToggle')) console.error('Error toggling rule:', error) diff --git a/frontend/src/components/admin/__tests__/ErrorPassthroughRulesModal.toggle.spec.ts b/frontend/src/components/admin/__tests__/ErrorPassthroughRulesModal.toggle.spec.ts new file mode 100644 index 0000000000..e1a91ec1d5 --- /dev/null +++ b/frontend/src/components/admin/__tests__/ErrorPassthroughRulesModal.toggle.spec.ts @@ -0,0 +1,71 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils' +import ErrorPassthroughRulesModal from '../ErrorPassthroughRulesModal.vue' + +const mocks = vi.hoisted(() => ({ list: vi.fn(), toggleEnabled: vi.fn(), showError: vi.fn() })) +vi.mock('@/api/admin', () => ({ adminAPI: { errorPassthrough: mocks } })) +vi.mock('@/stores/app', () => ({ useAppStore: () => ({ showError: mocks.showError }) })) +vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) })) +enableAutoUnmount(afterEach) +afterEach(() => vi.restoreAllMocks()) +beforeEach(() => vi.resetAllMocks()) + +function rule(enabled: boolean) { + return { id: 7, name: 'Rule', enabled, priority: 1, error_codes: [429], keywords: [], + platforms: [], match_mode: 'any', passthrough_code: true, passthrough_body: true, skip_monitoring: false } +} + +async function openRules(enabled = true) { + mocks.list.mockResolvedValue([rule(enabled)]) + const wrapper = mount(ErrorPassthroughRulesModal, { + props: { show: false }, + global: { stubs: { + BaseDialog: { props: ['show'], template: '