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>
185 lines
7.6 KiB
PHP
185 lines
7.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests;
|
|
|
|
final class ProjectTest extends ApiTestCase
|
|
{
|
|
public function test_projects_require_authentication(): void
|
|
{
|
|
self::assertSame(401, $this->request('GET', '/api/projects')->getStatusCode());
|
|
}
|
|
|
|
public function test_create_and_list_projects(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
|
|
$created = $this->request('POST', '/api/projects', [
|
|
'title' => ' Groceries ',
|
|
'description' => 'Weekly shop',
|
|
], $auth);
|
|
|
|
self::assertSame(201, $created->getStatusCode());
|
|
$project = $this->decode($created)['project'];
|
|
self::assertSame('Groceries', $project['title']);
|
|
self::assertSame('Weekly shop', $project['description']);
|
|
self::assertSame(0, $project['card_count']);
|
|
|
|
$index = $this->decode($this->request('GET', '/api/projects', null, $auth));
|
|
self::assertCount(1, $index['projects']);
|
|
self::assertSame($project['id'], $index['projects'][0]['id']);
|
|
}
|
|
|
|
public function test_projects_come_back_alphabetically(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
|
|
foreach (['Banana', 'apple', 'Cherry'] as $title) {
|
|
$this->request('POST', '/api/projects', ['title' => $title], $auth);
|
|
}
|
|
|
|
$titles = array_column($this->decode($this->request('GET', '/api/projects', null, $auth))['projects'], 'title');
|
|
self::assertSame(['apple', 'Banana', 'Cherry'], $titles);
|
|
}
|
|
|
|
public function test_an_owner_cannot_exceed_100_projects(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
|
|
for ($i = 1; $i <= 100; $i++) {
|
|
$response = $this->request('POST', '/api/projects', ['title' => "Project {$i}"], $auth);
|
|
self::assertSame(201, $response->getStatusCode(), "project {$i} should be created");
|
|
}
|
|
|
|
$overflow = $this->request('POST', '/api/projects', ['title' => 'One too many'], $auth);
|
|
self::assertSame(409, $overflow->getStatusCode());
|
|
self::assertStringContainsString('100', $this->decode($overflow)['error']['message']);
|
|
|
|
// The cap is per owner, so a different user is unaffected.
|
|
$other = $this->authHeader('roomy@example.com');
|
|
self::assertSame(201, $this->request('POST', '/api/projects', ['title' => 'Fine'], $other)->getStatusCode());
|
|
}
|
|
|
|
public function test_project_creation_validates_title(): void
|
|
{
|
|
$response = $this->request('POST', '/api/projects', ['description' => 'no title'], $this->authHeader());
|
|
|
|
self::assertSame(422, $response->getStatusCode());
|
|
self::assertArrayHasKey('title', $this->decode($response)['error']['details']);
|
|
}
|
|
|
|
public function test_a_project_is_only_visible_to_its_owner(): void
|
|
{
|
|
$owner = $this->authHeader('owner@example.com');
|
|
$other = $this->authHeader('other@example.com');
|
|
|
|
$projectId = $this->decode(
|
|
$this->request('POST', '/api/projects', ['title' => 'Private'], $owner),
|
|
)['project']['id'];
|
|
|
|
self::assertSame(200, $this->request('GET', "/api/projects/{$projectId}", null, $owner)->getStatusCode());
|
|
self::assertSame(404, $this->request('GET', "/api/projects/{$projectId}", null, $other)->getStatusCode());
|
|
self::assertSame(404, $this->request('PATCH', "/api/projects/{$projectId}", ['title' => 'x'], $other)->getStatusCode());
|
|
self::assertSame(404, $this->request('DELETE', "/api/projects/{$projectId}", null, $other)->getStatusCode());
|
|
}
|
|
|
|
public function test_update_and_delete_project(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
$projectId = $this->decode(
|
|
$this->request('POST', '/api/projects', ['title' => 'Draft'], $auth),
|
|
)['project']['id'];
|
|
|
|
$updated = $this->decode(
|
|
$this->request('PATCH', "/api/projects/{$projectId}", ['title' => 'Final'], $auth),
|
|
)['project'];
|
|
self::assertSame('Final', $updated['title']);
|
|
|
|
self::assertSame(204, $this->request('DELETE', "/api/projects/{$projectId}", null, $auth)->getStatusCode());
|
|
self::assertSame(404, $this->request('GET', "/api/projects/{$projectId}", null, $auth)->getStatusCode());
|
|
}
|
|
|
|
public function test_cards_land_in_the_first_status_and_track_completion(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
$projectId = $this->decode(
|
|
$this->request('POST', '/api/projects', ['title' => 'Chores'], $auth),
|
|
)['project']['id'];
|
|
$firstStatus = $this->decode(
|
|
$this->request('GET', "/api/projects/{$projectId}/statuses", null, $auth),
|
|
)['statuses'][0];
|
|
|
|
foreach (['Wash up', 'Hoover', 'Bins'] as $text) {
|
|
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => $text], $auth);
|
|
}
|
|
|
|
$cards = $this->decode($this->request('GET', "/api/projects/{$projectId}/cards", null, $auth))['cards'];
|
|
self::assertSame(['Wash up', 'Hoover', 'Bins'], array_column($cards, 'text'));
|
|
self::assertSame([0, 1, 2], array_column($cards, 'position'));
|
|
self::assertSame([$firstStatus['id'], $firstStatus['id'], $firstStatus['id']], array_column($cards, 'status_id'));
|
|
self::assertFalse($cards[0]['complete']);
|
|
|
|
$done = $this->decode(
|
|
$this->request('PATCH', "/api/cards/{$cards[0]['id']}", ['complete' => true], $auth),
|
|
)['card'];
|
|
self::assertTrue($done['complete']);
|
|
|
|
$project = $this->decode($this->request('GET', "/api/projects/{$projectId}", null, $auth))['project'];
|
|
self::assertSame(3, $project['card_count']);
|
|
self::assertSame(1, $project['completed_count']);
|
|
}
|
|
|
|
public function test_card_creation_accepts_explicit_position_and_validates_text(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
$projectId = $this->decode(
|
|
$this->request('POST', '/api/projects', ['title' => 'P'], $auth),
|
|
)['project']['id'];
|
|
|
|
$card = $this->decode(
|
|
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'Pinned', 'position' => 5], $auth),
|
|
)['card'];
|
|
self::assertSame(5, $card['position']);
|
|
|
|
$bad = $this->request('POST', "/api/projects/{$projectId}/cards", ['text' => ' '], $auth);
|
|
self::assertSame(422, $bad->getStatusCode());
|
|
self::assertArrayHasKey('text', $this->decode($bad)['error']['details']);
|
|
}
|
|
|
|
public function test_deleting_a_project_cascades_to_its_cards(): void
|
|
{
|
|
$auth = $this->authHeader();
|
|
$projectId = $this->decode(
|
|
$this->request('POST', '/api/projects', ['title' => 'Temp'], $auth),
|
|
)['project']['id'];
|
|
$cardId = $this->decode(
|
|
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth),
|
|
)['card']['id'];
|
|
|
|
$this->request('DELETE', "/api/projects/{$projectId}", null, $auth);
|
|
|
|
// The card went with its project.
|
|
self::assertSame(404, $this->request('GET', "/api/cards/{$cardId}", null, $auth)->getStatusCode());
|
|
}
|
|
|
|
public function test_cards_under_another_users_project_are_not_reachable(): void
|
|
{
|
|
$owner = $this->authHeader('owner2@example.com');
|
|
$other = $this->authHeader('other2@example.com');
|
|
|
|
$projectId = $this->decode(
|
|
$this->request('POST', '/api/projects', ['title' => 'Mine'], $owner),
|
|
)['project']['id'];
|
|
|
|
self::assertSame(
|
|
404,
|
|
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'sneaky'], $other)->getStatusCode(),
|
|
);
|
|
self::assertSame(
|
|
404,
|
|
$this->request('GET', "/api/projects/{$projectId}/cards", null, $other)->getStatusCode(),
|
|
);
|
|
}
|
|
}
|