* ST-1243: F1 schema + propagateStatusUpwards-helper voor sprint-flow Schema-uitbreidingen voor de sprint-niveau jobflow (PBI-46): - TaskStatus, StoryStatus, PbiStatus, SprintStatus krijgen FAILED - Nieuwe enums: SprintRunStatus, PrStrategy - Nieuw SprintRun-model dat per-task ClaudeJobs groepeert - ClaudeJob.sprint_run_id koppeling + index - Product.pr_strategy (default SPRINT) - Bijhorende Prisma-migratie propagateStatusUpwards vervangt updateTaskStatusWithStoryPromotion en herevalueert de keten Task → Story → PBI → Sprint → SprintRun bij elke task-statuswijziging. Bij FAILED cancelt het sibling-jobs in dezelfde SprintRun. PBI-status BLOCKED blijft handmatig en wordt niet overschreven. Status-mappers + theme krijgen failed-token + label-uitbreidingen. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ST-1244: F2 sprint-runs actions + deprecate per-task enqueues actions/sprint-runs.ts (nieuw): - startSprintRunAction met pre-flight (impl_plan / open ClaudeQuestion / PBI BLOCKED|FAILED) - Maakt SprintRun + ClaudeJobs in PBI→Story→Task volgorde - resumeSprintAction zet FAILED tasks/stories/PBIs terug en start nieuwe SprintRun - cancelSprintRunAction breekt lopende SprintRun af zonder cascade actions/claude-jobs.ts: - enqueueClaudeJobAction, enqueueAllTodoJobsAction, previewEnqueueAllAction, enqueueClaudeJobsBatchAction nu deprecation-stubs (UI-cleanup volgt in F4) - cancelClaudeJobAction blijft beschikbaar voor losse jobs Tests bijgewerkt: 11 nieuwe sprint-runs tests, claude-jobs(-batch) tests herzien naar deprecation-asserties. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ST-1246: F4 UI Start/Resume/Cancel sprint + pr_strategy dropdown - components/sprint/sprint-run-controls.tsx: knoppen Start Sprint (sprintStatus=ACTIVE), Hervat sprint (sprintStatus=FAILED) en Annuleer sprint-run (lopende run). Pre-flight blocker-modal toont blockers met directe links naar de relevante pagina's. - components/products/pr-strategy-select.tsx: dropdown SPRINT|STORY in product-settings, met optimistic update + sonner-toast op fail. - actions/products.ts: updatePrStrategyAction (eigenaar-only, demo-block). - Sprint-page: query op actieve SprintRun + tonen van controls-balk. Live cascade-visualisatie (T-634) staat als follow-up genoteerd — huidige sprint-board statusbadges volstaan voor MVP. De Solo-board "Voer uit"-knoppen zijn niet expliciet verwijderd; ze tonen nu de deprecation-error van de gestubde actions tot de Solo-flow opnieuw ontworpen wordt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
268 lines
9.2 KiB
TypeScript
268 lines
9.2 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
|
|
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
|
|
vi.mock('iron-session', () => ({
|
|
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
|
|
}))
|
|
vi.mock('@/lib/session', () => ({
|
|
sessionOptions: { cookieName: 'test', password: 'test' },
|
|
}))
|
|
vi.mock('@/lib/product-access', () => ({
|
|
productAccessFilter: vi.fn().mockReturnValue({}),
|
|
}))
|
|
vi.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
task: {
|
|
findFirst: vi.fn(),
|
|
create: vi.fn(),
|
|
update: vi.fn(),
|
|
delete: vi.fn(),
|
|
findMany: vi.fn(),
|
|
},
|
|
story: {
|
|
findFirst: vi.fn(),
|
|
findUniqueOrThrow: vi.fn(),
|
|
findMany: vi.fn(),
|
|
update: vi.fn(),
|
|
},
|
|
pbi: {
|
|
findUniqueOrThrow: vi.fn(),
|
|
findMany: vi.fn(),
|
|
update: vi.fn(),
|
|
},
|
|
sprint: {
|
|
findUniqueOrThrow: vi.fn(),
|
|
update: vi.fn(),
|
|
},
|
|
claudeJob: {
|
|
findFirst: vi.fn(),
|
|
updateMany: vi.fn(),
|
|
},
|
|
sprintRun: {
|
|
findUnique: vi.fn(),
|
|
update: vi.fn(),
|
|
},
|
|
$transaction: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
import { prisma } from '@/lib/prisma'
|
|
import { getIronSession } from 'iron-session'
|
|
import { saveTask, deleteTask } from '@/actions/tasks'
|
|
|
|
const mockPrisma = prisma as unknown as {
|
|
task: {
|
|
findFirst: ReturnType<typeof vi.fn>
|
|
create: ReturnType<typeof vi.fn>
|
|
update: ReturnType<typeof vi.fn>
|
|
delete: ReturnType<typeof vi.fn>
|
|
findMany: ReturnType<typeof vi.fn>
|
|
}
|
|
story: {
|
|
findFirst: ReturnType<typeof vi.fn>
|
|
findUniqueOrThrow: ReturnType<typeof vi.fn>
|
|
findMany: ReturnType<typeof vi.fn>
|
|
update: ReturnType<typeof vi.fn>
|
|
}
|
|
pbi: {
|
|
findUniqueOrThrow: ReturnType<typeof vi.fn>
|
|
findMany: ReturnType<typeof vi.fn>
|
|
update: ReturnType<typeof vi.fn>
|
|
}
|
|
sprint: {
|
|
findUniqueOrThrow: ReturnType<typeof vi.fn>
|
|
update: ReturnType<typeof vi.fn>
|
|
}
|
|
claudeJob: {
|
|
findFirst: ReturnType<typeof vi.fn>
|
|
updateMany: ReturnType<typeof vi.fn>
|
|
}
|
|
sprintRun: {
|
|
findUnique: ReturnType<typeof vi.fn>
|
|
update: ReturnType<typeof vi.fn>
|
|
}
|
|
$transaction: ReturnType<typeof vi.fn>
|
|
}
|
|
const mockSession = getIronSession as ReturnType<typeof vi.fn>
|
|
|
|
const VALID_INPUT = {
|
|
title: 'Test taak',
|
|
description: 'Beschrijving',
|
|
implementation_plan: 'Plan',
|
|
priority: 3,
|
|
}
|
|
|
|
const TASK = {
|
|
id: 'task-1',
|
|
title: 'Test taak',
|
|
status: 'TO_DO',
|
|
}
|
|
|
|
const STORY = { sprint_id: 'sprint-1' }
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockSession.mockResolvedValue({ userId: 'user-1', isDemo: false })
|
|
// Pass-through transaction so saveTask's $transaction wrapper executes its callback inline.
|
|
mockPrisma.$transaction.mockImplementation(async (run: (tx: typeof prisma) => Promise<unknown>) => {
|
|
return run(prisma)
|
|
})
|
|
})
|
|
|
|
// ─── saveTask ────────────────────────────────────────────────────────────────
|
|
|
|
describe('saveTask — demo-readonly (laag 2)', () => {
|
|
it('blokkeert demo-sessie', async () => {
|
|
mockSession.mockResolvedValue({ userId: 'user-1', isDemo: true })
|
|
const result = await saveTask(VALID_INPUT, { productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'demo_readonly' })
|
|
})
|
|
})
|
|
|
|
describe('saveTask — unauthenticated', () => {
|
|
it('blokkeert niet-ingelogde gebruiker', async () => {
|
|
mockSession.mockResolvedValue({ userId: undefined, isDemo: false })
|
|
const result = await saveTask(VALID_INPUT, { productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'forbidden' })
|
|
})
|
|
})
|
|
|
|
describe('saveTask — validatie', () => {
|
|
it('retourneert 422 bij lege titel', async () => {
|
|
const result = await saveTask({ ...VALID_INPUT, title: '' }, { productId: 'p-1', storyId: 's-1' })
|
|
expect(result).toMatchObject({ ok: false, code: 422, error: 'validation' })
|
|
})
|
|
|
|
it('retourneert 422 bij te lange titel (>120 tekens)', async () => {
|
|
const result = await saveTask(
|
|
{ ...VALID_INPUT, title: 'a'.repeat(121) },
|
|
{ productId: 'p-1', storyId: 's-1' },
|
|
)
|
|
expect(result).toMatchObject({ ok: false, code: 422, error: 'validation' })
|
|
})
|
|
})
|
|
|
|
describe('saveTask — edit (cross-tenant scope)', () => {
|
|
it('retourneert forbidden als task buiten scope valt', async () => {
|
|
mockPrisma.task.findFirst.mockResolvedValue(null) // out-of-scope
|
|
const result = await saveTask(VALID_INPUT, { taskId: 'task-1', productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'forbidden' })
|
|
})
|
|
|
|
it('update slaagt voor een geautoriseerde task', async () => {
|
|
mockPrisma.task.findFirst.mockResolvedValue(TASK)
|
|
mockPrisma.task.update.mockResolvedValue(TASK)
|
|
const result = await saveTask(VALID_INPUT, { taskId: 'task-1', productId: 'p-1' })
|
|
expect(result).toMatchObject({ ok: true })
|
|
// scope-filter is toegepast: findFirst bevat `story.product`
|
|
expect(mockPrisma.task.findFirst).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
where: expect.objectContaining({ id: 'task-1', story: expect.anything() }),
|
|
}),
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('saveTask — edit met status-promotie', () => {
|
|
it('promotes story naar DONE wanneer status flip naar DONE alle siblings DONE maakt', async () => {
|
|
mockPrisma.task.findFirst.mockResolvedValue({ id: 'task-1', status: 'IN_PROGRESS' })
|
|
mockPrisma.task.update.mockResolvedValue({
|
|
id: 'task-1',
|
|
title: 'Test taak',
|
|
status: 'IN_PROGRESS',
|
|
story_id: 'story-1',
|
|
implementation_plan: null,
|
|
})
|
|
// Wanneer de helper draait, gebruikt-ie tx.task.update voor de status-flip.
|
|
// Dezelfde mock vangt beide updates op; tweede return-value voor de status-update.
|
|
mockPrisma.task.update.mockResolvedValueOnce({
|
|
id: 'task-1',
|
|
title: 'Test taak',
|
|
status: 'IN_PROGRESS',
|
|
story_id: 'story-1',
|
|
implementation_plan: null,
|
|
}).mockResolvedValueOnce({
|
|
id: 'task-1',
|
|
title: 'Test taak',
|
|
status: 'DONE',
|
|
story_id: 'story-1',
|
|
implementation_plan: null,
|
|
})
|
|
mockPrisma.task.findMany.mockResolvedValue([{ status: 'DONE' }, { status: 'DONE' }])
|
|
mockPrisma.story.findUniqueOrThrow.mockResolvedValue({
|
|
id: 'story-1',
|
|
status: 'IN_SPRINT',
|
|
pbi_id: 'pbi-1',
|
|
sprint_id: null,
|
|
})
|
|
mockPrisma.story.findMany.mockResolvedValue([{ status: 'DONE' }])
|
|
mockPrisma.pbi.findUniqueOrThrow.mockResolvedValue({ id: 'pbi-1', status: 'READY' })
|
|
|
|
const result = await saveTask(
|
|
{ ...VALID_INPUT, status: 'DONE' },
|
|
{ taskId: 'task-1', productId: 'p-1' },
|
|
)
|
|
|
|
expect(result).toMatchObject({ ok: true })
|
|
expect(mockPrisma.story.update).toHaveBeenCalledWith({
|
|
where: { id: 'story-1' },
|
|
data: { status: 'DONE' },
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('saveTask — create (cross-tenant scope)', () => {
|
|
it('retourneert forbidden als story buiten scope valt', async () => {
|
|
mockPrisma.story.findFirst.mockResolvedValue(null)
|
|
const result = await saveTask(VALID_INPUT, { storyId: 's-1', productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'forbidden' })
|
|
})
|
|
|
|
it('aanmaken slaagt voor een geautoriseerde story', async () => {
|
|
mockPrisma.story.findFirst.mockResolvedValue(STORY)
|
|
mockPrisma.task.findFirst.mockResolvedValue(null) // geen vorige taak
|
|
mockPrisma.task.create.mockResolvedValue(TASK)
|
|
const result = await saveTask(VALID_INPUT, { storyId: 's-1', productId: 'p-1' })
|
|
expect(result).toMatchObject({ ok: true })
|
|
})
|
|
})
|
|
|
|
// ─── deleteTask ──────────────────────────────────────────────────────────────
|
|
|
|
describe('deleteTask — demo-readonly (laag 2)', () => {
|
|
it('blokkeert demo-sessie', async () => {
|
|
mockSession.mockResolvedValue({ userId: 'user-1', isDemo: true })
|
|
const result = await deleteTask('task-1', { productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'demo_readonly' })
|
|
})
|
|
})
|
|
|
|
describe('deleteTask — unauthenticated', () => {
|
|
it('blokkeert niet-ingelogde gebruiker', async () => {
|
|
mockSession.mockResolvedValue({ userId: undefined, isDemo: false })
|
|
const result = await deleteTask('task-1', { productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'forbidden' })
|
|
})
|
|
})
|
|
|
|
describe('deleteTask — cross-tenant scope', () => {
|
|
it('retourneert forbidden als task buiten scope valt', async () => {
|
|
mockPrisma.task.findFirst.mockResolvedValue(null)
|
|
const result = await deleteTask('task-1', { productId: 'p-1' })
|
|
expect(result).toEqual({ ok: false, code: 403, error: 'forbidden' })
|
|
})
|
|
|
|
it('verwijderen slaagt voor een geautoriseerde task', async () => {
|
|
mockPrisma.task.findFirst.mockResolvedValue(TASK)
|
|
mockPrisma.task.delete.mockResolvedValue(TASK)
|
|
const result = await deleteTask('task-1', { productId: 'p-1' })
|
|
expect(result).toEqual({ ok: true })
|
|
// scope-filter toegepast
|
|
expect(mockPrisma.task.findFirst).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
where: expect.objectContaining({ id: 'task-1', story: expect.anything() }),
|
|
}),
|
|
)
|
|
})
|
|
})
|