LifeMate — Personal, Family & Learning Companion

feat/learning-content-operations
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
js 293 lines 22.7 KB
Raw
1 import test, { after, before } from 'node:test';
2 import assert from 'node:assert/strict';
3 import crypto from 'node:crypto';
4 import { spawn } from 'node:child_process';
5 import { once } from 'node:events';
6 import net from 'node:net';
7 import pg from 'pg';
8 import jwt from 'jsonwebtoken';
9 import fs from 'node:fs/promises';
10
11 assert.ok(process.env.DATABASE_URL, 'School tests require migrated synthetic PostgreSQL');
12 assert.ok(process.env.JWT_SECRET?.length >= 32, 'School tests require a synthetic JWT secret');
13 const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
14 const users = [], families = [];
15 let child, base, output = '', errors = '';
16
17 async function start() {
18 const reservation = net.createServer().listen(0, '127.0.0.1');
19 await once(reservation, 'listening');
20 const port = reservation.address().port;
21 await new Promise((resolve) => reservation.close(resolve));
22 base = `http://127.0.0.1:${port}`;
23 let startup = '';
24 child = spawn(process.execPath, ['src/entrypoint.js'], {
25 env: { ...process.env, NODE_ENV: 'production', PORT: String(port),
26 SMS_PROVIDER: 'disabled', SMS_PROVIDER_URL: '', SMS_PROVIDER_TOKEN: '', EMAIL_FROM: '', RESEND_API_KEY: '', SMTP_HOST: '',
27 CORS_ORIGINS: '', TRUSTED_PROXY_CIDRS: '', ENABLE_SENSITIVE_FEATURES: 'false',
28 RATE_LIMIT_AUTH_MAX: '2000', RATE_LIMIT_GENERAL_MAX: '4000', RATE_LIMIT_AI_MAX: '2000' },
29 stdio: ['ignore', 'pipe', 'pipe'],
30 });
31 child.stdout.on('data', (chunk) => { output += chunk.toString(); startup += chunk.toString(); });
32 child.stderr.on('data', (chunk) => { errors += chunk.toString(); });
33 await new Promise((resolve, reject) => {
34 const timer = setTimeout(() => reject(new Error('School fixture startup timed out')), 10000);
35 const onData = () => {
36 if (!startup.includes('"type":"startup"')) return;
37 clearTimeout(timer); child.stdout.off('data', onData); resolve();
38 };
39 child.stdout.on('data', onData);
40 child.once('error', (error) => { clearTimeout(timer); reject(error); });
41 });
42 }
43 async function stop() {
44 if (child && child.exitCode === null && child.signalCode === null) {
45 const closed = once(child, 'close'); child.kill('SIGTERM'); await closed;
46 }
47 }
48 before(start);
49 after(async () => {
50 await stop();
51 try {
52 await pool.query('delete from access_audit where family_id=any($1::uuid[]) or actor_user_id=any($2::uuid[])', [families, users]);
53 await pool.query('delete from family_workspace where id=any($1::uuid[])', [families]);
54 await pool.query('delete from app_user where id=any($1::uuid[])', [users]);
55 } finally { await pool.end(); }
56 });
57 async function user() {
58 const id = crypto.randomUUID(), sid = crypto.randomUUID();
59 users.push(id);
60 await pool.query('insert into app_user(id,identity_subject,email_normalized,email_verified_at) values($1,$2,$3,now())', [id, `school-fixture:${id}`, `school-${id}@example.test`]);
61 await pool.query("insert into profile(user_id,display_name,theme_preference) values($1,'Synthetic School User','adult_blue')", [id]);
62 await pool.query("insert into auth_session(id,user_id,refresh_digest,expires_at) values($1,$2,$3,now()+interval '1 day')", [sid, id, crypto.randomBytes(32).toString('hex')]);
63 return { id, token: jwt.sign({ sub: id, sid, aud: 'lifemate-api' }, process.env.JWT_SECRET, { issuer: 'lifemate', expiresIn: '15m' }) };
64 }
65 async function request(path, { method = 'GET', actor, body } = {}) {
66 const response = await fetch(base + path, { method, headers: { 'content-type': 'application/json', ...(actor ? { authorization: `Bearer ${actor.token}` } : {}) }, body: body === undefined ? undefined : JSON.stringify(body) });
67 const text = await response.text();
68 return { status: response.status, body: text && response.headers.get('content-type')?.includes('application/json') ? JSON.parse(text) : text || null };
69 }
70 async function school(actor = undefined) {
71 actor ??= await user();
72 const context = await request('/v1/life-contexts', { method: 'POST', actor, body: { kind: 'student', title: 'Synthetic School' } });
73 assert.equal(context.status, 201);
74 const year = await request('/v1/school/years', { method: 'POST', actor, body: { lifeContextId: context.body.id, title: 'Synthetic Year', startsOn: '2026-09-01', endsOn: '2027-06-30' } });
75 assert.equal(year.status, 201);
76 const term = await request(`/v1/school/years/${year.body.id}/terms`, { method: 'POST', actor, body: { title: 'Synthetic Term', startsOn: '2026-09-01', endsOn: '2027-01-31' } });
77 assert.equal(term.status, 201);
78 const subject = await request(`/v1/school/terms/${term.body.id}/subjects`, { method: 'POST', actor, body: { name: 'Synthetic Math', teacherName: 'Synthetic Teacher', colorKey: 'blue' } });
79 assert.equal(subject.status, 201);
80 const lesson = await request(`/v1/school/subjects/${subject.body.id}/classes`, { method: 'POST', actor, body: { weekday: 1, startsAt: '09:00', endsAt: '10:00', location: 'Synthetic Room', recurrenceUntil: '2027-01-31' } });
81 assert.equal(lesson.status, 201);
82 return { actor, context: context.body, year: year.body, term: term.body, subject: subject.body, lesson: lesson.body };
83 }
84 async function familyFixture() {
85 const f = await school();
86 const parent = await user(), outsider = await user();
87 const familyId = crypto.randomUUID(); families.push(familyId);
88 await pool.query("insert into family_workspace(id,name,created_by) values($1,'Synthetic School Family',$2)", [familyId, parent.id]);
89 await pool.query("insert into family_membership(family_id,user_id,role) values($1,$2,'teen_minor'),($1,$3,'parent_guardian')", [familyId, f.actor.id, parent.id]);
90 await pool.query('insert into guardian_relationship(family_id,guardian_user_id,minor_user_id) values($1,$2,$3)', [familyId, parent.id, f.actor.id]);
91 return { ...f, parent, outsider, familyId };
92 }
93
94 test('subject create/read/edit survives a real API process restart and archive preserves homework and report names', async () => {
95 const f = await familyFixture();
96 const path = `/v1/school/subjects/${f.subject.id}`;
97 assert.equal((await request(path, { actor: f.actor })).status, 200);
98 const updated = await request(path, { method: 'PATCH', actor: f.actor, body: { name: 'Renamed Math', teacherName: null, colorKey: 'green' } });
99 assert.equal(updated.status, 200);
100 const homework = await request('/v1/plan-items', { method: 'POST', actor: f.actor, body: { kind: 'assignment', title: 'Historical Math Homework', subjectId: f.subject.id, familyId: f.familyId, visibility: 'parent_guardian', notes: 'PRIVATE-SCHOOL-NOTE-MARKER' } });
101 assert.equal(homework.status, 201);
102 await stop(); await start();
103 const reopened = await request(path, { actor: f.actor });
104 assert.equal(reopened.status, 200);
105 assert.equal(reopened.body.name, 'Renamed Math');
106 assert.equal(reopened.body.teacher_name, null);
107 assert.equal((await request(path, { method: 'DELETE', actor: f.actor })).status, 204);
108 assert.equal((await request(path, { method: 'DELETE', actor: f.actor })).status, 204);
109 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { name: 'Must Not Restore' } })).status, 409);
110 assert.ok((await request(path, { actor: f.actor })).body.archived_at);
111 const current = await request(`/v1/school/${f.actor.id}/overview`, { actor: f.actor });
112 assert.equal(current.status, 200);
113 assert.equal(current.body.subjects.some((item) => item.id === f.subject.id), false);
114 assert.equal((await request(`/v1/school/${f.actor.id}/timetable`, { actor: f.actor })).body.classes.length, 0);
115 const stored = (await pool.query('select p.subject_id,s.name,s.archived_at from plan_item p join subject s on s.id=p.subject_id where p.id=$1', [homework.body.id])).rows[0];
116 assert.equal(stored.subject_id, f.subject.id);
117 assert.equal(stored.name, 'Renamed Math');
118 assert.ok(stored.archived_at);
119 const report = await request(`/v1/families/${f.familyId}/children/${f.actor.id}/learning-report`, { actor: f.parent });
120 assert.equal(report.status, 200);
121 assert.equal(report.body.items.find((item) => item.id === homework.body.id).subjectName, 'Renamed Math');
122 assert.equal(JSON.stringify(report.body).includes('PRIVATE-SCHOOL-NOTE-MARKER'), false);
123 });
124
125 test('class edits validate real times/dates and ownership, and archive remains persistent and owner-only', async () => {
126 const f = await school();
127 const other = await school();
128 const path = `/v1/school/classes/${f.lesson.id}`;
129 assert.equal((await request(path, { actor: f.actor })).status, 200);
130 for (const bad of [{ weekday: 8 }, { weekday: '2' }, { startsAt: '10:00', endsAt: '09:00' }, { startsAt: '25:00' }, { endsAt: '10:00Z' }, { recurrenceUntil: '2026-02-30' }, { recurrenceUntil: '2027-02-01' }, { location: 'x'.repeat(241) }]) {
131 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: bad })).status, 400);
132 }
133 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { subjectId: other.subject.id } })).status, 403);
134 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { weekday: 3, startsAt: '11:15', endsAt: '12:00', location: null, recurrenceUntil: null } })).status, 200);
135 await stop(); await start();
136 const reopened = await request(path, { actor: f.actor });
137 assert.equal(reopened.body.weekday, 3);
138 assert.equal(reopened.body.starts_at, '11:15:00');
139 assert.equal(reopened.body.location, null);
140 assert.equal((await request(path, { method: 'DELETE', actor: other.actor })).status, 404);
141 assert.equal((await request(path, { method: 'DELETE', actor: f.actor })).status, 204);
142 assert.equal((await request(path, { method: 'DELETE', actor: f.actor })).status, 204);
143 assert.equal((await request(`/v1/school/${f.actor.id}/timetable`, { actor: f.actor })).body.classes.length, 0);
144 assert.ok((await pool.query('select archived_at from class_session where id=$1', [f.lesson.id])).rows[0].archived_at);
145 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { weekday: 2 } })).status, 409);
146 });
147
148 test('guardians can read only currently authorized school projections and cannot mutate owner courses/classes', async () => {
149 const f = await familyFixture();
150 await request('/v1/plan-items', { method: 'POST', actor: f.actor, body: { title: 'Shared Class Homework', kind: 'assignment', familyId: f.familyId, subjectId: f.subject.id, visibility: 'parent_guardian' } });
151 for (const actor of [f.parent, f.outsider]) {
152 for (const path of [`/v1/school/subjects/${f.subject.id}`, `/v1/school/classes/${f.lesson.id}`]) {
153 for (const method of ['GET', 'PATCH', 'DELETE']) assert.equal((await request(path, { method, actor, body: method === 'PATCH' ? { name: 'Forbidden', weekday: 2 } : undefined })).status, 404);
154 }
155 }
156 assert.equal((await request(`/v1/school/${f.actor.id}/timetable`, { actor: f.parent })).body.classes.length, 1);
157 assert.equal((await request(`/v1/school/${f.actor.id}/timetable`, { actor: f.outsider })).status, 403);
158 await pool.query('update guardian_relationship set active=false where family_id=$1', [f.familyId]);
159 assert.equal((await request(`/v1/school/${f.actor.id}/overview`, { actor: f.parent })).status, 403);
160 await pool.query('update guardian_relationship set active=true where family_id=$1', [f.familyId]);
161 await pool.query('update family_workspace set archived_at=now() where id=$1', [f.familyId]);
162 assert.equal((await request(`/v1/school/${f.actor.id}/timetable`, { actor: f.parent })).status, 403);
163 assert.equal((await request(`/v1/school/subjects/${f.subject.id}`, { actor: f.actor })).status, 200);
164 });
165
166 test('subject edits require an active owned term and reject invalid fields without partial changes', async () => {
167 const f = await school(), other = await school();
168 const path = `/v1/school/subjects/${f.subject.id}`;
169 for (const body of [{ name: '' }, { name: 'x'.repeat(121) }, { teacherName: 'x'.repeat(121) }, { colorKey: 'x'.repeat(41) }, { academicTermId: 'invalid' }]) {
170 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body })).status, 400);
171 }
172 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { name: 'Must Not Change', academicTermId: other.term.id } })).status, 403);
173 assert.equal((await request(path, { actor: f.actor })).body.name, 'Synthetic Math');
174 const nextTerm = await request(`/v1/school/years/${f.year.id}/terms`, { method: 'POST', actor: f.actor, body: { title: 'Next Term', startsOn: '2027-02-01', endsOn: '2027-06-30' } });
175 assert.equal(nextTerm.status, 201);
176 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { academicTermId: nextTerm.body.id } })).status, 400);
177 assert.equal((await request(`/v1/school/classes/${f.lesson.id}`, { method: 'PATCH', actor: f.actor, body: { recurrenceUntil: null } })).status, 200);
178 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { academicTermId: nextTerm.body.id } })).status, 200);
179 await pool.query('update academic_year set active=false where id=$1', [f.year.id]);
180 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { name: 'Inactive Term' } })).status, 409);
181 });
182
183 test('school create rejects malformed dates/times and archived subject links without inserting records', async () => {
184 const f = await school();
185 for (const body of [
186 { title: 'Invalid Year', startsOn: '2026-02-30', endsOn: '2026-06-30' },
187 { title: 'Reversed Year', startsOn: '2027-06-30', endsOn: '2026-09-01' },
188 { title: 'x'.repeat(121), startsOn: '2026-09-01', endsOn: '2027-06-30' },
189 ]) assert.equal((await request('/v1/school/years', { method: 'POST', actor: f.actor, body: { ...body, lifeContextId: f.context.id } })).status, 400);
190 assert.equal((await request(`/v1/school/years/${f.year.id}/terms`, { method: 'POST', actor: f.actor, body: { title: 'Outside Year', startsOn: '2026-08-01', endsOn: '2027-01-31' } })).status, 400);
191 assert.equal((await request(`/v1/school/terms/${f.term.id}/subjects`, { method: 'POST', actor: f.actor, body: { name: 'x'.repeat(121) } })).status, 400);
192 const classPath = `/v1/school/subjects/${f.subject.id}/classes`;
193 for (const body of [{ weekday: 0, startsAt: '09:00', endsAt: '10:00' }, { weekday: 1, startsAt: '25:00', endsAt: '26:00' }, { weekday: 1, startsAt: '10:00', endsAt: '09:00' }, { weekday: 1, startsAt: '09:00', endsAt: '10:00', recurrenceUntil: '2026-02-30' }]) {
194 assert.equal((await request(classPath, { method: 'POST', actor: f.actor, body })).status, 400);
195 }
196 assert.equal((await request(`/v1/school/subjects/${f.subject.id}`, { method: 'DELETE', actor: f.actor })).status, 204);
197 assert.equal((await request(classPath, { method: 'POST', actor: f.actor, body: { weekday: 1, startsAt: '09:00', endsAt: '10:00' } })).status, 409);
198 assert.equal((await pool.query('select count(*)::int as n from class_session where subject_id=$1', [f.subject.id])).rows[0].n, 1);
199 });
200
201 test('learning check-ins have persistent owner CRUD, explicit self-report timestamps and private notes', async () => {
202 const f = await familyFixture();
203 const goal = await request('/v1/learning/goals', { method: 'POST', actor: f.actor, body: { title: 'Synthetic Goal', subjectId: f.subject.id } });
204 assert.equal(goal.status, 201);
205 const created = await request('/v1/learning/checkins', { method: 'POST', actor: f.actor, body: { learningGoalId: goal.body.id, confidence: 2, difficulty: 4, note: 'PRIVATE-CHECKIN-SYNTHETIC-MARKER' } });
206 assert.equal(created.status, 201);
207 assert.equal(created.body.source, 'self_reported');
208 assert.equal(created.body.isEvidenceOfStudy, false);
209 assert.ok(created.body.occurred_at);
210 const path = `/v1/learning/checkins/${created.body.id}`;
211 assert.equal((await request(path, { actor: f.actor })).body.note, 'PRIVATE-CHECKIN-SYNTHETIC-MARKER');
212 for (const actor of [f.parent, f.outsider]) {
213 assert.equal((await request(path, { actor })).status, 404);
214 assert.equal((await request(path, { method: 'PATCH', actor, body: { note: 'Forbidden' } })).status, 404);
215 assert.equal((await request(path, { method: 'DELETE', actor })).status, 404);
216 assert.equal(JSON.stringify((await request('/v1/learning/checkins', { actor })).body).includes('PRIVATE-CHECKIN-SYNTHETIC-MARKER'), false);
217 }
218 const occurredAt = new Date(Date.now() - 86400000).toISOString();
219 const updated = await request(path, { method: 'PATCH', actor: f.actor, body: { confidence: 5, difficulty: 1, note: null, occurredAt } });
220 assert.equal(updated.status, 200);
221 await stop(); await start();
222 const reopened = await request(path, { actor: f.actor });
223 assert.equal(reopened.status, 200);
224 assert.equal(reopened.body.confidence, 5);
225 assert.equal(reopened.body.note, null);
226 assert.equal(reopened.body.occurred_at, occurredAt);
227 assert.equal((await request(path, { method: 'DELETE', actor: f.actor })).status, 204);
228 assert.equal((await request(path, { method: 'DELETE', actor: f.actor })).status, 204);
229 assert.equal((await request('/v1/learning/checkins', { actor: f.actor })).body.items.some((item) => item.id === created.body.id), false);
230 assert.equal((await request(path, { method: 'PATCH', actor: f.actor, body: { confidence: 3 } })).status, 409);
231 const stored = (await pool.query('select archived_at,note,learning_goal_id from learning_checkin where id=$1', [created.body.id])).rows[0];
232 assert.ok(stored.archived_at);
233 assert.equal(stored.learning_goal_id, goal.body.id);
234 assert.equal(stored.note, null);
235 assert.equal(errors.includes('PRIVATE-CHECKIN-SYNTHETIC-MARKER'), false);
236 assert.equal(output.includes('PRIVATE-CHECKIN-SYNTHETIC-MARKER'), false);
237 });
238
239 test('check-in validation rejects forged/archived goals, invalid timestamps and claimed evidence without data loss', async () => {
240 const actor = await user(), other = await user();
241 const own = await request('/v1/learning/goals', { method: 'POST', actor, body: { title: 'Own Goal' } });
242 const foreign = await request('/v1/learning/goals', { method: 'POST', actor: other, body: { title: 'Foreign Goal' } });
243 const body = { confidence: 3, difficulty: 3, note: 'Unchanged Note', learningGoalId: own.body.id };
244 assert.equal((await request('/v1/learning/checkins', { method: 'POST', actor, body: { ...body, learningGoalId: foreign.body.id } })).status, 403);
245 const created = await request('/v1/learning/checkins', { method: 'POST', actor, body });
246 assert.equal(created.status, 201);
247 const path = `/v1/learning/checkins/${created.body.id}`;
248 for (const bad of [{ confidence: 0 }, { difficulty: 6 }, { difficulty: '3' }, { note: 'x'.repeat(2001) }, { occurredAt: '2026-02-30T12:00:00Z' }, { occurredAt: new Date(Date.now() + 300000).toISOString() }, { source: 'verified' }, { isEvidenceOfStudy: true }]) {
249 assert.equal((await request(path, { method: 'PATCH', actor, body: { ...bad, note: bad.note ?? 'Must Not Save' } })).status, 400);
250 }
251 assert.equal((await request(path, { method: 'PATCH', actor, body: { learningGoalId: foreign.body.id } })).status, 403);
252 assert.equal((await request(path, { actor })).body.note, 'Unchanged Note');
253 assert.equal((await request(`/v1/learning/goals/${own.body.id}`, { method: 'DELETE', actor })).status, 204);
254 assert.equal((await request('/v1/learning/checkins', { method: 'POST', actor, body })).status, 403);
255 assert.equal((await request(path, { method: 'PATCH', actor, body: { learningGoalId: own.body.id } })).status, 403);
256 assert.equal((await request(path, { method: 'PATCH', actor, body: { learningGoalId: null, note: 'Detached Private Note' } })).status, 200);
257 });
258
259 test('every new school/check-in operation requires current verified sessions and validates IDs', async () => {
260 const id = crypto.randomUUID();
261 const actor = await user();
262 for (const path of [`/v1/school/subjects/${id}`, `/v1/school/classes/${id}`, `/v1/learning/checkins/${id}`]) {
263 for (const method of ['GET', 'PATCH', 'DELETE']) assert.equal((await request(path, { method, body: method === 'PATCH' ? {} : undefined })).status, 401);
264 }
265 for (const path of ['/v1/school/subjects/bad', '/v1/school/classes/bad', '/v1/learning/checkins/bad']) {
266 assert.equal((await request(path, { actor })).status, 400);
267 }
268 await pool.query('update app_user set disabled_at=now() where id=$1', [actor.id]);
269 assert.equal((await request('/v1/learning/checkins', { actor })).status, 401);
270 });
271
272 test('school and check-in migration preserves legacy IDs, linked homework, notes and original timestamps', async () => {
273 const client = new pg.Client({ connectionString: process.env.DATABASE_URL });
274 await client.connect();
275 try {
276 await client.query(`create temporary table subject(id uuid primary key,student_user_id uuid,name text,created_at timestamptz);
277 create temporary table class_session(id uuid primary key,subject_id uuid,weekday smallint,starts_at time,created_at timestamptz);
278 create temporary table learning_checkin(id uuid primary key,owner_user_id uuid,learning_goal_id uuid,note text,confidence smallint,created_at timestamptz);
279 create temporary table plan_item(id uuid primary key,subject_id uuid)`);
280 const subjectId = crypto.randomUUID(), classId = crypto.randomUUID(), checkinId = crypto.randomUUID(), owner = crypto.randomUUID(), goalId = crypto.randomUUID();
281 await client.query("insert into subject values($1,$2,'Legacy Course','2025-01-01T09:00:00Z')", [subjectId, owner]);
282 await client.query("insert into class_session values($1,$2,2,'09:00','2025-01-02T09:00:00Z')", [classId, subjectId]);
283 await client.query("insert into learning_checkin values($1,$2,$3,'Legacy Private Note',4,'2025-01-03T09:00:00Z')", [checkinId, owner, goalId]);
284 await client.query('insert into plan_item values($1,$2)', [crypto.randomUUID(), subjectId]);
285 await client.query(await fs.readFile(new URL('../migrations/0012_school_archive.sql', import.meta.url), 'utf8'));
286 const course = (await client.query('select s.id,s.name,s.created_at=s.updated_at as timestamp_preserved,s.archived_at,p.subject_id from subject s join plan_item p on p.subject_id=s.id')).rows[0];
287 assert.equal(course.id, subjectId); assert.equal(course.subject_id, subjectId); assert.equal(course.name, 'Legacy Course'); assert.equal(course.timestamp_preserved, true); assert.equal(course.archived_at, null);
288 const lesson = (await client.query('select id,subject_id,weekday,starts_at,created_at=updated_at as timestamp_preserved,archived_at from class_session')).rows[0];
289 assert.equal(lesson.id, classId); assert.equal(lesson.subject_id, subjectId); assert.equal(lesson.weekday, 2); assert.equal(lesson.timestamp_preserved, true); assert.equal(lesson.archived_at, null);
290 const checkin = (await client.query('select id,learning_goal_id,note,confidence,source,created_at=occurred_at and created_at=updated_at as timestamp_preserved,archived_at from learning_checkin')).rows[0];
291 assert.equal(checkin.id, checkinId); assert.equal(checkin.learning_goal_id, goalId); assert.equal(checkin.note, 'Legacy Private Note'); assert.equal(checkin.confidence, 4); assert.equal(checkin.source, 'self_reported'); assert.equal(checkin.timestamp_preserved, true); assert.equal(checkin.archived_at, null);
292 } finally { await client.end(); }
293 });