Files
project-manager/tests/CardStatusTest.php
T
aneurinandClaude Sonnet 5 4ee0f24078 Make the inbox global instead of per-project
A card either sits in its owner's inbox (project_id AND status_id both NULL)
or belongs to exactly one project with a status in it (both set) -- enforced
by a CHECK constraint, never one without the other. The inbox is global to a
user now, not per-project: cards can move from a project into the inbox and
back into any status column of any project.

Backend
- migrations/009: rebuilds `cards` (SQLite can't relax NOT NULL / add a CHECK
  in place) with a nullable project_id, a new owner_id (cards need direct
  ownership once they can have no project), and the CHECK constraint. Cards
  that had no status (the old per-project inbox) move to the new global inbox.
  status_id's FK is now ON DELETE RESTRICT, not SET NULL -- nulling it alone
  would violate the invariant, and there's no status-delete endpoint anyway.
- CardRepository: "column" is now (owner_id, project_id, status_id); every
  method that dealt with a project's columns is generalised to also cover the
  inbox and cross-project moves (orderColumn, idsInColumn, repack, ...).
- CardController/routes: single-card and ordering routes move to global,
  since a card may have no project to nest them under --
  GET/PATCH/DELETE /api/cards/{id}, PUT /api/cards/order (body now takes
  project_id + status_id, both null for the inbox). New GET/POST
  /api/inbox/cards. PATCH no longer accepts status_id -- moving a card, in or
  out of a project, is exclusively PUT /api/cards/order now. A card created
  directly in a project (POST /api/projects/{id}/cards) lands in its first
  status, since a project card can't have no status.
- Tests: ProjectTest/CardStatusTest updated for the new routes; CardOrderTest
  rewritten with full inbox/cross-project coverage. 57 tests pass.

Frontend
- New stores/inbox.ts (the global inbox) and lib/cardOrder.ts (the shared
  PUT /api/cards/order call, used by both the sidebar and a project's board).
- AppSidebar: an Inbox section under the project list -- a vuedraggable list
  in the same "kanban" drag group as every project's kanban columns, so a
  card drags straight from the sidebar into whichever project is open, or
  back out. (The empty-inbox state needed a real bugfix: it wasn't rendering
  a <draggable> at all, so there was nowhere to drop a card back into an
  empty inbox.) A drop reloads the inbox and, if a project is open, its cards.
- ProjectView's kanban board drops its synthetic Inbox column -- just the
  real statuses now.
- DashboardView simplified to a plain grid of project tiles (name + card
  count); its per-project "New" section is gone, since a project card can no
  longer have no status.
- stores/cards.ts: patch/remove move to the global /api/cards/{id} routes.

Verified end-to-end against the rebuilt container (existing per-project-inbox
cards correctly migrated to the global inbox, 0 invariant violations) and the
dev server via headless Chrome: sidebar inbox -> project A "To do" -> back to
inbox -> project B "Done", full journey confirmed via the API at each step.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:22:33 +01:00

114 lines
4.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests;
use PDOException;
final class CardStatusTest extends ApiTestCase
{
/** Create a project and return its id. */
private function newProject(array $auth, string $title = 'Board'): int
{
return $this->decode(
$this->request('POST', '/api/projects', ['title' => $title], $auth),
)['project']['id'];
}
/** @param array<string, string> $auth @return array<int, mixed> */
private function statuses(int $projectId, array $auth): array
{
return $this->decode(
$this->request('GET', "/api/projects/{$projectId}/statuses", null, $auth),
)['statuses'];
}
public function test_statuses_require_authentication(): void
{
$projectId = $this->newProject($this->authHeader());
self::assertSame(401, $this->request('GET', "/api/projects/{$projectId}/statuses")->getStatusCode());
}
public function test_new_projects_are_seeded_with_the_default_statuses(): void
{
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$statuses = $this->statuses($projectId, $auth);
self::assertSame(['To do', 'Doing', 'Done'], array_column($statuses, 'name'));
self::assertSame([0, 1, 2], array_column($statuses, 'position'));
self::assertSame([$projectId, $projectId, $projectId], array_column($statuses, 'project_id'));
}
public function test_each_project_gets_its_own_status_rows(): void
{
$auth = $this->authHeader();
$first = $this->newProject($auth, 'One');
$second = $this->newProject($auth, 'Two');
$firstIds = array_column($this->statuses($first, $auth), 'id');
$secondIds = array_column($this->statuses($second, $auth), 'id');
self::assertSame([], array_intersect($firstIds, $secondIds));
}
public function test_statuses_are_only_visible_to_the_project_owner(): void
{
$owner = $this->authHeader('owner@example.com');
$other = $this->authHeader('other@example.com');
$projectId = $this->newProject($owner, 'Private');
self::assertSame(200, $this->request('GET', "/api/projects/{$projectId}/statuses", null, $owner)->getStatusCode());
self::assertSame(404, $this->request('GET', "/api/projects/{$projectId}/statuses", null, $other)->getStatusCode());
}
public function test_a_card_created_directly_in_a_project_starts_in_its_first_status(): void
{
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$firstStatus = $this->statuses($projectId, $auth)[0];
$card = $this->decode(
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'First'], $auth),
)['card'];
self::assertSame($firstStatus['id'], $card['status_id']);
self::assertSame('To do', $card['status']['name']);
self::assertSame($projectId, $card['project_id']);
}
public function test_a_referenced_status_cannot_be_deleted(): void
{
// There's no delete-status endpoint; this exercises the FK directly.
// A card with a project must have a status (the CHECK constraint), so
// the FK is ON DELETE RESTRICT rather than SET NULL.
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$statusId = $this->statuses($projectId, $auth)[0]['id'];
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth);
$this->db()->exec('PRAGMA foreign_keys = ON');
$this->expectException(PDOException::class);
$this->db()->prepare('DELETE FROM card_statuses WHERE id = ?')->execute([$statusId]);
}
public function test_deleting_a_project_cascades_to_its_statuses(): void
{
$auth = $this->authHeader();
$projectId = $this->newProject($auth, 'Temp');
$count = fn (): int => (int) $this->db()
->query("SELECT COUNT(*) FROM card_statuses WHERE project_id = {$projectId}")
->fetchColumn();
self::assertSame(3, $count());
$this->request('DELETE', "/api/projects/{$projectId}", null, $auth);
self::assertSame(0, $count());
}
}