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
| 1 | import test, { after } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { app, pool } from '../src/server.js'; |
| 4 | |
| 5 | const server = app.listen(0); |
| 6 | const address = server.address(); |
| 7 | const base = `http://127.0.0.1:${address.port}`; |
| 8 | |
| 9 | after(async () => { |
| 10 | await new Promise((resolve) => server.close(resolve)); |
| 11 | await pool.end(); |
| 12 | }); |
| 13 | |
| 14 | async function request(path, { method = 'GET', body, token } = {}) { |
| 15 | const response = await fetch(base + path, { |
| 16 | method, |
| 17 | headers: { |
| 18 | 'content-type': 'application/json', |
| 19 | ...(token ? { authorization: `Bearer ${token}` } : {}), |
| 20 | }, |
| 21 | body: body === undefined ? undefined : JSON.stringify(body), |
| 22 | }); |
| 23 | const text = await response.text(); |
| 24 | return { |
| 25 | status: response.status, |
| 26 | body: text ? JSON.parse(text) : null, |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | test('identity + family vertical slice', async () => { |
| 31 | const suffix = Date.now().toString(36); |
| 32 | const parentEmail = `parent-${suffix}@example.test`; |
| 33 | const teenEmail = `teen-${suffix}@example.test`; |
| 34 | const supporterEmail = `supporter-${suffix}@example.test`; |
| 35 | const initialPassword = 'StrongPass!123'; |
| 36 | const changedPassword = 'StrongerPass!456'; |
| 37 | |
| 38 | const parentRegister = await request('/v1/auth/register', { |
| 39 | method: 'POST', |
| 40 | body: { |
| 41 | displayName: 'Parent', |
| 42 | email: parentEmail, |
| 43 | password: initialPassword, |
| 44 | }, |
| 45 | }); |
| 46 | assert.equal(parentRegister.status, 201); |
| 47 | assert.ok(parentRegister.body.verificationToken); |
| 48 | |
| 49 | const parentVerify = await request('/v1/auth/verify-email', { |
| 50 | method: 'POST', |
| 51 | body: { token: parentRegister.body.verificationToken, newPassword: initialPassword }, |
| 52 | }); |
| 53 | assert.equal(parentVerify.status, 204); |
| 54 | |
| 55 | const parentLogin = await request('/v1/auth/login', { |
| 56 | method: 'POST', |
| 57 | body: { email: parentEmail, password: initialPassword }, |
| 58 | }); |
| 59 | assert.equal(parentLogin.status, 200); |
| 60 | assert.ok(parentLogin.body.accessToken); |
| 61 | assert.ok(parentLogin.body.refreshToken); |
| 62 | |
| 63 | const refreshed = await request('/v1/auth/refresh', { |
| 64 | method: 'POST', |
| 65 | body: { refreshToken: parentLogin.body.refreshToken }, |
| 66 | }); |
| 67 | assert.equal(refreshed.status, 200); |
| 68 | assert.ok(refreshed.body.accessToken); |
| 69 | assert.notEqual(refreshed.body.refreshToken, parentLogin.body.refreshToken); |
| 70 | |
| 71 | const profile = await request('/v1/profile', { |
| 72 | token: refreshed.body.accessToken, |
| 73 | }); |
| 74 | assert.equal(profile.status, 200); |
| 75 | assert.equal(profile.body.display_name, 'Parent'); |
| 76 | |
| 77 | const profileUpdate = await request('/v1/profile', { |
| 78 | method: 'PATCH', |
| 79 | token: refreshed.body.accessToken, |
| 80 | body: { themePreference: 'adult_blue' }, |
| 81 | }); |
| 82 | assert.equal(profileUpdate.status, 200); |
| 83 | assert.equal(profileUpdate.body.theme_preference, 'adult_blue'); |
| 84 | |
| 85 | const family = await request('/v1/families', { |
| 86 | method: 'POST', |
| 87 | token: refreshed.body.accessToken, |
| 88 | body: { name: 'Test Family', role: 'parent_guardian' }, |
| 89 | }); |
| 90 | assert.equal(family.status, 201); |
| 91 | assert.ok(family.body.id); |
| 92 | |
| 93 | const teenRegister = await request('/v1/auth/register', { |
| 94 | method: 'POST', |
| 95 | body: { |
| 96 | displayName: 'Teen', |
| 97 | email: teenEmail, |
| 98 | password: initialPassword, |
| 99 | }, |
| 100 | }); |
| 101 | assert.equal(teenRegister.status, 201); |
| 102 | |
| 103 | assert.equal( |
| 104 | (await request('/v1/auth/verify-email', { |
| 105 | method: 'POST', |
| 106 | body: { token: teenRegister.body.verificationToken, newPassword: initialPassword }, |
| 107 | })).status, |
| 108 | 204, |
| 109 | ); |
| 110 | |
| 111 | const teenLogin = await request('/v1/auth/login', { |
| 112 | method: 'POST', |
| 113 | body: { email: teenEmail, password: initialPassword }, |
| 114 | }); |
| 115 | assert.equal(teenLogin.status, 200); |
| 116 | |
| 117 | const unauthenticatedMembers = await request(`/v1/families/${family.body.id}/members`); |
| 118 | assert.equal(unauthenticatedMembers.status, 401); |
| 119 | |
| 120 | const invite = await request(`/v1/families/${family.body.id}/invitations`, { |
| 121 | method: 'POST', |
| 122 | token: refreshed.body.accessToken, |
| 123 | body: { email: teenEmail, role: 'teen_minor' }, |
| 124 | }); |
| 125 | assert.equal(invite.status, 201); |
| 126 | assert.ok(invite.body.invitationToken); |
| 127 | |
| 128 | const accept = await request('/v1/invitations/accept', { |
| 129 | method: 'POST', |
| 130 | token: teenLogin.body.accessToken, |
| 131 | body: { token: invite.body.invitationToken }, |
| 132 | }); |
| 133 | assert.equal(accept.status, 204); |
| 134 | |
| 135 | const members = await request(`/v1/families/${family.body.id}/members`, { |
| 136 | token: refreshed.body.accessToken, |
| 137 | }); |
| 138 | assert.equal(members.status, 200); |
| 139 | assert.equal(members.body.members.length, 2); |
| 140 | const parentMember = members.body.members.find((m) => m.display_name === 'Parent'); |
| 141 | const teenMember = members.body.members.find((m) => m.display_name === 'Teen'); |
| 142 | assert.equal(parentMember.role, 'parent_guardian'); |
| 143 | assert.equal(parentMember.is_admin, true); |
| 144 | assert.equal(teenMember.role, 'teen_minor'); |
| 145 | assert.equal(teenMember.is_admin, false); |
| 146 | |
| 147 | const teenInviteAttempt = await request(`/v1/families/${family.body.id}/invitations`, { |
| 148 | method: 'POST', |
| 149 | token: teenLogin.body.accessToken, |
| 150 | body: { email: 'blocked@example.test', role: 'adult_member' }, |
| 151 | }); |
| 152 | assert.equal(teenInviteAttempt.status, 403); |
| 153 | |
| 154 | const reinviteActiveTeen = await request( |
| 155 | `/v1/families/${family.body.id}/invitations`, |
| 156 | { |
| 157 | method: 'POST', |
| 158 | token: refreshed.body.accessToken, |
| 159 | body: { |
| 160 | email: teenEmail, |
| 161 | role: 'parent_guardian', |
| 162 | themePreference: 'adult_blue', |
| 163 | }, |
| 164 | }, |
| 165 | ); |
| 166 | assert.equal(reinviteActiveTeen.status, 409); |
| 167 | |
| 168 | const supporterRegister = await request('/v1/auth/register', { |
| 169 | method: 'POST', |
| 170 | body: { |
| 171 | displayName: 'Supporter', |
| 172 | email: supporterEmail, |
| 173 | password: initialPassword, |
| 174 | }, |
| 175 | }); |
| 176 | assert.equal(supporterRegister.status, 201); |
| 177 | assert.equal( |
| 178 | ( |
| 179 | await request('/v1/auth/verify-email', { |
| 180 | method: 'POST', |
| 181 | body: { token: supporterRegister.body.verificationToken, newPassword: initialPassword }, |
| 182 | }) |
| 183 | ).status, |
| 184 | 204, |
| 185 | ); |
| 186 | const supporterLogin = await request('/v1/auth/login', { |
| 187 | method: 'POST', |
| 188 | body: { email: supporterEmail, password: initialPassword }, |
| 189 | }); |
| 190 | assert.equal(supporterLogin.status, 200); |
| 191 | |
| 192 | const supporterInvite = await request( |
| 193 | `/v1/families/${family.body.id}/invitations`, |
| 194 | { |
| 195 | method: 'POST', |
| 196 | token: refreshed.body.accessToken, |
| 197 | body: { email: supporterEmail, role: 'parent_guardian' }, |
| 198 | }, |
| 199 | ); |
| 200 | assert.equal(supporterInvite.status, 201); |
| 201 | assert.equal( |
| 202 | ( |
| 203 | await request('/v1/invitations/accept', { |
| 204 | method: 'POST', |
| 205 | token: supporterLogin.body.accessToken, |
| 206 | body: { token: supporterInvite.body.invitationToken }, |
| 207 | }) |
| 208 | ).status, |
| 209 | 204, |
| 210 | ); |
| 211 | |
| 212 | const nonAdminParentInviteAttempt = await request( |
| 213 | `/v1/families/${family.body.id}/invitations`, |
| 214 | { |
| 215 | method: 'POST', |
| 216 | token: supporterLogin.body.accessToken, |
| 217 | body: { email: 'blocked-by-policy@example.test', role: 'adult_member' }, |
| 218 | }, |
| 219 | ); |
| 220 | assert.equal(nonAdminParentInviteAttempt.status, 403); |
| 221 | |
| 222 | const guardian = await request(`/v1/families/${family.body.id}/guardians`, { |
| 223 | method: 'POST', |
| 224 | token: refreshed.body.accessToken, |
| 225 | body: { |
| 226 | guardianUserId: parentMember.user_id, |
| 227 | minorUserId: teenMember.user_id, |
| 228 | }, |
| 229 | }); |
| 230 | assert.equal(guardian.status, 204); |
| 231 | |
| 232 | const teenGuardianAttempt = await request(`/v1/families/${family.body.id}/guardians`, { |
| 233 | method: 'POST', |
| 234 | token: teenLogin.body.accessToken, |
| 235 | body: { |
| 236 | guardianUserId: parentMember.user_id, |
| 237 | minorUserId: teenMember.user_id, |
| 238 | }, |
| 239 | }); |
| 240 | assert.equal(teenGuardianAttempt.status, 403); |
| 241 | |
| 242 | const forgot = await request('/v1/auth/forgot-password', { |
| 243 | method: 'POST', |
| 244 | body: { email: teenEmail }, |
| 245 | }); |
| 246 | assert.equal(forgot.status, 200); |
| 247 | assert.equal(forgot.body.accepted, true); |
| 248 | assert.ok(forgot.body.resetToken); |
| 249 | |
| 250 | const reset = await request('/v1/auth/reset-password', { |
| 251 | method: 'POST', |
| 252 | body: { token: forgot.body.resetToken, newPassword: changedPassword }, |
| 253 | }); |
| 254 | assert.equal(reset.status, 204); |
| 255 | |
| 256 | const oldLogin = await request('/v1/auth/login', { |
| 257 | method: 'POST', |
| 258 | body: { email: teenEmail, password: initialPassword }, |
| 259 | }); |
| 260 | assert.equal(oldLogin.status, 401); |
| 261 | |
| 262 | const newLogin = await request('/v1/auth/login', { |
| 263 | method: 'POST', |
| 264 | body: { email: teenEmail, password: changedPassword }, |
| 265 | }); |
| 266 | assert.equal(newLogin.status, 200); |
| 267 | |
| 268 | const changedAgain = await request('/v1/auth/change-password', { |
| 269 | method: 'POST', |
| 270 | token: newLogin.body.accessToken, |
| 271 | body: { currentPassword: changedPassword, newPassword: initialPassword }, |
| 272 | }); |
| 273 | assert.equal(changedAgain.status, 204); |
| 274 | |
| 275 | const logout = await request('/v1/auth/logout', { |
| 276 | method: 'POST', |
| 277 | token: newLogin.body.accessToken, |
| 278 | }); |
| 279 | assert.equal(logout.status, 204); |
| 280 | |
| 281 | const afterLogout = await request('/v1/profile', { |
| 282 | token: newLogin.body.accessToken, |
| 283 | }); |
| 284 | assert.equal(afterLogout.status, 401); |
| 285 | }); |
| 286 | |
| 287 | test('forgot-password response does not enumerate accounts', async () => { |
| 288 | const response = await request('/v1/auth/forgot-password', { |
| 289 | method: 'POST', |
| 290 | body: { email: `missing-${Date.now()}@example.test` }, |
| 291 | }); |
| 292 | assert.equal(response.status, 200); |
| 293 | assert.deepEqual(response.body, { accepted: true }); |
| 294 | }); |