Sprint: Stories en taken krijgen één voorspelbare volgorde gekoppeld aan hun code; drag-and-drop herordening voor stories/taken verdwijnt, priority wordt puur label. (#201)
* feat(code): add parseCodeNumber helper to lib/code.ts
Pure helper that extracts the trailing numeric sequence from a code string
(ST-007 → 7, T-42 → 42). Non-conforming codes fall back to Number.MAX_SAFE_INTEGER
so they sort to the end. Includes 5 unit tests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(tasks): add code field to BacklogTask type and all task selects
Adds `code: string | null` to BacklogTask interface and includes it in
all Prisma task.findMany selects (backlog API, stories tasks API, page
hydration routes). Updates coerceTaskPayload and test fixtures to match.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(sort-order): derive story/task sort_order from parseCodeNumber(code)
All create paths (createStoryAction, saveTask, createTaskAction,
materializeIdeaPlanAction) and code-edit paths (updateStoryAction, saveTask
update) now set sort_order = parseCodeNumber(code) instead of last+1.
Removes stale last-record queries from create paths.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(sort-order): decouple sprint membership actions from sort_order
createSprintAction and addStoryToSprintAction no longer write sort_order
when adding stories to a sprint. sort_order is derived from code via
parseCodeNumber, so membership should only set sprint_id + status.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(ordering): remove priority from all story/task orderBy
Story- en taak-ordering is nu puur sort_order asc (created_at als
tiebreaker). PBI-ordering (priority + sort_order) blijft ongewijzigd.
Gewijzigd: backlog/route, pbis/stories/route, claude-context/route,
next-story/route, workspace/route, tasks/route, sprint-runs (query +
in-memory sort), solo-workspace-server, page.tsx (app + mobile + sprint),
store compareStory, actions/sprints story-query, next-story test.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(dnd): remove drag-and-drop reorder for stories and tasks
- Remove reorderStoriesAction, reorderTasksAction, reorderSprintStoriesAction
- Delete REST route app/api/stories/[id]/tasks/reorder/route.ts
- Remove DnD from backlog story-panel and task-panel (flat list)
- Remove reorder-within-sprint branch from sprint-board-client handleDragEnd
- Switch SortableSprintRow to plain SprintRow using useDraggable (membership drag kept)
- Remove all DnD from task-list (status toggle + edit kept)
- Remove story-order/task-order/sprint-story-order/sprint-task-order mutation types and store handlers
- Remove related tests for deleted reorder route; fix sprint store tests
* feat(backlog): toon code-badge op backlog-taakkaarten
Geeft code={task.code} door aan <BacklogCard> in TaskCard (task-panel.tsx).
BacklogCard rendert de CodeBadge al conditionally — alleen de prop ontbrak.
* feat(migration): backfill story/task sort_order from code numeric suffix
One-time Prisma migration that sets sort_order = trailing numeric part
of code for all existing stories and tasks, consistent with
parseCodeNumber (fallback = Number.MAX_SAFE_INTEGER for non-conforming
codes). PBIs are intentionally excluded.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs+tests(sort-order): update for code-binding order on stories/tasks
- Rewrite docs/patterns/sort-order.md: float-insertion PBI only; story/task
sort_order = parseCodeNumber(code), never drag/membership mutated
- Update plan-to-pbi-flow.md: sort_order auto, sprint_id param, priority=label
- Update make-plan.md: priority=label, array order = execution order
- Update rest-contract.md: fix sprint-tasks ordering, remove reorder endpoint
- Add ADR-0011: code is bindende volgordesleutel voor stories/taken
- Regenerate docs/INDEX.md via npm run docs
- Remove reorderStoriesAction/reorderTasksAction mocks from backlog tests
- Remove dnd-kit mocks from task-panel test (panel no longer uses dnd)
- Extend materializeIdeaPlanAction test: assert sort_order=parseCodeNumber(code)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b6249a41c0
commit
ff22196714
43 changed files with 296 additions and 951 deletions
|
|
@ -95,7 +95,7 @@ describe('GET /api/products/:id/next-story', () => {
|
|||
expect(data.tasks[0]).toMatchObject({ id: 'task-1', status: 'todo' })
|
||||
})
|
||||
|
||||
it('queries story ordered by priority then sort_order', async () => {
|
||||
it('queries story ordered by sort_order only', async () => {
|
||||
mockPrisma.sprint.findFirst.mockResolvedValue(SPRINT)
|
||||
mockPrisma.story.findFirst.mockResolvedValue(STORY)
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ describe('GET /api/products/:id/next-story', () => {
|
|||
|
||||
expect(mockPrisma.story.findFirst).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }],
|
||||
orderBy: [{ sort_order: 'asc' }],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,111 +0,0 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
vi.mock('@/lib/prisma', () => ({
|
||||
prisma: {
|
||||
story: {
|
||||
findFirst: vi.fn(),
|
||||
},
|
||||
task: {
|
||||
update: vi.fn(),
|
||||
},
|
||||
$transaction: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/api-auth', () => ({
|
||||
authenticateApiRequest: vi.fn(),
|
||||
}))
|
||||
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { authenticateApiRequest } from '@/lib/api-auth'
|
||||
import { PATCH as patchReorder } from '@/app/api/stories/[id]/tasks/reorder/route'
|
||||
|
||||
const mockPrisma = prisma as unknown as {
|
||||
story: { findFirst: ReturnType<typeof vi.fn> }
|
||||
task: { update: ReturnType<typeof vi.fn> }
|
||||
$transaction: ReturnType<typeof vi.fn>
|
||||
}
|
||||
const mockAuth = authenticateApiRequest as ReturnType<typeof vi.fn>
|
||||
|
||||
function makeStory(taskIds: string[]) {
|
||||
return {
|
||||
id: 'story-1',
|
||||
product_id: 'prod-1',
|
||||
tasks: taskIds.map(id => ({ id })),
|
||||
}
|
||||
}
|
||||
|
||||
function makeRequest(body: unknown, storyId = 'story-1'): [Request, { params: Promise<{ id: string }> }] {
|
||||
return [
|
||||
new Request(`http://localhost/api/stories/${storyId}/tasks/reorder`, {
|
||||
method: 'PATCH',
|
||||
headers: { Authorization: 'Bearer test-token', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
}),
|
||||
{ params: Promise.resolve({ id: storyId }) },
|
||||
]
|
||||
}
|
||||
|
||||
describe('PATCH /api/stories/:id/tasks/reorder', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockAuth.mockResolvedValue({ userId: 'user-1', isDemo: false })
|
||||
mockPrisma.$transaction.mockResolvedValue([])
|
||||
mockPrisma.task.update.mockResolvedValue({ id: 'task-1', sort_order: 1 })
|
||||
})
|
||||
|
||||
// TC-RO-06 — body validation fires before story lookup
|
||||
it('returns 422 when task_ids is an empty array', async () => {
|
||||
const res = await patchReorder(...makeRequest({ task_ids: [] }))
|
||||
expect(res.status).toBe(422)
|
||||
expect(mockPrisma.story.findFirst).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
// TC-RO-07
|
||||
it('returns 422 when task_ids is not an array', async () => {
|
||||
const res = await patchReorder(...makeRequest({ task_ids: 'task-1' }))
|
||||
expect(res.status).toBe(422)
|
||||
expect(mockPrisma.story.findFirst).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('returns 422 when task_ids is missing entirely', async () => {
|
||||
const res = await patchReorder(...makeRequest({}))
|
||||
expect(res.status).toBe(422)
|
||||
})
|
||||
|
||||
// TC-RO-08
|
||||
it('returns 422 when task_ids contains an ID not belonging to the story', async () => {
|
||||
mockPrisma.story.findFirst.mockResolvedValue(makeStory(['task-1', 'task-2']))
|
||||
|
||||
const res = await patchReorder(...makeRequest({ task_ids: ['task-1', 'task-from-other-story'] }))
|
||||
const data = await res.json()
|
||||
|
||||
expect(res.status).toBe(422)
|
||||
expect(data.error).toContain('task-from-other-story')
|
||||
})
|
||||
|
||||
// TC-RO-09
|
||||
it('reorders tasks and returns 200 with success: true', async () => {
|
||||
mockPrisma.story.findFirst.mockResolvedValue(makeStory(['task-1', 'task-2', 'task-3']))
|
||||
|
||||
const res = await patchReorder(...makeRequest({ task_ids: ['task-3', 'task-1', 'task-2'] }))
|
||||
const data = await res.json()
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(data).toEqual({ success: true })
|
||||
expect(mockPrisma.$transaction).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('updates each task with its new sort_order index', async () => {
|
||||
mockPrisma.story.findFirst.mockResolvedValue(makeStory(['task-1', 'task-2']))
|
||||
|
||||
await patchReorder(...makeRequest({ task_ids: ['task-2', 'task-1'] }))
|
||||
|
||||
expect(mockPrisma.task.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ where: { id: 'task-2' }, data: { sort_order: 1 } })
|
||||
)
|
||||
expect(mockPrisma.task.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ where: { id: 'task-1' }, data: { sort_order: 2 } })
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
@ -54,7 +54,6 @@ import { authenticateApiRequest } from '@/lib/api-auth'
|
|||
import { GET as getProducts } from '@/app/api/products/route'
|
||||
import { GET as getNextStory } from '@/app/api/products/[id]/next-story/route'
|
||||
import { GET as getSprintTasks } from '@/app/api/sprints/[id]/tasks/route'
|
||||
import { PATCH as patchReorder } from '@/app/api/stories/[id]/tasks/reorder/route'
|
||||
import { POST as postStoryLog } from '@/app/api/stories/[id]/log/route'
|
||||
import { PATCH as patchTask } from '@/app/api/tasks/[id]/route'
|
||||
|
||||
|
|
@ -276,56 +275,6 @@ describe('GET /api/sprints/:id/tasks', () => {
|
|||
})
|
||||
})
|
||||
|
||||
// ─── PATCH /api/stories/:id/tasks/reorder ────────────────────────────────────
|
||||
|
||||
describe('PATCH /api/stories/:id/tasks/reorder', () => {
|
||||
const VALID_BODY = { task_ids: ['task-x'] }
|
||||
|
||||
// TC-RO-01
|
||||
it('returns 401 when no valid token provided', async () => {
|
||||
mockAuth.mockResolvedValue(UNAUTHORIZED)
|
||||
const res = await patchReorder(
|
||||
makePatch('http://localhost/api/stories/story-1/tasks/reorder', VALID_BODY),
|
||||
routeCtx('story-1')
|
||||
)
|
||||
expect(res.status).toBe(401)
|
||||
})
|
||||
|
||||
// TC-RO-03
|
||||
it('returns 403 for demo users', async () => {
|
||||
mockAuth.mockResolvedValue(DEMO_AUTH)
|
||||
const res = await patchReorder(
|
||||
makePatch('http://localhost/api/stories/story-1/tasks/reorder', VALID_BODY),
|
||||
routeCtx('story-1')
|
||||
)
|
||||
expect(res.status).toBe(403)
|
||||
const data = await res.json()
|
||||
expect(data.error).toBe('Niet beschikbaar in demo-modus')
|
||||
})
|
||||
|
||||
// TC-RO-04 / TC-RO-05
|
||||
it('returns 404 when story is not accessible to the authenticated user', async () => {
|
||||
mockAuth.mockResolvedValue(USER_2_AUTH)
|
||||
mockPrisma.story.findFirst.mockResolvedValue(null)
|
||||
|
||||
const res = await patchReorder(
|
||||
makePatch('http://localhost/api/stories/story-1/tasks/reorder', VALID_BODY),
|
||||
routeCtx('story-1')
|
||||
)
|
||||
expect(res.status).toBe(404)
|
||||
expect(mockPrisma.story.findFirst).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({
|
||||
id: 'story-1',
|
||||
product: expect.objectContaining({
|
||||
OR: expect.arrayContaining([{ user_id: 'user-2' }]),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
// ─── POST /api/stories/:id/log ────────────────────────────────────────────────
|
||||
|
||||
describe('POST /api/stories/:id/log', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue