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
66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import { useProvenanceStore } from '../src/stores/provenance.js'
|
|
import { stubFetch } from './support/stubFetch.js'
|
|
|
|
describe('provenance store', () => {
|
|
beforeEach(() => setActivePinia(createPinia()))
|
|
afterEach(() => vi.restoreAllMocks())
|
|
|
|
it('loadForImage caches: repeat same id does not refetch', async () => {
|
|
const store = useProvenanceStore()
|
|
stubFetch(() => ({ status: 200, body: { image_id: 5, provenance: [] } }))
|
|
await store.loadForImage(5)
|
|
await store.loadForImage(5)
|
|
expect(globalThis.fetch.mock.calls.length).toBe(1)
|
|
expect(store.imageProv(5).entries).toEqual([])
|
|
})
|
|
|
|
it('loadForImage fetches distinct ids separately', async () => {
|
|
const store = useProvenanceStore()
|
|
stubFetch(() => ({
|
|
status: 200,
|
|
body: { image_id: 1, provenance: [{ provenance_id: 9 }] }
|
|
}))
|
|
await store.loadForImage(1)
|
|
await store.loadForImage(2)
|
|
expect(globalThis.fetch.mock.calls.length).toBe(2)
|
|
expect(store.imageProv(1).entries.length).toBe(1)
|
|
})
|
|
|
|
it('loadForImage records error without throwing', async () => {
|
|
const store = useProvenanceStore()
|
|
stubFetch(() => ({ status: 404, body: { error: 'not found' } }))
|
|
await store.loadForImage(7)
|
|
expect(store.imageProv(7).error).toBeTruthy()
|
|
expect(store.imageProv(7).entries).toBe(null)
|
|
})
|
|
|
|
it('loadForPost caches and stores post/source/artist', async () => {
|
|
const store = useProvenanceStore()
|
|
stubFetch(() => ({
|
|
status: 200,
|
|
body: { post: { id: 3 }, source: { platform: 'patreon' },
|
|
artist: { name: 'A', slug: 'a' } }
|
|
}))
|
|
await store.loadForPost(3)
|
|
await store.loadForPost(3)
|
|
expect(globalThis.fetch.mock.calls.length).toBe(1)
|
|
expect(store.postInfo(3).data.artist.slug).toBe('a')
|
|
})
|
|
|
|
it('loadForImage keeps attachments from the payload', async () => {
|
|
const store = useProvenanceStore()
|
|
stubFetch(() => ({
|
|
status: 200,
|
|
body: {
|
|
image_id: 1, provenance: [],
|
|
attachments: [{ id: 9, original_filename: 'p.zip', size_bytes: 5,
|
|
ext: '.zip', download_url: '/api/attachments/9/download' }]
|
|
}
|
|
}))
|
|
await store.loadForImage(1)
|
|
expect(store.imageProv(1).attachments[0].id).toBe(9)
|
|
})
|
|
})
|