@aerokit/sdk 14.1.1 → 14.3.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/package.json +1 -1
- package/test/flows/my.js +148 -0
- package/test/index.js +2 -0
package/package.json
CHANGED
package/test/flows/my.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { makeApi } from '../api.js';
|
|
2
|
+
import { expect, test } from '../fixtures.js';
|
|
3
|
+
import { resolveRelationSamples } from '../form.js';
|
|
4
|
+
import { sampleRecord } from '../sample-values.js';
|
|
5
|
+
|
|
6
|
+
// Wave 2 (UI parity): the personal PAGE renders what the wire serves. Driven by the same
|
|
7
|
+
// own-row lifecycle as the wire test (created through the scoped controller, removed in the
|
|
8
|
+
// finally); skips without an identity mapping, exactly like the wire flow.
|
|
9
|
+
// - layout 'list': every relation column of the own row shows its referenced LABEL - the
|
|
10
|
+
// raw-FK-id regression class the personal templates fixed;
|
|
11
|
+
// - layout 'calendar'/'slots': the personal route renders the calendar / slot picker, never a
|
|
12
|
+
// plain form+list downgrade;
|
|
13
|
+
// - layout 'document-chat': the composer accepts a message and the bubble renders (the my
|
|
14
|
+
// document chat parity class). A plain 'document' asserts the page serves.
|
|
15
|
+
function myUiTest(manifest, entity, mine, buildContext, idProperty) {
|
|
16
|
+
test(`${entity.name}: the My page renders the own record with resolved labels (UI parity)`, async ({ api, page }) => {
|
|
17
|
+
const { payload, samples } = await buildContext(api);
|
|
18
|
+
const createdResponse = await api.post(manifest.restBase + mine.api, { data: payload });
|
|
19
|
+
test.skip(
|
|
20
|
+
!createdResponse.ok(),
|
|
21
|
+
`personal create returned ${createdResponse.status()} - the test user has no identity mapping; ` +
|
|
22
|
+
`seed the dev identity row (an owner-target record whose identity field equals the login user)`
|
|
23
|
+
);
|
|
24
|
+
const created = JSON.parse(await createdResponse.text());
|
|
25
|
+
const id = created?.[idProperty];
|
|
26
|
+
const client = makeApi(api, manifest);
|
|
27
|
+
try {
|
|
28
|
+
const layout = entity.personal.layout ?? 'list';
|
|
29
|
+
if (layout === 'calendar' || layout === 'slots') {
|
|
30
|
+
await page.goto(manifest.standaloneShell + entity.personal.route);
|
|
31
|
+
await expect(page.locator('[x-h-calendar], [x-h-slot-picker]').first()).toBeVisible();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (layout === 'document-chat' || layout === 'document') {
|
|
35
|
+
await page.goto(manifest.standaloneShell + entity.personal.route + '/' + id + '/edit');
|
|
36
|
+
if (layout === 'document-chat') {
|
|
37
|
+
const message = `UI parity probe ${id}`;
|
|
38
|
+
const composer = page.getByRole('textbox', { name: /write a message/i }).first();
|
|
39
|
+
await composer.fill(message);
|
|
40
|
+
await page.getByRole('button', { name: /send/i }).first().click();
|
|
41
|
+
await expect(page.getByText(message).first(), 'the sent message must render as a bubble').toBeVisible();
|
|
42
|
+
} else {
|
|
43
|
+
await expect(page.locator('[x-h-toolbar-title]').first()).toBeVisible();
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// list: the own rows are the only rows - every asserted relation column of the created
|
|
48
|
+
// row must surface its referenced label somewhere in the table body
|
|
49
|
+
await page.goto(manifest.standaloneShell + entity.personal.route);
|
|
50
|
+
await expect(page.locator('tbody tr:visible').first()).toBeVisible();
|
|
51
|
+
const fkColumns = new Set(entity.personal.fkColumns ?? []);
|
|
52
|
+
for (const sample of samples) {
|
|
53
|
+
if (!fkColumns.has(sample.relation.name) || sample.label == null) continue;
|
|
54
|
+
await expect(
|
|
55
|
+
page.locator('tbody').getByText(String(sample.label)).first(),
|
|
56
|
+
`${sample.relation.name} must render its referenced label ("${sample.label}"), not the raw id ${sample.id}`
|
|
57
|
+
).toBeVisible();
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
await client.remove(mine, id);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The personal (my) surface WIRE contract, driven when the manifest marks an entity `personal`:
|
|
66
|
+
// the scoped <Entity>MyController filters reads to the identity-mapped user, forces the owner FK
|
|
67
|
+
// server-side on create (whatever the client sends is ignored), strips every `sensitive` field
|
|
68
|
+
// from its responses (the allow-list is the security boundary - UI hiding alone is cosmetic),
|
|
69
|
+
// serves foreign rows as 404, and deletes only own rows.
|
|
70
|
+
//
|
|
71
|
+
// Prerequisite: the DEV IDENTITY mapping - a row of the owner relation's target whose identity
|
|
72
|
+
// field equals the test user (e.g. an Employee with email 'admin'). Without it the personal
|
|
73
|
+
// surface is EMPTY by design (never an error), so the flow SKIPS with a pointer instead of
|
|
74
|
+
// failing. Wave 2 (myUiTest below) walks the personal PAGE over the same own-row lifecycle:
|
|
75
|
+
// resolved relation labels on the list, calendar/slots rendering, the chat composer round-trip.
|
|
76
|
+
export function myFlow(manifest, entity, opts = {}) {
|
|
77
|
+
const cfg = opts.extend?.entities?.[entity.name] ?? {};
|
|
78
|
+
if (!entity.personal || new Set(cfg.skip ?? []).has('my')) return;
|
|
79
|
+
const idProperty = manifest.idProperty ?? 'Id';
|
|
80
|
+
// the same entity through the scoped controller
|
|
81
|
+
const mine = { ...entity, api: entity.personal.api };
|
|
82
|
+
|
|
83
|
+
async function buildContext(api) {
|
|
84
|
+
const payload = sampleRecord(entity);
|
|
85
|
+
const samples = await resolveRelationSamples(api, manifest, entity);
|
|
86
|
+
for (const sample of samples) {
|
|
87
|
+
payload[sample.relation.name] = sample.id;
|
|
88
|
+
}
|
|
89
|
+
// the owner FK is server-forced on the personal surface; sending a value must be pointless
|
|
90
|
+
delete payload[entity.personal.owner];
|
|
91
|
+
return { payload, samples };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function buildPayload(api) {
|
|
95
|
+
return (await buildContext(api)).payload;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
test(`${entity.name}: personal (my) surface scopes rows, forces the owner and strips sensitive fields`, async ({ api }) => {
|
|
99
|
+
const client = makeApi(api, manifest);
|
|
100
|
+
|
|
101
|
+
const createdResponse = await api.post(manifest.restBase + mine.api, { data: await buildPayload(api) });
|
|
102
|
+
test.skip(
|
|
103
|
+
!createdResponse.ok(),
|
|
104
|
+
`personal create returned ${createdResponse.status()} - the test user has no identity mapping; ` +
|
|
105
|
+
`seed the dev identity row (an owner-target record whose identity field equals the login user)`
|
|
106
|
+
);
|
|
107
|
+
const created = JSON.parse(await createdResponse.text());
|
|
108
|
+
const id = created?.[idProperty];
|
|
109
|
+
expect(id, 'personal create carries the generated id').toBeTruthy();
|
|
110
|
+
let foreignId;
|
|
111
|
+
try {
|
|
112
|
+
const own = await client.get(mine, id);
|
|
113
|
+
expect(own[entity.personal.owner], 'the owner FK is forced server-side on a personal create').toBeTruthy();
|
|
114
|
+
for (const field of entity.personal.sensitive ?? []) {
|
|
115
|
+
expect(own[field], `sensitive field ${field} must never reach the personal wire`).toBeFalsy();
|
|
116
|
+
}
|
|
117
|
+
const rows = await client.list(mine, 1000);
|
|
118
|
+
expect(rows.some((row) => row[idProperty] === id), 'the own row appears in the personal list').toBe(true);
|
|
119
|
+
|
|
120
|
+
// the power surface still serves the full record
|
|
121
|
+
const power = await client.get(entity, id);
|
|
122
|
+
expect(power[idProperty]).toBe(id);
|
|
123
|
+
|
|
124
|
+
// a row with no owner is foreign to everyone: the personal controller must 404 it and the
|
|
125
|
+
// personal list must not include it (only checkable when the owner relation is optional)
|
|
126
|
+
const ownerRelation = (entity.relations ?? []).find((relation) => relation.name === entity.personal.owner);
|
|
127
|
+
if (ownerRelation && !ownerRelation.required) {
|
|
128
|
+
const foreign = await client.create(entity, await buildPayload(api));
|
|
129
|
+
foreignId = foreign?.[idProperty];
|
|
130
|
+
const foreignThroughMine = await api.get(manifest.restBase + mine.api + '/' + foreignId);
|
|
131
|
+
expect(foreignThroughMine.status(), 'a foreign row must 404 through the personal controller').toBe(404);
|
|
132
|
+
const rowsAfter = await client.list(mine, 1000);
|
|
133
|
+
expect(rowsAfter.some((row) => row[idProperty] === foreignId), 'a foreign row must not appear in the personal list').toBe(false);
|
|
134
|
+
}
|
|
135
|
+
} finally {
|
|
136
|
+
await client.remove(mine, id); // deleting the OWN row through the personal controller works
|
|
137
|
+
if (foreignId) await client.remove(entity, foreignId);
|
|
138
|
+
}
|
|
139
|
+
const gone = await api.get(manifest.restBase + mine.api + '/' + id);
|
|
140
|
+
expect(gone.status()).toBe(404);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// wave 2: the UI-parity walk over the same personal surface (older manifests without the
|
|
144
|
+
// route/layout metadata regenerate to get it - skip quietly until then)
|
|
145
|
+
if (entity.personal.route) {
|
|
146
|
+
myUiTest(manifest, entity, mine, buildContext, idProperty);
|
|
147
|
+
}
|
|
148
|
+
}
|
package/test/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { test } from './fixtures.js';
|
|
|
3
3
|
import { crudFlow } from './flows/crud.js';
|
|
4
4
|
import { listFlow } from './flows/list.js';
|
|
5
5
|
import { multilingualFlow } from './flows/multilingual.js';
|
|
6
|
+
import { myFlow } from './flows/my.js';
|
|
6
7
|
import { restFlow } from './flows/rest.js';
|
|
7
8
|
import { shellFlow } from './flows/shell.js';
|
|
8
9
|
|
|
@@ -16,6 +17,7 @@ export function runTest(manifestRef, opts = {}) {
|
|
|
16
17
|
listFlow(manifest, entity, opts);
|
|
17
18
|
crudFlow(manifest, entity, opts);
|
|
18
19
|
restFlow(manifest, entity, opts);
|
|
20
|
+
myFlow(manifest, entity, opts);
|
|
19
21
|
multilingualFlow(manifest, entity, opts);
|
|
20
22
|
shellFlow(manifest, entity, opts);
|
|
21
23
|
});
|