@quad-education/sdk 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/contract-tests/apps.d.ts +3 -112
- package/dist/contract-tests/apps.js +6 -183
- package/dist/contract-tests/harness.d.ts +2 -2
- package/dist/contract-tests/index.d.ts +2 -3
- package/dist/contract-tests/index.js +1 -2
- package/dist/contract-tests/suite.d.ts +3 -10
- package/dist/contract-tests/suite.js +49 -502
- package/dist/src/client/connect.d.ts +3 -13
- package/dist/src/client/connect.js +3 -21
- package/dist/src/client/create-client.js +0 -3
- package/dist/src/client/handshake-client.d.ts +0 -2
- package/dist/src/client/handshake-client.js +0 -2
- package/dist/src/contract/errors.d.ts +1 -1
- package/dist/src/contract/recipients.d.ts +2 -8
- package/dist/src/contract/types.d.ts +7 -44
- package/dist/src/contract/types.js +1 -1
- package/dist/src/engine/engine.d.ts +10 -46
- package/dist/src/engine/engine.js +42 -222
- package/dist/src/engine/host.d.ts +2 -2
- package/dist/src/engine/in-process.d.ts +2 -2
- package/dist/src/engine/runner.js +2 -4
- package/dist/src/engine/state.d.ts +6 -17
- package/dist/src/engine/state.js +3 -31
- package/dist/src/engine/tasks.js +3 -10
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/jobs/define.d.ts +2 -2
- package/dist/src/platform-types.d.ts +2 -2
- package/dist/src/protocol.d.ts +1 -1
- package/dist/src/protocol.js +0 -1
- package/package.json +4 -4
- package/dist/contract-tests/standalone-apps.d.ts +0 -183
- package/dist/contract-tests/standalone-apps.js +0 -178
- package/dist/contract-tests/standalone.d.ts +0 -2
- package/dist/contract-tests/standalone.js +0 -709
- package/dist/src/client/http-transport.d.ts +0 -18
- package/dist/src/client/http-transport.js +0 -76
- package/dist/src/client/live.d.ts +0 -39
- package/dist/src/client/live.js +0 -122
- package/dist/src/contract/principals.d.ts +0 -30
- package/dist/src/contract/principals.js +0 -12
|
@@ -4,9 +4,8 @@ import { eligibleParents } from '@quad-education/canonical';
|
|
|
4
4
|
import { personasFor, withDerived } from '@quad-education/fictional-school';
|
|
5
5
|
import stored from '@quad-education/fictional-school/dataset' with { type: 'json' };
|
|
6
6
|
import { parentsOf, staffOf, studentsOf } from "../src/index.js";
|
|
7
|
-
import { ACCESS_APP,
|
|
7
|
+
import { ACCESS_APP, BASIC_APP, JOBS_APP, ROLES_APP, TEST_APP, MEDICAL_APP, slowGate, } from "./apps.js";
|
|
8
8
|
import { expectError, ids, listAll } from "./helpers.js";
|
|
9
|
-
import { defineStandaloneSections } from "./standalone.js";
|
|
10
9
|
// The fictional school is the oracle: tests compare what the SDK returns with what the
|
|
11
10
|
// dataset says should be visible. They never read an implementation's storage.
|
|
12
11
|
const ds = withDerived(stored);
|
|
@@ -25,9 +24,7 @@ const RESTRICTED_PARENT = persona('restricted-parent');
|
|
|
25
24
|
const childrenOf = (parentId) => ds.parentStudentLinks
|
|
26
25
|
.filter((l) => l.parentId === parentId && !l.contactRestricted)
|
|
27
26
|
.map((l) => l.studentId);
|
|
28
|
-
export function defineContractSuite(name, factory
|
|
29
|
-
const school = options.school !== false;
|
|
30
|
-
const schoolDescribe = school ? describe : describe.skip;
|
|
27
|
+
export function defineContractSuite(name, factory) {
|
|
31
28
|
describe(`@quad-education/sdk contract: ${name}`, () => {
|
|
32
29
|
let env;
|
|
33
30
|
const useApp = (app) => {
|
|
@@ -38,190 +35,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
38
35
|
await env.dispose();
|
|
39
36
|
});
|
|
40
37
|
};
|
|
41
|
-
describe('
|
|
42
|
-
useApp(ACCOUNT_APP);
|
|
43
|
-
const account = (accountId, ...roles) => ({
|
|
44
|
-
kind: 'account',
|
|
45
|
-
accountId,
|
|
46
|
-
roles,
|
|
47
|
-
});
|
|
48
|
-
const ADA = account('acc-ada', 'Teacher');
|
|
49
|
-
const BEN = account('acc-ben', 'Teacher', 'Student');
|
|
50
|
-
const CAI = account('acc-cai', 'Student');
|
|
51
|
-
const DEE = account('acc-dee', 'Student');
|
|
52
|
-
const GUEST1 = { kind: 'guest', guestId: 'guest-1' };
|
|
53
|
-
const GUEST2 = { kind: 'guest', guestId: 'guest-2' };
|
|
54
|
-
const notes = (sdk) => sdk.db.entity('note');
|
|
55
|
-
it('says who an account and a guest are', async () => {
|
|
56
|
-
expect(await (await env.connect(ADA)).auth.me()).toEqual({
|
|
57
|
-
kind: 'account',
|
|
58
|
-
account: { id: 'acc-ada', displayName: 'Ada Teacher' },
|
|
59
|
-
roles: ['Teacher'],
|
|
60
|
-
});
|
|
61
|
-
expect((await (await env.connect(BEN)).auth.me()).roles).toEqual(['Teacher', 'Student']);
|
|
62
|
-
expect(await (await env.connect(GUEST1)).auth.me()).toEqual({
|
|
63
|
-
kind: 'guest',
|
|
64
|
-
guest: { id: 'guest-1' },
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
it('refuses a role the app does not have, and guests when the app does not handle them', async () => {
|
|
68
|
-
const janitor = account('acc-ada', 'Janitor');
|
|
69
|
-
await expectError((await env.connect(janitor)).auth.me(), 'FORBIDDEN');
|
|
70
|
-
await env.control.restart({ manifest: { ...ACCOUNT_APP.manifest, guests: false } });
|
|
71
|
-
await expectError((await env.connect(GUEST1)).auth.me(), 'FORBIDDEN');
|
|
72
|
-
expect((await (await env.connect(ADA)).auth.me()).kind).toBe('account');
|
|
73
|
-
});
|
|
74
|
-
it('applies the rules of every role an account holds, matched ignoring case', async () => {
|
|
75
|
-
const [ada, ben, cai, dee] = await Promise.all([ADA, BEN, CAI, DEE].map((p) => env.connect(p)));
|
|
76
|
-
const fromBen = await notes(ben).create({ body: 'ben' });
|
|
77
|
-
const fromCai = await notes(cai).create({ body: 'cai' });
|
|
78
|
-
expect(fromBen.createdBy).toBe('acct:acc-ben');
|
|
79
|
-
// Teacher can read all; a Student only their own; Ben holds both, so he gets Teacher's `all`.
|
|
80
|
-
expect(ids(await listAll(notes(ada)))).toEqual(ids([fromBen, fromCai]));
|
|
81
|
-
expect(ids(await listAll(notes(ben)))).toEqual(ids([fromBen, fromCai]));
|
|
82
|
-
expect(ids(await listAll(notes(cai)))).toEqual([fromCai.id]);
|
|
83
|
-
expect(await listAll(notes(dee))).toEqual([]);
|
|
84
|
-
await expectError(notes(dee).get(fromCai.id), 'NOT_FOUND');
|
|
85
|
-
await expectError(notes(cai).get(fromBen.id), 'NOT_FOUND');
|
|
86
|
-
// A Student may change and delete only their own.
|
|
87
|
-
await notes(cai).update(fromCai.id, { body: 'cai again' });
|
|
88
|
-
await expectError(notes(cai).update(fromBen.id, { body: 'x' }), 'NOT_FOUND');
|
|
89
|
-
await notes(cai).delete(fromCai.id);
|
|
90
|
-
});
|
|
91
|
-
it('gives a guest only the guest rules, and never another guest’s records', async () => {
|
|
92
|
-
const [ada, guest1, guest2] = await Promise.all([ADA, GUEST1, GUEST2].map((p) => env.connect(p)));
|
|
93
|
-
const mine = await notes(guest1).create({ body: 'hello' });
|
|
94
|
-
expect(mine.createdBy).toBe('guest:guest-1');
|
|
95
|
-
expect(ids(await listAll(notes(guest1)))).toEqual([mine.id]);
|
|
96
|
-
expect(await listAll(notes(guest2))).toEqual([]);
|
|
97
|
-
await expectError(notes(guest2).get(mine.id), 'NOT_FOUND');
|
|
98
|
-
// `guest` has read and create, nothing else.
|
|
99
|
-
await expectError(notes(guest1).update(mine.id, { body: 'x' }), 'NOT_PERMITTED');
|
|
100
|
-
await expectError(notes(guest1).delete(mine.id), 'NOT_PERMITTED');
|
|
101
|
-
// A teacher reads everything, a guest's note included.
|
|
102
|
-
expect(ids(await listAll(notes(ada)))).toEqual([mine.id]);
|
|
103
|
-
});
|
|
104
|
-
it('sorts on createdBy, an implicit index with createdAt, and still refuses an unindexed sort', async () => {
|
|
105
|
-
const ada = await env.connect(ADA);
|
|
106
|
-
await notes(ada).create({ body: 'a' });
|
|
107
|
-
await notes(ada).create({ body: 'b' });
|
|
108
|
-
const sorted = await notes(ada).list({ orderBy: { field: 'createdBy' } });
|
|
109
|
-
expect(sorted.items).toHaveLength(2);
|
|
110
|
-
await expectError(notes(ada).list({ orderBy: { field: 'body' } }), 'VALIDATION');
|
|
111
|
-
});
|
|
112
|
-
it('gives NOT_AVAILABLE for everything under sdk.school, to accounts, guests and school personas alike', async () => {
|
|
113
|
-
const calls = (sdk) => [
|
|
114
|
-
() => sdk.school.info(),
|
|
115
|
-
() => sdk.school.students.list(),
|
|
116
|
-
() => sdk.school.students.get('stu-0001'),
|
|
117
|
-
() => sdk.school.students.parents('stu-0001'),
|
|
118
|
-
() => sdk.school.parents.children('par-0001'),
|
|
119
|
-
() => sdk.school.cohorts.byCode('y07'),
|
|
120
|
-
() => sdk.school.cohorts.members('coh-001'),
|
|
121
|
-
() => sdk.school.calendar.list({ from: '2026-01-01', to: '2026-12-31' }),
|
|
122
|
-
];
|
|
123
|
-
// The standalone app is previewed by a school persona of the same role name: still no school.
|
|
124
|
-
for (const who of school ? [ADA, CAI, GUEST1, STUDENT] : [ADA, CAI, GUEST1]) {
|
|
125
|
-
const sdk = await env.connect(who);
|
|
126
|
-
for (const call of calls(sdk))
|
|
127
|
-
await expectError(call(), 'NOT_AVAILABLE');
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
it('gives NOT_AVAILABLE for relationship recipients, school people and `regarding`', async () => {
|
|
131
|
-
const ada = await env.connect(ADA);
|
|
132
|
-
const send = (to) => ada.notify.send({ type: 'test.message', to, subject: 'S', body: 'B' });
|
|
133
|
-
await expectError(send(parentsOf('stu-0001')), 'NOT_AVAILABLE');
|
|
134
|
-
await expectError(send(staffOf('coh-001')), 'NOT_AVAILABLE');
|
|
135
|
-
await expectError(send(studentsOf('coh-001')), 'NOT_AVAILABLE');
|
|
136
|
-
await expectError(send({ person: 'stu-0001' }), 'NOT_AVAILABLE');
|
|
137
|
-
await expectError(ada.tasks.assign({ type: 'test.review', title: 'T', assignee: parentsOf('stu-0001') }), 'NOT_AVAILABLE');
|
|
138
|
-
await expectError(ada.tasks.assign({
|
|
139
|
-
type: 'test.review',
|
|
140
|
-
title: 'T',
|
|
141
|
-
assignee: { role: 'Student' },
|
|
142
|
-
regarding: { studentId: 'stu-0001' },
|
|
143
|
-
}), 'NOT_AVAILABLE');
|
|
144
|
-
});
|
|
145
|
-
it('notifies accounts by id and by app role, never guests, into the simulated outbox', async () => {
|
|
146
|
-
const ada = await env.connect(ADA);
|
|
147
|
-
await ada.notify.send({
|
|
148
|
-
type: 'test.message',
|
|
149
|
-
to: [{ role: 'Student' }],
|
|
150
|
-
subject: 'Hello',
|
|
151
|
-
body: 'B',
|
|
152
|
-
});
|
|
153
|
-
const outbox = await env.control.outbox();
|
|
154
|
-
expect(outbox.map((e) => e.recipientId).sort()).toEqual([
|
|
155
|
-
'acct:acc-ben',
|
|
156
|
-
'acct:acc-cai',
|
|
157
|
-
'acct:acc-dee',
|
|
158
|
-
]);
|
|
159
|
-
expect(outbox.every((e) => e.simulated && e.sentBy === 'acct:acc-ada')).toBe(true);
|
|
160
|
-
await env.control.reset();
|
|
161
|
-
await ada.notify.send({
|
|
162
|
-
type: 'test.message',
|
|
163
|
-
to: [{ account: 'acc-cai' }, { role: 'teacher' }],
|
|
164
|
-
subject: 'S',
|
|
165
|
-
body: 'B',
|
|
166
|
-
});
|
|
167
|
-
expect((await env.control.outbox()).map((e) => e.recipientId).sort()).toEqual([
|
|
168
|
-
'acct:acc-ada',
|
|
169
|
-
'acct:acc-ben',
|
|
170
|
-
'acct:acc-cai',
|
|
171
|
-
]);
|
|
172
|
-
await expectError(ada.notify.send({
|
|
173
|
-
type: 'test.message',
|
|
174
|
-
to: [{ account: 'acc-zed' }],
|
|
175
|
-
subject: 'S',
|
|
176
|
-
body: 'B',
|
|
177
|
-
}), 'VALIDATION');
|
|
178
|
-
await expectError(ada.notify.send({
|
|
179
|
-
type: 'test.message',
|
|
180
|
-
to: [{ role: 'Janitor' }],
|
|
181
|
-
subject: 'S',
|
|
182
|
-
body: 'B',
|
|
183
|
-
}), 'VALIDATION');
|
|
184
|
-
const guest = await env.connect(GUEST1);
|
|
185
|
-
await expectError(guest.notify.send({
|
|
186
|
-
type: 'test.message',
|
|
187
|
-
to: [{ role: 'Teacher' }],
|
|
188
|
-
subject: 'S',
|
|
189
|
-
body: 'B',
|
|
190
|
-
}), 'FORBIDDEN');
|
|
191
|
-
});
|
|
192
|
-
it('assigns tasks to accounts and app roles, completed only by an assignee', async () => {
|
|
193
|
-
const [ada, cai, dee, guest] = await Promise.all([ADA, CAI, DEE, GUEST1].map((p) => env.connect(p)));
|
|
194
|
-
const { tasks } = await ada.tasks.assign({
|
|
195
|
-
type: 'test.review',
|
|
196
|
-
title: 'Review your notes',
|
|
197
|
-
assignee: { role: 'Student' },
|
|
198
|
-
});
|
|
199
|
-
expect(tasks).toHaveLength(3);
|
|
200
|
-
expect((await env.control.inbox('acct:acc-cai')).map((t) => t.type)).toEqual([
|
|
201
|
-
'test.review',
|
|
202
|
-
]);
|
|
203
|
-
const mine = (await cai.tasks.list()).items;
|
|
204
|
-
expect(mine).toHaveLength(1);
|
|
205
|
-
expect(mine[0].assignedToMe).toBe(true);
|
|
206
|
-
// Dee isn't involved in Cai's task, so it isn't there for her at all.
|
|
207
|
-
const caisTask = tasks.find((t) => t.id === mine[0].id);
|
|
208
|
-
await expectError(dee.tasks.complete(caisTask.id), 'NOT_FOUND');
|
|
209
|
-
expect((await cai.tasks.complete(caisTask.id)).status).toBe('completed');
|
|
210
|
-
await expectError(guest.tasks.assign({ type: 'test.review', title: 'T', assignee: { account: 'acc-cai' } }), 'FORBIDDEN');
|
|
211
|
-
});
|
|
212
|
-
it('runs a job an account scheduled as that account, and lets no guest schedule one', async () => {
|
|
213
|
-
const ada = await env.connect(ADA);
|
|
214
|
-
await ada.schedule.at({ job: 'remind', when: '2026-03-04T00:00:00Z' });
|
|
215
|
-
const runs = await env.control.runDueJobs();
|
|
216
|
-
expect(runs.map((r) => [r.jobName, r.ok])).toEqual([['remind', true]]);
|
|
217
|
-
const [made] = (await listAll(notes(ada))).filter((n) => n.body.includes('"kind"'));
|
|
218
|
-
expect(JSON.parse(made.body)).toMatchObject({ kind: 'account', account: { id: 'acc-ada' } });
|
|
219
|
-
const guest = await env.connect(GUEST1);
|
|
220
|
-
await expectError(guest.schedule.at({ job: 'remind', when: '2026-03-05T00:00:00Z' }), 'FORBIDDEN');
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
defineStandaloneSections(() => env, useApp);
|
|
224
|
-
schoolDescribe('auth', () => {
|
|
38
|
+
describe('auth', () => {
|
|
225
39
|
useApp(TEST_APP);
|
|
226
40
|
it('returns the connected user', async () => {
|
|
227
41
|
const sdk = await env.connect(STAFF);
|
|
@@ -238,14 +52,14 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
238
52
|
},
|
|
239
53
|
});
|
|
240
54
|
expect(sdk.appId).toBe(TEST_APP.manifest.id);
|
|
241
|
-
expect(sdk.version).toBe('0.
|
|
55
|
+
expect(sdk.version).toBe('0.4.0');
|
|
242
56
|
});
|
|
243
57
|
it('knows parents and students', async () => {
|
|
244
58
|
expect((await (await env.connect(STUDENT)).auth.me()).role).toBe('student');
|
|
245
59
|
expect((await (await env.connect(SIBLINGS_PARENT)).auth.me()).role).toBe('parent');
|
|
246
60
|
});
|
|
247
61
|
});
|
|
248
|
-
|
|
62
|
+
describe('school: visibility (D4)', () => {
|
|
249
63
|
useApp(TEST_APP);
|
|
250
64
|
it('staff see every student', async () => {
|
|
251
65
|
const sdk = await env.connect(STAFF);
|
|
@@ -255,7 +69,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
255
69
|
const sdk = await env.connect(STUDENT);
|
|
256
70
|
expect(ids(await listAll(sdk.school.students))).toEqual([STUDENT.personId]);
|
|
257
71
|
expect((await listAll(sdk.school.parents)).length).toBe(0);
|
|
258
|
-
expect((await listAll(sdk.school.
|
|
72
|
+
expect((await listAll(sdk.school.medicalAlerts)).every((a) => a.studentId === STUDENT.personId)).toBe(true);
|
|
259
73
|
});
|
|
260
74
|
it('a parent sees only their own children', async () => {
|
|
261
75
|
const sdk = await env.connect(SIBLINGS_PARENT);
|
|
@@ -291,12 +105,13 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
291
105
|
expect(m.personId).toBe(studentId);
|
|
292
106
|
}
|
|
293
107
|
});
|
|
294
|
-
it('staff see
|
|
295
|
-
expect((await listAll((await env.connect(STAFF)).school.
|
|
296
|
-
|
|
108
|
+
it('staff see every medical alert; a parent sees only their own children’s', async () => {
|
|
109
|
+
expect((await listAll((await env.connect(STAFF)).school.medicalAlerts)).length).toBe(ds.medicalAlerts.length);
|
|
110
|
+
const kids = new Set(childrenOf(SIBLINGS_PARENT.personId));
|
|
111
|
+
expect(ids(await listAll((await env.connect(SIBLINGS_PARENT)).school.medicalAlerts))).toEqual(ids(ds.medicalAlerts.filter((a) => kids.has(a.studentId))));
|
|
297
112
|
});
|
|
298
113
|
});
|
|
299
|
-
|
|
114
|
+
describe('school: scopes and tiers (D5, D23)', () => {
|
|
300
115
|
describe('with only students.basic:read', () => {
|
|
301
116
|
useApp(BASIC_APP);
|
|
302
117
|
it('returns basic fields and leaves other tiers absent', async () => {
|
|
@@ -313,7 +128,6 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
313
128
|
const sdk = await env.connect(STAFF);
|
|
314
129
|
await expectError(sdk.school.parents.list(), 'SCOPE_NOT_GRANTED');
|
|
315
130
|
await expectError(sdk.school.medicalAlerts.get(ds.medicalAlerts[0].id), 'SCOPE_NOT_GRANTED');
|
|
316
|
-
await expectError(sdk.school.calendar.list({ from: '2026-01-01', to: '2027-01-01' }), 'SCOPE_NOT_GRANTED');
|
|
317
131
|
await expectError(sdk.school.sessionAttendance.list({ where: { date: '2026-03-03' } }), 'SCOPE_NOT_GRANTED');
|
|
318
132
|
});
|
|
319
133
|
it('still answers school.info', async () => {
|
|
@@ -354,7 +168,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
354
168
|
});
|
|
355
169
|
});
|
|
356
170
|
});
|
|
357
|
-
|
|
171
|
+
describe('app-defined roles are previewed by the persona of the same name (D84)', () => {
|
|
358
172
|
useApp(ROLES_APP);
|
|
359
173
|
it('serves the personas whose role matches an app role, ignoring case, and refuses the rest', async () => {
|
|
360
174
|
const staff = await env.connect(STAFF);
|
|
@@ -376,57 +190,15 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
376
190
|
await expectError(student.db.entity('entry').delete(note.id), 'NOT_PERMITTED');
|
|
377
191
|
});
|
|
378
192
|
});
|
|
379
|
-
|
|
380
|
-
useApp(DATA_APP);
|
|
381
|
-
it('returns the core fields and the declared ones, and nothing else that varies', async () => {
|
|
382
|
-
const sdk = await env.connect(STAFF);
|
|
383
|
-
const expected = ds.students[0];
|
|
384
|
-
const student = await sdk.school.students.get(expected.id);
|
|
385
|
-
expect(student.givenName).toBe(expected.givenName);
|
|
386
|
-
expect(student.studentNumber).toBe(expected.studentNumber);
|
|
387
|
-
expect(student.dateOfBirth).toBe(expected.dateOfBirth);
|
|
388
|
-
expect(student.email).toBe(expected.email);
|
|
389
|
-
// yearLevel and preferredName are granted by tier but were not declared.
|
|
390
|
-
expect('yearLevel' in student).toBe(false);
|
|
391
|
-
expect('preferredName' in student).toBe(false);
|
|
392
|
-
for (const s of (await sdk.school.students.list({ limit: 25 })).items) {
|
|
393
|
-
expect('yearLevel' in s).toBe(false);
|
|
394
|
-
expect('preferredName' in s).toBe(false);
|
|
395
|
-
expect('dateOfBirth' in s).toBe(true);
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
it('refuses to filter or sort on a field that was not declared, so it cannot be probed', async () => {
|
|
399
|
-
const sdk = await env.connect(STAFF);
|
|
400
|
-
await expectError(sdk.school.students.list({ where: { yearLevel: 'Y9' } }), 'VALIDATION');
|
|
401
|
-
await expectError(sdk.school.students.list({ orderBy: { field: 'preferredName' } }), 'VALIDATION');
|
|
402
|
-
// Declared and core fields still work.
|
|
403
|
-
const name = ds.students[0].familyName;
|
|
404
|
-
const found = await sdk.school.students.list({ where: { familyName: name }, limit: 200 });
|
|
405
|
-
expect(found.items.length).toBeGreaterThan(0);
|
|
406
|
-
expect((await sdk.school.students.list({ where: { dateOfBirth: ds.students[0].dateOfBirth } }))
|
|
407
|
-
.items.length).toBeGreaterThan(0);
|
|
408
|
-
});
|
|
409
|
-
it('strips included school refs the same way', async () => {
|
|
410
|
-
const sdk = await env.connect(STAFF);
|
|
411
|
-
await sdk.db
|
|
412
|
-
.entity('greeting')
|
|
413
|
-
.create({ message: 'hi', studentId: ds.students[0].id, tone: 'warm' });
|
|
414
|
-
const { items } = await sdk.db.entity('greeting').list({ include: ['studentId'] });
|
|
415
|
-
const included = items[0].$included.studentId;
|
|
416
|
-
expect(included.givenName).toBe(ds.students[0].givenName);
|
|
417
|
-
expect('yearLevel' in included).toBe(false);
|
|
418
|
-
expect('dateOfBirth' in included).toBe(true);
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
schoolDescribe('school: no declaration (version 0) still gives every field of the granted tiers', () => {
|
|
193
|
+
describe('school: every field of the granted tiers, with no declaration (D103)', () => {
|
|
422
194
|
useApp(BASIC_APP);
|
|
423
|
-
it('
|
|
195
|
+
it('gives yearLevel with the basic tier', async () => {
|
|
424
196
|
const student = (await (await env.connect(STAFF)).school.students.list({ limit: 1 }))
|
|
425
197
|
.items[0];
|
|
426
198
|
expect('yearLevel' in student).toBe(true);
|
|
427
199
|
});
|
|
428
200
|
});
|
|
429
|
-
|
|
201
|
+
describe('school: queries and helpers', () => {
|
|
430
202
|
useApp(TEST_APP);
|
|
431
203
|
it('filters with where, orders and pages without gaps or repeats', async () => {
|
|
432
204
|
const sdk = await env.connect(STAFF);
|
|
@@ -557,7 +329,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
557
329
|
where: { date: '2026-03-03', code: 'late' },
|
|
558
330
|
});
|
|
559
331
|
expect(late.length).toBeGreaterThan(0);
|
|
560
|
-
expect(late.every((m) => m.code === 'late'
|
|
332
|
+
expect(late.every((m) => m.code === 'late')).toBe(true);
|
|
561
333
|
}, 30_000);
|
|
562
334
|
it('pages through a register without gaps or repeats, and finds one mark by id', async () => {
|
|
563
335
|
const staff = await env.connect(STAFF);
|
|
@@ -598,274 +370,49 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
598
370
|
expect(new Set(parent.map((m) => m.studentId))).toEqual(new Set(kids));
|
|
599
371
|
expect(await listAll((await env.connect(RESTRICTED_PARENT)).school.sessionAttendance, day)).toEqual([]);
|
|
600
372
|
});
|
|
601
|
-
it('
|
|
602
|
-
const staff = await env.connect(STAFF);
|
|
603
|
-
const withComments = await listAll(staff.school.sessionAttendance, {
|
|
604
|
-
where: { studentId: ds.students[3].id },
|
|
605
|
-
});
|
|
606
|
-
expect(withComments.some((m) => typeof m.comment === 'string')).toBe(true);
|
|
607
|
-
const log = await env.control.auditLog();
|
|
608
|
-
const reads = log.filter((e) => e.action === 'school.sensitive-read' && e.entity === 'sessionAttendance');
|
|
609
|
-
expect(reads.length).toBeGreaterThan(0);
|
|
610
|
-
expect(reads[0].data.tiers).toEqual(['pastoral']);
|
|
611
|
-
});
|
|
612
|
-
it('serves absences and term summaries, each student’s own', async () => {
|
|
613
|
-
const staff = await env.connect(STAFF);
|
|
614
|
-
const mine = await listAll((await env.connect(STUDENT)).school.attendanceSummaries);
|
|
615
|
-
expect(mine).toHaveLength(4);
|
|
616
|
-
expect(mine.every((s) => s.studentId === STUDENT.personId)).toBe(true);
|
|
617
|
-
expect(mine[0]).toMatchObject({
|
|
618
|
-
possibleMarks: expect.any(Number),
|
|
619
|
-
presentMarks: expect.any(Number),
|
|
620
|
-
});
|
|
621
|
-
const all = await listAll(staff.school.attendanceSummaries, {
|
|
622
|
-
where: { termName: 'Term 1' },
|
|
623
|
-
});
|
|
624
|
-
expect(all).toHaveLength(ds.students.length);
|
|
625
|
-
const absences = await listAll(staff.school.studentAbsences, {
|
|
626
|
-
where: { studentId: ds.students[0].id },
|
|
627
|
-
});
|
|
628
|
-
expect(absences.length).toBeGreaterThan(0);
|
|
629
|
-
// The reason is pastoral, and this app was not granted that tier.
|
|
630
|
-
expect(absences.every((a) => a.endAt > a.startAt && !('reason' in a) && !('comment' in a))).toBe(true);
|
|
631
|
-
const own = await listAll((await env.connect(SIBLINGS_PARENT)).school.studentAbsences);
|
|
632
|
-
expect(new Set(own.map((a) => a.studentId))).toEqual(new Set(childrenOf(SIBLINGS_PARENT.personId)));
|
|
633
|
-
}, 30_000);
|
|
634
|
-
it('serves behaviour incidents and achievements, each student’s own (S4.3)', async () => {
|
|
635
|
-
const staff = await env.connect(STAFF);
|
|
636
|
-
const mine = ds.behaviours.find((b) => b.studentId !== STUDENT.personId);
|
|
637
|
-
const incidents = await listAll(staff.school.behaviours, {
|
|
638
|
-
where: { studentId: mine.studentId },
|
|
639
|
-
});
|
|
640
|
-
expect(incidents.length).toBeGreaterThan(0);
|
|
641
|
-
expect(incidents.every((b) => b.studentId === mine.studentId && b.points < 0)).toBe(true);
|
|
642
|
-
expect(incidents[0]).toMatchObject({
|
|
643
|
-
incident: expect.any(String),
|
|
644
|
-
date: expect.any(String),
|
|
645
|
-
});
|
|
646
|
-
const own = await listAll((await env.connect(STUDENT)).school.behaviours);
|
|
647
|
-
expect(own.every((b) => b.studentId === STUDENT.personId)).toBe(true);
|
|
648
|
-
expect(own).toHaveLength(ds.behaviours.filter((b) => b.studentId === STUDENT.personId).length);
|
|
649
|
-
const kids = new Set(childrenOf(SIBLINGS_PARENT.personId));
|
|
650
|
-
const family = await listAll((await env.connect(SIBLINGS_PARENT)).school.behaviours);
|
|
651
|
-
expect(family.every((b) => kids.has(b.studentId))).toBe(true);
|
|
652
|
-
expect(family).toHaveLength(ds.behaviours.filter((b) => kids.has(b.studentId)).length);
|
|
653
|
-
expect(await listAll((await env.connect(RESTRICTED_PARENT)).school.behaviours)).toEqual([]);
|
|
654
|
-
await expectError((await env.connect(STUDENT)).school.behaviours.get(mine.id), 'NOT_FOUND');
|
|
655
|
-
const awards = await listAll((await env.connect(STUDENT)).school.achievements);
|
|
656
|
-
expect(awards).toHaveLength(ds.achievements.filter((a) => a.studentId === STUDENT.personId).length);
|
|
657
|
-
expect(awards.every((a) => a.points > 0 && typeof a.type === 'string')).toBe(true);
|
|
658
|
-
const all = await listAll(staff.school.achievements, { where: { type: 'Sport' } });
|
|
659
|
-
expect(all).toHaveLength(ds.achievements.filter((a) => a.type === 'Sport').length);
|
|
660
|
-
}, 30_000);
|
|
661
|
-
it('audits behaviour reads, which are pastoral, but not achievements, which are academic (S4.3, D19)', async () => {
|
|
662
|
-
const staff = await env.connect(STAFF);
|
|
663
|
-
await staff.school.behaviours.list({ limit: 4 });
|
|
664
|
-
await staff.school.achievements.list({ limit: 4 });
|
|
665
|
-
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read' &&
|
|
666
|
-
['behaviours', 'achievements'].includes(String(e.entity)));
|
|
667
|
-
expect(reads.map((e) => [e.entity, e.data.tiers])).toEqual([['behaviours', ['pastoral']]]);
|
|
668
|
-
});
|
|
669
|
-
describe('an awards app with no pastoral scope', () => {
|
|
670
|
-
useApp(AWARDS_APP);
|
|
671
|
-
it('reads achievements but not behaviour, and leaves no pastoral audit entry', async () => {
|
|
672
|
-
const sdk = await env.connect(STAFF);
|
|
673
|
-
const { items } = await sdk.school.achievements.list({ limit: 5 });
|
|
674
|
-
expect(items).toHaveLength(5);
|
|
675
|
-
await expectError(sdk.school.behaviours.list(), 'SCOPE_NOT_GRANTED');
|
|
676
|
-
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read');
|
|
677
|
-
expect(reads).toEqual([]);
|
|
678
|
-
});
|
|
679
|
-
});
|
|
680
|
-
it('leaves the diagnosis out of learning support when only the pastoral tier is granted (S4.4)', async () => {
|
|
373
|
+
it('refuses medical notes to an app without the scope', async () => {
|
|
681
374
|
const staff = await env.connect(STAFF);
|
|
682
|
-
const withNeed = ds.learningSupportNeeds[0];
|
|
683
|
-
const items = await listAll(staff.school.learningSupportNeeds, {
|
|
684
|
-
where: { studentId: withNeed.studentId },
|
|
685
|
-
});
|
|
686
|
-
expect(items.length).toBeGreaterThan(0);
|
|
687
|
-
expect(items[0]).toMatchObject({ category: expect.any(String), level: expect.any(String) });
|
|
688
|
-
expect(items.every((n) => !('need' in n))).toBe(true);
|
|
689
|
-
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read' && e.entity === 'learningSupportNeeds');
|
|
690
|
-
expect(reads.map((e) => e.data.tiers)).toEqual([['pastoral']]);
|
|
691
|
-
await expectError(staff.school.medicalEvents.list(), 'SCOPE_NOT_GRANTED');
|
|
692
375
|
await expectError(staff.school.medicalNotes.list(), 'SCOPE_NOT_GRANTED');
|
|
693
376
|
});
|
|
694
|
-
describe('a
|
|
695
|
-
useApp(
|
|
696
|
-
it('
|
|
697
|
-
const staff = await env.connect(STAFF);
|
|
698
|
-
const withNeed = ds.learningSupportNeeds[0];
|
|
699
|
-
const items = await listAll(staff.school.learningSupportNeeds, {
|
|
700
|
-
where: { studentId: withNeed.studentId },
|
|
701
|
-
});
|
|
702
|
-
expect(items.some((n) => n.need === withNeed.need && n.category === withNeed.category)).toBe(true);
|
|
703
|
-
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read' && e.entity === 'learningSupportNeeds');
|
|
704
|
-
expect([...reads[0].data.tiers].sort()).toEqual(['medical', 'pastoral']);
|
|
705
|
-
});
|
|
706
|
-
it('serves medical events and the notes that link to them, each student’s own', async () => {
|
|
377
|
+
describe('a first-aid app with the medical tier (D103)', () => {
|
|
378
|
+
useApp(MEDICAL_APP);
|
|
379
|
+
it('reads alerts and the notes about them, and the audit records the medical tier', async () => {
|
|
707
380
|
const staff = await env.connect(STAFF);
|
|
708
|
-
const
|
|
709
|
-
const
|
|
710
|
-
where: { studentId:
|
|
711
|
-
});
|
|
712
|
-
expect(events.find((e) => e.id === event.id)).toMatchObject({
|
|
713
|
-
type: event.type,
|
|
714
|
-
followUpDate: event.followUpDate,
|
|
381
|
+
const alert = ds.medicalAlerts[0];
|
|
382
|
+
const alerts = await listAll(staff.school.medicalAlerts, {
|
|
383
|
+
where: { studentId: alert.studentId },
|
|
715
384
|
});
|
|
385
|
+
expect(alerts.some((a) => a.condition === alert.condition)).toBe(true);
|
|
716
386
|
const notes = await listAll(staff.school.medicalNotes, {
|
|
717
|
-
where: { studentId:
|
|
387
|
+
where: { studentId: alert.studentId },
|
|
718
388
|
});
|
|
719
|
-
expect(notes.
|
|
720
|
-
expect(notes.every((n) =>
|
|
389
|
+
expect(notes.length).toBeGreaterThan(0);
|
|
390
|
+
expect(notes.every((n) => typeof n.note === 'string')).toBe(true);
|
|
391
|
+
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read' &&
|
|
392
|
+
['medicalAlerts', 'medicalNotes'].includes(String(e.entity)));
|
|
393
|
+
expect(reads.length).toBeGreaterThan(0);
|
|
394
|
+
expect(reads.every((e) => e.data.tiers.includes('medical'))).toBe(true);
|
|
395
|
+
});
|
|
396
|
+
it('gives a student or a parent only their own, and nothing to a restricted parent', async () => {
|
|
721
397
|
const student = await env.connect(STUDENT);
|
|
398
|
+
const kids = new Set(childrenOf(SIBLINGS_PARENT.personId));
|
|
722
399
|
for (const [entity, all] of [
|
|
723
|
-
['
|
|
724
|
-
['medicalEvents', ds.medicalEvents],
|
|
400
|
+
['medicalAlerts', ds.medicalAlerts],
|
|
725
401
|
['medicalNotes', ds.medicalNotes],
|
|
726
402
|
]) {
|
|
727
403
|
const own = await listAll(student.school[entity]);
|
|
728
404
|
expect(own, entity).toHaveLength(all.filter((r) => r.studentId === STUDENT.personId).length);
|
|
729
405
|
expect(own.every((r) => r.studentId === STUDENT.personId)).toBe(true);
|
|
730
|
-
const kids = new Set(childrenOf(SIBLINGS_PARENT.personId));
|
|
731
406
|
const family = await listAll((await env.connect(SIBLINGS_PARENT)).school[entity]);
|
|
732
407
|
expect(family, entity).toHaveLength(all.filter((r) => kids.has(r.studentId)).length);
|
|
733
408
|
expect(await listAll((await env.connect(RESTRICTED_PARENT)).school[entity])).toEqual([]);
|
|
734
409
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
});
|
|
738
|
-
describe('demographics: the sensitive tier is staff-only (S4.5, D88)', () => {
|
|
739
|
-
useApp(DEMOGRAPHICS_APP);
|
|
740
|
-
const SENSITIVE = [
|
|
741
|
-
'firstLanguage',
|
|
742
|
-
'englishAsAdditionalLanguage',
|
|
743
|
-
'ethnicity',
|
|
744
|
-
'nationality',
|
|
745
|
-
'religion',
|
|
746
|
-
'birthPlace',
|
|
747
|
-
'freeSchoolMeals',
|
|
748
|
-
];
|
|
749
|
-
const leaks = (value) => JSON.stringify(value) !== undefined &&
|
|
750
|
-
SENSITIVE.filter((k) => JSON.stringify(value).includes(`"${k}"`));
|
|
751
|
-
it('gives staff the fields the app asked for, lets them filter on one, and audits the read', async () => {
|
|
752
|
-
const staff = await env.connect(STAFF);
|
|
753
|
-
const some = ds.students.find((s) => s.religion && s.firstLanguage);
|
|
754
|
-
const one = await staff.school.students.get(some.id);
|
|
755
|
-
expect(one).toMatchObject({ religion: some.religion, firstLanguage: some.firstLanguage });
|
|
756
|
-
const catholic = await listAll(staff.school.students, { where: { religion: 'Catholic' } });
|
|
757
|
-
expect(catholic).toHaveLength(ds.students.filter((s) => s.religion === 'Catholic').length);
|
|
758
|
-
expect(catholic.length).toBeGreaterThan(20);
|
|
759
|
-
const eal = await listAll(staff.school.students, {
|
|
760
|
-
where: { englishAsAdditionalLanguage: true },
|
|
761
|
-
});
|
|
762
|
-
expect(eal.every((s) => s.englishAsAdditionalLanguage === true)).toBe(true);
|
|
763
|
-
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read' && e.entity === 'students');
|
|
764
|
-
expect(reads.length).toBeGreaterThan(0);
|
|
765
|
-
expect(reads.every((e) => e.data.tiers.includes('sensitive'))).toBe(true);
|
|
410
|
+
const other = ds.medicalAlerts.find((a) => a.studentId !== STUDENT.personId);
|
|
411
|
+
await expectError(student.school.medicalAlerts.get(other.id), 'NOT_FOUND');
|
|
766
412
|
});
|
|
767
|
-
it('never gives a student or a parent the fields, and refuses a filter that would probe them', async () => {
|
|
768
|
-
for (const who of [STUDENT, SIBLINGS_PARENT, SEPARATED_PARENT]) {
|
|
769
|
-
const sdk = await env.connect(who);
|
|
770
|
-
const mine = await listAll(sdk.school.students);
|
|
771
|
-
expect(mine.length).toBeGreaterThan(0);
|
|
772
|
-
expect(leaks(mine), who.personId).toEqual([]);
|
|
773
|
-
expect(leaks(await sdk.school.students.get(mine[0].id))).toEqual([]);
|
|
774
|
-
await expectError(sdk.school.students.list({ where: { religion: 'Catholic' } }), 'VALIDATION');
|
|
775
|
-
await expectError(sdk.school.students.list({ orderBy: { field: 'ethnicity' } }), 'VALIDATION');
|
|
776
|
-
}
|
|
777
|
-
});
|
|
778
|
-
it('does not leak them through the helpers that return students or parents', async () => {
|
|
779
|
-
const kids = childrenOf(SIBLINGS_PARENT.personId);
|
|
780
|
-
const parent = await env.connect(SIBLINGS_PARENT);
|
|
781
|
-
expect(leaks(await parent.school.parents.children(SIBLINGS_PARENT.personId))).toEqual([]);
|
|
782
|
-
expect(leaks(await parent.school.students.parents(kids[0]))).toEqual([]);
|
|
783
|
-
const student = await env.connect(STUDENT);
|
|
784
|
-
expect(leaks(await student.school.students.parents(STUDENT.personId))).toEqual([]);
|
|
785
|
-
expect(leaks(await student.auth.me())).toEqual([]);
|
|
786
|
-
const staff = await env.connect(STAFF);
|
|
787
|
-
// Staff with the scope get them for a parent's children too: the tier is for staff.
|
|
788
|
-
const children = await staff.school.parents.children(SIBLINGS_PARENT.personId);
|
|
789
|
-
expect(children.some((c) => SENSITIVE.some((k) => k in c))).toBe(true);
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
it('never gives the fields to an app that was not granted the tier', async () => {
|
|
793
|
-
const staff = await env.connect(STAFF);
|
|
794
|
-
const students = await listAll(staff.school.students, { where: { yearLevel: 'Y9' } });
|
|
795
|
-
expect(students.length).toBeGreaterThan(0);
|
|
796
|
-
expect(JSON.stringify(students)).not.toMatch(/"(religion|ethnicity|nationality|firstLanguage|birthPlace)"/);
|
|
797
|
-
await expectError(staff.school.students.list({ where: { religion: 'Catholic' } }), 'VALIDATION');
|
|
798
|
-
});
|
|
799
|
-
describe('staff absences are in the hr tier (S4.6)', () => {
|
|
800
|
-
useApp(HR_APP);
|
|
801
|
-
it('are read by any staff member whose app holds the tier, and audited as hr', async () => {
|
|
802
|
-
for (const who of [STAFF, DEPUTY]) {
|
|
803
|
-
const sdk = await env.connect(who);
|
|
804
|
-
const all = await listAll(sdk.school.employeeAbsences);
|
|
805
|
-
expect(all).toHaveLength(ds.employeeAbsences.length);
|
|
806
|
-
expect(all[0]).toMatchObject({
|
|
807
|
-
staffId: expect.any(String),
|
|
808
|
-
absenceType: expect.any(String),
|
|
809
|
-
workingDays: expect.any(Number),
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
const sdk = await env.connect(STAFF);
|
|
813
|
-
const sick = await listAll(sdk.school.employeeAbsences, {
|
|
814
|
-
where: { absenceType: 'Sick leave' },
|
|
815
|
-
});
|
|
816
|
-
expect(sick).toHaveLength(ds.employeeAbsences.filter((a) => a.absenceType === 'Sick leave').length);
|
|
817
|
-
expect(sick.every((a) => typeof a.illnessCategory === 'string')).toBe(true);
|
|
818
|
-
const reads = (await env.control.auditLog()).filter((e) => e.action === 'school.sensitive-read' && e.entity === 'employeeAbsences');
|
|
819
|
-
expect(reads.length).toBeGreaterThan(0);
|
|
820
|
-
expect(reads.every((e) => e.data.tiers.includes('hr'))).toBe(true);
|
|
821
|
-
});
|
|
822
|
-
it('are never given to a student or a parent, however they ask', async () => {
|
|
823
|
-
const one = ds.employeeAbsences[0];
|
|
824
|
-
for (const who of [STUDENT, SIBLINGS_PARENT, SEPARATED_PARENT, RESTRICTED_PARENT]) {
|
|
825
|
-
const sdk = await env.connect(who);
|
|
826
|
-
expect(await listAll(sdk.school.employeeAbsences)).toEqual([]);
|
|
827
|
-
await expectError(sdk.school.employeeAbsences.get(one.id), 'NOT_FOUND');
|
|
828
|
-
await expectError(sdk.school.employeeAbsences.list({ where: { absenceType: 'Sick leave' } }), 'VALIDATION');
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
});
|
|
832
|
-
it('refuses staff absences to an app that was not granted the tier', async () => {
|
|
833
|
-
const staff = await env.connect(STAFF);
|
|
834
|
-
await expectError(staff.school.employeeAbsences.list(), 'SCOPE_NOT_GRANTED');
|
|
835
|
-
});
|
|
836
|
-
it('serves admissions applicants to staff only, in the contact tier (S4.6)', async () => {
|
|
837
|
-
const staff = await env.connect(STAFF);
|
|
838
|
-
const all = await listAll(staff.school.applicants);
|
|
839
|
-
expect(all).toHaveLength(ds.applicants.length);
|
|
840
|
-
expect(all[0]).toMatchObject({
|
|
841
|
-
givenName: expect.any(String),
|
|
842
|
-
email: expect.any(String),
|
|
843
|
-
status: expect.any(String),
|
|
844
|
-
});
|
|
845
|
-
const offered = await listAll(staff.school.applicants, { where: { status: 'offered' } });
|
|
846
|
-
expect(offered).toHaveLength(ds.applicants.filter((a) => a.status === 'offered').length);
|
|
847
|
-
const sibling = ds.applicants.find((a) => a.siblingId);
|
|
848
|
-
expect((await staff.school.applicants.get(sibling.id)).siblingId).toBe(sibling.siblingId);
|
|
849
|
-
for (const who of [STUDENT, SIBLINGS_PARENT, RESTRICTED_PARENT]) {
|
|
850
|
-
const sdk = await env.connect(who);
|
|
851
|
-
expect(await listAll(sdk.school.applicants)).toEqual([]);
|
|
852
|
-
await expectError(sdk.school.applicants.get(sibling.id), 'NOT_FOUND');
|
|
853
|
-
}
|
|
854
|
-
});
|
|
855
|
-
it('lists calendar events in a date range', async () => {
|
|
856
|
-
const sdk = await env.connect(STAFF);
|
|
857
|
-
const from = '2026-03-01T00:00:00Z';
|
|
858
|
-
const to = '2026-04-01T00:00:00Z';
|
|
859
|
-
const events = await sdk.school.calendar.list({ from, to });
|
|
860
|
-
const expected = ds.calendarEvents.filter((e) => e.start < to && e.end > from);
|
|
861
|
-
expect(ids(events)).toEqual(ids(expected));
|
|
862
|
-
const y7 = await sdk.school.cohorts.byCode('y07');
|
|
863
|
-
const forY7 = await sdk.school.calendar.list({ from, to, cohortId: y7.id });
|
|
864
|
-
expect(forY7.every((e) => e.cohortIds.length === 0 || e.cohortIds.includes(y7.id))).toBe(true);
|
|
865
|
-
expect(forY7.some((e) => e.title === 'Year 7 camp')).toBe(true);
|
|
866
413
|
});
|
|
867
414
|
});
|
|
868
|
-
|
|
415
|
+
describe('db', () => {
|
|
869
416
|
useApp(TEST_APP);
|
|
870
417
|
const studentId = ds.students[0].id;
|
|
871
418
|
it('creates, reads, updates and deletes records with system fields', async () => {
|
|
@@ -1049,7 +596,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1049
596
|
expect((await (await env.connect(STAFF)).db.entity('greeting').list()).items).toEqual([]);
|
|
1050
597
|
});
|
|
1051
598
|
});
|
|
1052
|
-
|
|
599
|
+
describe('db access control (D25)', () => {
|
|
1053
600
|
useApp(ACCESS_APP);
|
|
1054
601
|
const myChild = () => childrenOf(SIBLINGS_PARENT.personId)[0];
|
|
1055
602
|
const otherChild = () => ds.students.find((s) => !childrenOf(SIBLINGS_PARENT.personId).includes(s.id) &&
|
|
@@ -1213,7 +760,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1213
760
|
expect((await system.db.entity('consent').list()).items).toHaveLength(1);
|
|
1214
761
|
});
|
|
1215
762
|
});
|
|
1216
|
-
|
|
763
|
+
describe('notify (D10, D17)', () => {
|
|
1217
764
|
useApp(TEST_APP);
|
|
1218
765
|
const message = { type: 'test.message', subject: 'Hello', body: 'Body text' };
|
|
1219
766
|
it('delivers to the simulated outbox only', async () => {
|
|
@@ -1324,7 +871,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1324
871
|
await expectError(sdk.notify.send({ ...message, to: { role: 'staff' }, subject: '' }), 'VALIDATION');
|
|
1325
872
|
});
|
|
1326
873
|
});
|
|
1327
|
-
|
|
874
|
+
describe('notify: roles outside the manifest', () => {
|
|
1328
875
|
useApp({
|
|
1329
876
|
...TEST_APP,
|
|
1330
877
|
manifest: { ...TEST_APP.manifest, id: 'staff-only', roles: ['staff'] },
|
|
@@ -1359,7 +906,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1359
906
|
};
|
|
1360
907
|
const SYSTEM_JOBS = { kind: 'system', appId: 'contract-jobs' };
|
|
1361
908
|
const approval = { type: 'test.approval', title: 'Approve the excursion' };
|
|
1362
|
-
|
|
909
|
+
describe('tasks (D6)', () => {
|
|
1363
910
|
useApp(JOBS_APP);
|
|
1364
911
|
it("mode 'each' gives every assignee their own task and inbox entry", async () => {
|
|
1365
912
|
const sdk = await env.connect(STAFF);
|
|
@@ -1395,7 +942,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1395
942
|
await sdk.tasks.assign({ ...approval, assignee: staffOf(team.id), mode: 'any' });
|
|
1396
943
|
const deputies = new Set(teamMembers('deputy-principal'));
|
|
1397
944
|
for (const s of ds.staff) {
|
|
1398
|
-
expect((await env.control.inbox(s.id)).length, s.
|
|
945
|
+
expect((await env.control.inbox(s.id)).length, s.id).toBe(deputies.has(s.id) ? 1 : 0);
|
|
1399
946
|
}
|
|
1400
947
|
});
|
|
1401
948
|
it('permission slips never reach a restricted or non-consenting parent (D17)', async () => {
|
|
@@ -1536,7 +1083,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1536
1083
|
expect((await (await env.connect(STAFF)).tasks.get(tasks[0].id)).regardingStudentId).toBe(childrenOf(SIBLINGS_PARENT.personId)[0]);
|
|
1537
1084
|
});
|
|
1538
1085
|
});
|
|
1539
|
-
|
|
1086
|
+
describe('schedule and cron (D7, D8, D20)', () => {
|
|
1540
1087
|
useApp(JOBS_APP);
|
|
1541
1088
|
const logs = async () => (await (await env.connect(STAFF)).db.entity('jobLog').list({ limit: 200 })).items;
|
|
1542
1089
|
it('runs a scheduled job at its time, not before, as the user who scheduled it (D7)', async () => {
|
|
@@ -1722,7 +1269,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1722
1269
|
expect((await env.control.auditLog()).some((e) => e.action === 'job.redelivered')).toBe(true);
|
|
1723
1270
|
});
|
|
1724
1271
|
});
|
|
1725
|
-
|
|
1272
|
+
describe('audit (D19)', () => {
|
|
1726
1273
|
useApp({
|
|
1727
1274
|
...JOBS_APP,
|
|
1728
1275
|
manifest: { ...JOBS_APP.manifest, scopes: [...TEST_APP.manifest.scopes] },
|
|
@@ -1782,7 +1329,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1782
1329
|
await env.control.runDueJobs();
|
|
1783
1330
|
await staff.school.students.list({ limit: 5 }); // basic: no sensitive-read entry
|
|
1784
1331
|
await staff.school.medicalAlerts.list({ limit: 3 });
|
|
1785
|
-
await staff.school.
|
|
1332
|
+
await staff.school.medicalAlerts.get(ds.medicalAlerts[0].id);
|
|
1786
1333
|
const log = await env.control.auditLog();
|
|
1787
1334
|
const actions = log.map((e) => e.action);
|
|
1788
1335
|
for (const a of [
|
|
@@ -1798,7 +1345,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1798
1345
|
const reads = log.filter((e) => e.action === 'school.sensitive-read');
|
|
1799
1346
|
expect(reads.map((e) => [e.entity, e.data.recordCount, e.visibility])).toEqual([
|
|
1800
1347
|
['medicalAlerts', 3, 'cio'],
|
|
1801
|
-
['
|
|
1348
|
+
['medicalAlerts', 1, 'cio'],
|
|
1802
1349
|
]);
|
|
1803
1350
|
const suppressed = log.find((e) => e.action === 'notification.suppressed');
|
|
1804
1351
|
expect(suppressed).toMatchObject({
|
|
@@ -1863,7 +1410,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1863
1410
|
expect(same).toEqual(entry);
|
|
1864
1411
|
});
|
|
1865
1412
|
});
|
|
1866
|
-
|
|
1413
|
+
describe('clock controls (D14)', () => {
|
|
1867
1414
|
useApp(TEST_APP);
|
|
1868
1415
|
it('advances a frozen clock', async () => {
|
|
1869
1416
|
await env.control.setClock('2026-03-04T00:00:00.000Z');
|
|
@@ -1871,7 +1418,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1871
1418
|
expect((await env.connect(STAFF)).clock.now()).toBe('2026-03-05T00:00:00.000Z');
|
|
1872
1419
|
});
|
|
1873
1420
|
});
|
|
1874
|
-
|
|
1421
|
+
describe('clock (D14, D21)', () => {
|
|
1875
1422
|
useApp(TEST_APP);
|
|
1876
1423
|
it('follows the engine clock', async () => {
|
|
1877
1424
|
await env.control.setClock('2026-03-04T14:30:00.000Z');
|