test(timetable): useTimetableMutations 409 rollback + idempotency-key semantics (Step 9)

Minimal seam in src/composables/api/useTimetableMutations.ts: the move()
mutation's onError now calls useNotificationStore().show(...) on a 409
status. Generic axios errors stay quiet here — the global response
handler in lib/axios/factory.ts already toasts those. RFC D14 wanted
the version-mismatch toast specifically.

apps/app/tests/component/useTimetableMutations.test.ts (NEW, 5 tests):
  - on success: returns server payload with bumped version + sends the
    Idempotency-Key supplied by the caller
  - 409: rejects with VersionMismatchError + notification.show()
    invoked once with the Dutch translation + 'error' level
  - cascade: success with cascaded[] populated puts those peers into
    the result.cascaded array
  - Idempotency-Key uniqueness: two distinct logical move() calls send
    distinct keys
  - Idempotency-Key reuse: caller-controlled retry within the same
    logical action sends the SAME key on the wire (so the backend's
    60s idempotency middleware dedupes)

The two existing unit-project tests now register a Pinia instance
(createPinia + setActivePinia) so useNotificationStore() resolves.
Existing assertions unchanged.

Test count: 364 → 369.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 03:48:39 +02:00
parent 8db6ca6024
commit fbfe72d090
4 changed files with 276 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import { QueryClient, VueQueryPlugin } from '@tanstack/vue-query'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { defineComponent, h, ref } from 'vue'
import { ZodError } from 'zod'
@@ -39,14 +40,18 @@ function mountWithMutations() {
})
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
const pinia = createPinia()
mount(Host, { global: { plugins: [[VueQueryPlugin, { queryClient }]] } })
mount(Host, { global: { plugins: [pinia, [VueQueryPlugin, { queryClient }]] } })
return { api }
}
describe('Zod parse failure on API responses', () => {
beforeEach(() => vi.clearAllMocks())
beforeEach(() => {
setActivePinia(createPinia())
vi.clearAllMocks()
})
it('move() throws a ZodError when the success payload omits required fields', async () => {
// Backend renamed `cascaded` → `cascadedItems`, or removed `version`, etc.