CI and images / lint (push) Successful in 2s
CI and images / extension-version (push) Successful in 2s
CI and images / frontend-build (push) Successful in 20s
CI and images / backend-lint-and-test (push) Successful in 30s
CI and images / integration (push) Successful in 2m18s
CI and images / sign-extension (push) Successful in 3s
CI and images / build-agent (push) Successful in 6s
CI and images / build-web (push) Successful in 1m44s
CI and images / smoke-web (push) Successful in 56s
CI and images / promote (push) Skipped
tests/factories.py holds image_row/make_image/make_image_async/make_tag. The 17 byte-identical _img/_tag helpers (15 modules) now import them under their old names, so no call site changed. frontend/test/support/stubFetch.js replaces 15 copies that differed only in formatting. Copies whose bodies differ (other defaults, other columns, a url-only stub) are left as they are; folding those needs a look at each caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR
75 lines
2.7 KiB
JavaScript
75 lines
2.7 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import { useAdminStore } from '../src/stores/admin.js'
|
|
import { stubFetch } from './support/stubFetch.js'
|
|
|
|
// Covers the two helpers the admin store actions route through (DRY Finding C,
|
|
// #753): _dryRunPost (URL + dry_run body, sourceId→source_id) and _guard
|
|
// (lastError capture + rethrow). The store had no frontend test before.
|
|
|
|
function lastCallBody(calls) {
|
|
return JSON.parse(calls.at(-1).init.body)
|
|
}
|
|
|
|
describe('admin store', () => {
|
|
beforeEach(() => setActivePinia(createPinia()))
|
|
afterEach(() => vi.restoreAllMocks())
|
|
|
|
it('_dryRunPost sends the apply flag to the right endpoint', async () => {
|
|
const s = useAdminStore()
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, init })
|
|
return { status: 200, body: { deleted: 0 } }
|
|
})
|
|
await s.pruneUnusedTags({ dryRun: false })
|
|
const c = calls.at(-1)
|
|
expect(c.url).toContain('/api/admin/tags/prune-unused')
|
|
expect(c.init.method).toBe('POST')
|
|
expect(lastCallBody(calls)).toEqual({ dry_run: false })
|
|
})
|
|
|
|
it('_dryRunPost defaults to the safe preview', async () => {
|
|
const s = useAdminStore()
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, init })
|
|
return { status: 200, body: { count: 0 } }
|
|
})
|
|
await s.pruneBarePosts()
|
|
expect(lastCallBody(calls)).toEqual({ dry_run: true })
|
|
})
|
|
|
|
it('reconcileDuplicatePosts maps sourceId → source_id', async () => {
|
|
const s = useAdminStore()
|
|
const calls = []
|
|
stubFetch((url, init) => {
|
|
calls.push({ url, init })
|
|
return { status: 200, body: { groups: 0 } }
|
|
})
|
|
await s.reconcileDuplicatePosts({ dryRun: false, sourceId: 42 })
|
|
const c = calls.at(-1)
|
|
expect(c.url).toContain('/api/admin/posts/reconcile-duplicates')
|
|
expect(lastCallBody(calls)).toEqual({ dry_run: false, source_id: 42 })
|
|
})
|
|
|
|
it('_guard captures the error message on lastError and rethrows', async () => {
|
|
const s = useAdminStore()
|
|
stubFetch(() => ({ status: 500, body: { error: 'boom' } }))
|
|
await expect(s.deleteTag(7)).rejects.toThrow('boom')
|
|
expect(s.lastError).toBe('boom')
|
|
})
|
|
|
|
it('_guard clears lastError on a subsequent success', async () => {
|
|
const s = useAdminStore()
|
|
stubFetch(() => ({ status: 500, body: { error: 'boom' } }))
|
|
await expect(s.deleteTag(7)).rejects.toThrow()
|
|
expect(s.lastError).toBe('boom')
|
|
|
|
stubFetch(() => ({ status: 200, body: { count: 3 } }))
|
|
const n = await s.tagUsageCount(7)
|
|
expect(n).toBe(3) // tagUsageCount returns body.count, not the raw body
|
|
expect(s.lastError).toBe(null)
|
|
})
|
|
})
|