@davoodmehraban89 / LifeMate / commits / 975e952
Fork 0

LifeMate — Personal, Family & Learning Companion

test: add phase 3 database authorization matrix

davoodmehraban89 committed Oct 5, 2026 at 15:11 UTC 975e95246195644c75301cb57227937780c07181
1 file changed +45
backend/tests/phase3_schema_test.sql new
+45
@@ -0,0 +1,45 @@
1 +\set ON_ERROR_STOP on
2 +begin;
3 +
4 +insert into app_user(id,identity_subject,email_normalized) values
5 +('30000000-0000-0000-0000-000000000001','p3-parent','p3-parent@example.test'),
6 +('30000000-0000-0000-0000-000000000002','p3-teen','p3-teen@example.test'),
7 +('30000000-0000-0000-0000-000000000003','p3-other','p3-other@example.test');
8 +
9 +insert into family_workspace(id,name,created_by) values
10 +('31000000-0000-0000-0000-000000000001','P3 Family','30000000-0000-0000-0000-000000000001');
11 +
12 +insert into family_membership(family_id,user_id,role,is_admin) values
13 +('31000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000001','parent_guardian',true),
14 +('31000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000002','teen_minor',false);
15 +
16 +insert into guardian_relationship(family_id,guardian_user_id,minor_user_id) values
17 +('31000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000002');
18 +
19 +insert into plan_item(id,owner_user_id,family_id,kind,title,visibility,due_at) values
20 +('32000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000002','31000000-0000-0000-0000-000000000001','task','Private teen','private',now()+interval '1 day'),
21 +('32000000-0000-0000-0000-000000000002','30000000-0000-0000-0000-000000000002','31000000-0000-0000-0000-000000000001','assignment','Guardian item','parent_guardian',now()+interval '1 day'),
22 +('32000000-0000-0000-0000-000000000003','30000000-0000-0000-0000-000000000001','31000000-0000-0000-0000-000000000001','event','Family event','family',now()+interval '1 day');
23 +
24 +do $$
25 +begin
26 + if not can_view_plan_item('30000000-0000-0000-0000-000000000002','32000000-0000-0000-0000-000000000001') then raise exception 'owner must see private item'; end if;
27 + if can_view_plan_item('30000000-0000-0000-0000-000000000001','32000000-0000-0000-0000-000000000001') then raise exception 'guardian must not see private item'; end if;
28 + if not can_view_plan_item('30000000-0000-0000-0000-000000000001','32000000-0000-0000-0000-000000000002') then raise exception 'guardian must see guardian item'; end if;
29 + if can_view_plan_item('30000000-0000-0000-0000-000000000003','32000000-0000-0000-0000-000000000002') then raise exception 'outsider must not see guardian item'; end if;
30 + if not can_view_plan_item('30000000-0000-0000-0000-000000000002','32000000-0000-0000-0000-000000000003') then raise exception 'family member must see family event'; end if;
31 + if not can_view_student_academic('30000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000002') then raise exception 'guardian academic access missing'; end if;
32 + if can_view_student_academic('30000000-0000-0000-0000-000000000003','30000000-0000-0000-0000-000000000002') then raise exception 'outsider academic access must fail'; end if;
33 +end $$;
34 +
35 +update family_membership set ended_at=now()
36 +where family_id='31000000-0000-0000-0000-000000000001'
37 +and user_id='30000000-0000-0000-0000-000000000001';
38 +
39 +do $$
40 +begin
41 + if can_view_plan_item('30000000-0000-0000-0000-000000000001','32000000-0000-0000-0000-000000000002') then raise exception 'removed guardian must lose plan access'; end if;
42 + if can_view_student_academic('30000000-0000-0000-0000-000000000001','30000000-0000-0000-0000-000000000002') then raise exception 'removed guardian must lose academic access'; end if;
43 +end $$;
44 +
45 +rollback;