hensei-web/src/routes/database/summons/[id]/page.server.test.ts
Justin Edmund 4f8beab3ea fix: Update PartyAdapter to match corrected API endpoints
- Remove non-existent batch update methods for grid items
- Add gridUpdate for atomic batch operations
- Add preview management methods
- Split job management into separate endpoints
- Update tests to match new API structure
2025-09-20 00:04:36 -07:00

35 lines
1.3 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
import { actions } from './+page.server'
import { toEditData } from '$lib/features/database/summons/schema'
function makeEvent(edit: any, opts?: { status?: number }) {
const form = new FormData()
form.set('payload', JSON.stringify(edit))
const request = { formData: async () => form } as unknown as Request
const status = opts?.status ?? 200
const fetch = vi.fn(async () => new Response('{}', { status }))
const params = { id: '2040004000' } as any
return { request, fetch, params } as any
}
describe('summons actions.save', () => {
it('succeeds on valid payload', async () => {
const edit = toEditData({ granblue_id: '2040004000' })
const res: any = await actions.save!(makeEvent(edit))
expect(res).toMatchObject({ success: true })
})
it('fails validation for bad payload', async () => {
const edit = { ...toEditData({ granblue_id: 'x' }), granblue_id: '' }
const res: any = await actions.save!(makeEvent(edit))
expect(res.status).toBe(422)
expect(res.data.message).toBe('Validation error')
})
it('handles backend error', async () => {
const edit = toEditData({ granblue_id: '2040004000' })
const res: any = await actions.save!(makeEvent(edit, { status: 500 }))
expect(res.status).toBe(500)
})
})