@davoodmehraban89 / LifeMate / commits / c118f06
Fork 0

LifeMate — Personal, Family & Learning Companion

test: validate phase 4 database constraints

davoodmehraban89 committed Oct 5, 2026 at 16:16 UTC c118f06a91192c82ea280495709b9f4c6dee905c
1 file changed +48
backend/tests/phase4_schema_test.sql new
+48
@@ -0,0 +1,48 @@
1 +\set ON_ERROR_STOP on
2 +begin;
3 +
4 +insert into app_user(id,identity_subject,email_normalized) values
5 +('40000000-0000-0000-0000-000000000001','p4-owner','p4-owner@example.test');
6 +
7 +insert into profile(user_id,display_name) values
8 +('40000000-0000-0000-0000-000000000001','P4 Owner');
9 +
10 +insert into learning_goal(id,owner_user_id,title,target) values
11 +('41000000-0000-0000-0000-000000000001','40000000-0000-0000-0000-000000000001','Goal','Target');
12 +
13 +insert into learning_checkin(owner_user_id,learning_goal_id,confidence,difficulty,note) values
14 +('40000000-0000-0000-0000-000000000001','41000000-0000-0000-0000-000000000001',4,3,'note');
15 +
16 +insert into wellbeing_checkin(owner_user_id,mood,energy,stress,note,visibility) values
17 +('40000000-0000-0000-0000-000000000001',4,3,2,'private note','private');
18 +
19 +insert into ai_guide_session(id,owner_user_id,guide_kind) values
20 +('42000000-0000-0000-0000-000000000001','40000000-0000-0000-0000-000000000001','wellbeing');
21 +
22 +insert into ai_guide_message(session_id,author,body,safety_class) values
23 +('42000000-0000-0000-0000-000000000001','user','hello','ordinary');
24 +
25 +insert into wellbeing_safety_event(owner_user_id,source_session_id,severity) values
26 +('40000000-0000-0000-0000-000000000001','42000000-0000-0000-0000-000000000001','urgent_review');
27 +
28 +insert into ai_plan_proposal(owner_user_id,session_id,title,proposal) values
29 +('40000000-0000-0000-0000-000000000001','42000000-0000-0000-0000-000000000001','Plan','{"steps":[1,2]}'::jsonb);
30 +
31 +do $$
32 +begin
33 + begin
34 + insert into wellbeing_checkin(owner_user_id,mood,energy,stress)
35 + values('40000000-0000-0000-0000-000000000001',6,3,2);
36 + raise exception 'mood constraint failed to reject invalid value';
37 + exception when check_violation then null;
38 + end;
39 +
40 + begin
41 + insert into ai_guide_session(owner_user_id,guide_kind)
42 + values('40000000-0000-0000-0000-000000000001','diagnostician');
43 + raise exception 'guide kind constraint failed';
44 + exception when check_violation then null;
45 + end;
46 +end $$;
47 +
48 +rollback;