LifeMate — Personal, Family & Learning Companion
test(qa): preserve rollback-only Supabase family, study and denial SQL receipt
davoodmehraban89 committed
Oct 15, 2026 at 01:28 UTC
ca302ea07723e458de5069cf557a72cbeb41629a
1 file changed
+60
backend/tests/supabase_qa_guardian_acceptance.sql
new
+60
@@ -0,0 +1,60 @@
1
+-- Synthetic-only DB acceptance. Execute ONLY against isolated Supabase project
2
+-- LifeGuide-QA / iqkrwxeprxvdiubdfcrb. Never run against Finora or any real user DB.
3
+-- All writes and relationship changes are intentionally ROLLED BACK.
4
+begin;
5
+set local search_path=lifeguide_qa,extensions,pg_catalog;
6
+do $qa_guardian_test$
7
+declare
8
+ parent_a uuid := gen_random_uuid();
9
+ parent_b uuid := gen_random_uuid();
10
+ child_a uuid := gen_random_uuid();
11
+ outsider uuid := gen_random_uuid();
12
+ fam uuid := gen_random_uuid();
13
+ shared_task uuid := gen_random_uuid();
14
+ private_task uuid := gen_random_uuid();
15
+ study_id uuid := gen_random_uuid();
16
+ seconds int;
17
+begin
18
+ insert into lifeguide_qa.app_user(id,identity_subject,email_normalized) values
19
+ (parent_a,'qa:mother:'||parent_a::text,'mother-'||parent_a::text||'@example.invalid'),
20
+ (parent_b,'qa:father:'||parent_b::text,'father-'||parent_b::text||'@example.invalid'),
21
+ (child_a,'qa:child:'||child_a::text,'child-'||child_a::text||'@example.invalid'),
22
+ (outsider,'qa:outsider:'||outsider::text,'outsider-'||outsider::text||'@example.invalid');
23
+ insert into lifeguide_qa.family_workspace(id,name,created_by)
24
+ values (fam,'Synthetic LifeGuide QA Family',parent_a);
25
+ insert into lifeguide_qa.family_membership(family_id,user_id,role,is_admin) values
26
+ (fam,parent_a,'parent_guardian',true),
27
+ (fam,parent_b,'parent_guardian',false),
28
+ (fam,child_a,'teen_minor',false);
29
+ insert into lifeguide_qa.guardian_relationship(family_id,guardian_user_id,minor_user_id)
30
+ values (fam,parent_a,child_a),(fam,parent_b,child_a);
31
+ if not lifeguide_qa.is_active_guardian(fam,parent_a,child_a)
32
+ or not lifeguide_qa.is_active_guardian(fam,parent_b,child_a)
33
+ or lifeguide_qa.is_active_guardian(fam,outsider,child_a)
34
+ or not lifeguide_qa.can_view_student_academic(parent_a,child_a)
35
+ or lifeguide_qa.can_view_student_academic(outsider,child_a)
36
+ then raise exception 'qa_guardian_visibility_failed'; end if;
37
+ insert into lifeguide_qa.plan_item(id,owner_user_id,family_id,kind,title,visibility)
38
+ values (shared_task,child_a,fam,'assignment','Synthetic math task','parent_guardian'),
39
+ (private_task,child_a,fam,'task','Synthetic private task','private');
40
+ if not lifeguide_qa.can_view_plan_item(parent_a,shared_task)
41
+ or not lifeguide_qa.can_view_plan_item(parent_b,shared_task)
42
+ or lifeguide_qa.can_view_plan_item(outsider,shared_task)
43
+ or lifeguide_qa.can_view_plan_item(parent_a,private_task)
44
+ or not lifeguide_qa.can_view_plan_item(child_a,private_task)
45
+ then raise exception 'qa_plan_privacy_failed'; end if;
46
+ insert into lifeguide_qa.study_session(
47
+ id,child_user_id,plan_item_id,source,status,started_at,ended_at,last_event_at,recorded_duration_seconds)
48
+ values (study_id,child_a,shared_task,'timer','completed',
49
+ now()-interval '4 seconds',now(),now(),4);
50
+ select recorded_duration_seconds into seconds
51
+ from lifeguide_qa.study_session where id=study_id;
52
+ if seconds<>4 then raise exception 'qa_study_seconds_failed'; end if;
53
+ update lifeguide_qa.guardian_relationship set active=false
54
+ where family_id=fam and guardian_user_id=parent_b and minor_user_id=child_a;
55
+ if lifeguide_qa.is_active_guardian(fam,parent_b,child_a)
56
+ or lifeguide_qa.can_view_plan_item(parent_b,shared_task)
57
+ or not lifeguide_qa.can_view_plan_item(parent_a,shared_task)
58
+ then raise exception 'qa_guardian_revocation_failed'; end if;
59
+end $qa_guardian_test$;
60
+rollback;