3.0 Tests primero
pgTAP: 005_tasks_rls.sql (5 — completion CHECK), 006_notes_trash_purge.sql (4 — purge SQL inline + pin/archive CHECK)
Vitest RLS: rls-tasks.test.ts (14), rls-notes.test.ts (15)
Playwright: tasks.test.ts (3), notes.test.ts (4)
3.1 Tareas
Migration 008_tasks.sql: task_lists + tasks + task_list_collective_id() helper
CHECK constraint: is_completed ⇔ completed_by ⇔ completed_at
RLS by role + cross-collective isolation
Store apps/web/src/lib/stores/tasks.ts (optimistic CRUD + reorder)
/tasks overview (grid + sticky create input + 5s polling)
/tasks/[id] detail with svelte-dnd-action reorder, flip animation,
inline edit (dblclick), "Completed by …" attribution via lazy-loaded
collective_members
3.2 Notas
Migration 009_notes.sql: notes + note_color enum (8) + pin/archive CHECK
+ 7d trash window in RLS + fn_notes_touch trigger + pg_cron purge job
Store apps/web/src/lib/stores/notes.ts (CRUD + pin/archive/trash/duplicate)
/notes board (pinned section testid notes-pinned + 30s polling)
/notes/[id] editor (title + textarea, 500ms debounced autosave,
color picker, pin/archive/duplicate/trash actions)
/notes/archive (restore + send to trash)
/notes/trash (restore + permanent delete)
3.Z Verification
just test-all → 148 verdes, 2 skipped:
25 pgTAP (was 16, +9)
88 Vitest integration (was 59, +29; 2 presence skipped)
6 Vitest unit (unchanged)
29 Playwright (was 22, +3 tasks +4 notes)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
78 lines
3.1 KiB
PL/PgSQL
78 lines
3.1 KiB
PL/PgSQL
-- pgTAP: tasks completion-consistency CHECK constraint — Fase 3
|
|
-- Run with: psql -U postgres -d postgres -f supabase/tests/005_tasks_rls.sql
|
|
--
|
|
-- The completion CHECK constraint is the SQL invariant that backs the UI:
|
|
-- completed_at NOT NULL ⇔ completed_by NOT NULL ⇔ is_completed = true
|
|
|
|
CREATE EXTENSION IF NOT EXISTS pgtap;
|
|
|
|
BEGIN;
|
|
SELECT plan(5);
|
|
|
|
-- Reuse the seeded collective + admin (Ana) to satisfy FKs without RLS gymnastics.
|
|
DO $$
|
|
DECLARE
|
|
v_list_id uuid;
|
|
v_task_id uuid;
|
|
BEGIN
|
|
INSERT INTO public.task_lists (collective_id, name, created_by)
|
|
VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'pgtap list', '11111111-1111-1111-1111-111111111111')
|
|
RETURNING id INTO v_list_id;
|
|
|
|
-- Stash for assertions
|
|
PERFORM set_config('pgtap.list_id', v_list_id::text, false);
|
|
END $$;
|
|
|
|
-- T-PG-01: insert with default (is_completed=false, no completed_*) succeeds
|
|
SELECT lives_ok(
|
|
$$ INSERT INTO public.tasks (list_id, title, created_by)
|
|
VALUES (current_setting('pgtap.list_id')::uuid, 'pgtap incomplete task',
|
|
'11111111-1111-1111-1111-111111111111') $$,
|
|
'T-PG-01: incomplete task can be inserted with NULL completed_by/completed_at'
|
|
);
|
|
|
|
-- T-PG-02: insert is_completed=true + completed_by + completed_at succeeds
|
|
SELECT lives_ok(
|
|
$$ INSERT INTO public.tasks (list_id, title, is_completed, completed_by, completed_at, created_by)
|
|
VALUES (current_setting('pgtap.list_id')::uuid, 'pgtap completed task',
|
|
true, '11111111-1111-1111-1111-111111111111', now(),
|
|
'11111111-1111-1111-1111-111111111111') $$,
|
|
'T-PG-02: complete task with completed_by + completed_at succeeds'
|
|
);
|
|
|
|
-- T-PG-03: is_completed=true with NULL completed_by violates CHECK
|
|
SELECT throws_ok(
|
|
$$ INSERT INTO public.tasks (list_id, title, is_completed, completed_by, completed_at, created_by)
|
|
VALUES (current_setting('pgtap.list_id')::uuid, 'pgtap broken',
|
|
true, NULL, now(),
|
|
'11111111-1111-1111-1111-111111111111') $$,
|
|
'23514',
|
|
NULL,
|
|
'T-PG-03: is_completed=true without completed_by raises CHECK violation (23514)'
|
|
);
|
|
|
|
-- T-PG-04: is_completed=false with completed_by set violates CHECK
|
|
SELECT throws_ok(
|
|
$$ INSERT INTO public.tasks (list_id, title, is_completed, completed_by, completed_at, created_by)
|
|
VALUES (current_setting('pgtap.list_id')::uuid, 'pgtap broken-2',
|
|
false, '11111111-1111-1111-1111-111111111111', now(),
|
|
'11111111-1111-1111-1111-111111111111') $$,
|
|
'23514',
|
|
NULL,
|
|
'T-PG-04: is_completed=false with completed_by set raises CHECK violation'
|
|
);
|
|
|
|
-- T-PG-05: is_completed=true with completed_by but NULL completed_at violates CHECK
|
|
SELECT throws_ok(
|
|
$$ INSERT INTO public.tasks (list_id, title, is_completed, completed_by, completed_at, created_by)
|
|
VALUES (current_setting('pgtap.list_id')::uuid, 'pgtap broken-3',
|
|
true, '11111111-1111-1111-1111-111111111111', NULL,
|
|
'11111111-1111-1111-1111-111111111111') $$,
|
|
'23514',
|
|
NULL,
|
|
'T-PG-05: is_completed=true with NULL completed_at raises CHECK violation'
|
|
);
|
|
|
|
SELECT * FROM finish();
|
|
ROLLBACK;
|