Skip to content

Commit ab4b30a

Browse files
committed
test: pin the reporting-line read-back, the seeded Set Manager picker and the Remove Manager clear
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1
1 parent 045616a commit ab4b30a

3 files changed

Lines changed: 184 additions & 11 deletions

File tree

‎packages/platform-objects/src/identity/sys-user-set-manager-action.test.ts‎

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,27 @@ describe('#19249 — sys_user.set_user_manager posts the admin endpoint', () =>
113113
expect(ACTION.locations).toContain('record_header');
114114
});
115115

116-
it('collects the manager as an inline sys_user lookup under the body key the endpoint reads', () => {
116+
it('collects the manager on `manager_id`, seeded from the row, under the body key the endpoint reads', () => {
117117
const params = (ACTION.params ?? []) as AnyParam[];
118118
expect(params).toHaveLength(1);
119119
const [p] = params;
120120
expect(p.name).toBe('managerId');
121-
expect(p.type).toBe('lookup');
122-
expect(p.reference).toBe('sys_user');
123-
// INLINE, not field-backed: `{ field: 'manager_id' }` would inherit the
124-
// referenced field's metadata, and that field is `readonly: true`
125-
// (ADR-0092 D4 keeps it non-editable in the standard edit form).
126-
expect(p.field).toBeUndefined();
121+
// FIELD-BACKED and seeded from the row, so the dialog opens on the
122+
// CURRENT manager: before, it opened empty and an admin re-pointing a
123+
// manager could not see what the click would replace. The console's param
124+
// resolver inherits the field's type and target, never its `readonly`
125+
// (ADR-0092 D4 keeps the column locked in the edit form, not here).
126+
expect(p.field).toBe('manager_id');
127+
expect(p.defaultFromRow).toBe(true);
128+
expect(SysUser.fields.manager_id.type).toBe('lookup');
129+
expect((SysUser.fields.manager_id as { reference?: string }).reference).toBe('sys_user');
130+
// Seeded, not carried: the admin picks the new manager, so the control
131+
// stays editable.
132+
expect(p.carryOver).toBeUndefined();
127133
// Required, because the endpoint refuses an ABSENT or empty key by design
128134
// ("managerId is required — send null to clear the link, never omit the
129135
// key"). A dialog that could submit nothing would turn an ordinary click
130-
// into a 400 about a key the user never saw.
136+
// into a 400 about a key the user never saw; the clear is its own action.
131137
expect(p.required).toBe(true);
132138
});
133139

@@ -213,3 +219,77 @@ describe('the visible predicate: offered on every row, the SCIM-held refusal is
213219
expect(visible()).not.toContain('features.');
214220
});
215221
});
222+
223+
/**
224+
* `remove_user_manager` — the clear the required picker above cannot send.
225+
* The endpoint clears the link on `managerId: null` ("send null to clear the
226+
* link, never omit the key"); the action sends that null as its static body
227+
* and asks a confirm question instead of collecting anything. The forward
228+
* itself — the null arriving at the target — is pinned at the door, in
229+
* `@objectstack/runtime`'s `platform-admin-action-gate.test.ts`.
230+
*/
231+
describe('sys_user.remove_user_manager clears the link through the same endpoint', () => {
232+
const REMOVE = (() => {
233+
const found = actionsOf().find((a) => a.name === 'remove_user_manager');
234+
if (!found) throw new Error('sys_user declares no remove_user_manager action');
235+
return found;
236+
})();
237+
238+
it('posts the set-user-manager endpoint with `managerId: null` and collects nothing', () => {
239+
expect(REMOVE.type).toBe('api');
240+
expect(REMOVE.target).toBe(ACTION.target);
241+
expect(REMOVE.recordIdParam).toBe(ACTION.recordIdParam);
242+
expect(REMOVE.method === undefined || REMOVE.method === 'POST').toBe(true);
243+
// The key PRESENT and null: an absent key is the endpoint's 400.
244+
expect(REMOVE.bodyExtra).toEqual({ managerId: null });
245+
expect(Object.prototype.hasOwnProperty.call(REMOVE.bodyExtra, 'managerId')).toBe(true);
246+
expect(REMOVE.params ?? []).toEqual([]);
247+
// Nothing collected, so the question rides `confirmText`, not
248+
// `description` (the param-collecting set action's carrier).
249+
expect(REMOVE.confirmText).toBeTruthy();
250+
expect(REMOVE.description).toBeUndefined();
251+
});
252+
253+
it('⛔ does NOT write manager_id through the generic data API', () => {
254+
expect(String(REMOVE.target)).not.toContain('/data/');
255+
expect(REMOVE.operation).toBeUndefined();
256+
expect(REMOVE.patch).toBeUndefined();
257+
});
258+
259+
it('is gated exactly like set_user_manager: the same capability gate, the same standing term first', () => {
260+
expect(REMOVE.requiredPermissions).toEqual(ACTION.requiredPermissions);
261+
expect(REMOVE.requiresFeature).toBeUndefined();
262+
expect(REMOVE.locations).toEqual(ACTION.locations);
263+
const standing = sourceOf(ACTION.visible)!;
264+
expect(sourceOf(REMOVE.visible)!.startsWith(`${standing} && `)).toBe(true);
265+
});
266+
267+
it('reads only the row\'s `manager_id`, never a copy of a server refusal', () => {
268+
const visible = sourceOf(REMOVE.visible)!;
269+
const columns = new Set([...visible.matchAll(/record\.([a-z_][a-z0-9_]*)/gi)].map((m) => m[1]));
270+
expect([...columns]).toEqual(['manager_id']);
271+
expect(visible).not.toContain('record.source');
272+
expect(visible).not.toContain('ctx.user.id');
273+
});
274+
275+
it('is offered only while the row has a manager, and only to the standing the door admits', () => {
276+
const visible = sourceOf(REMOVE.visible)!;
277+
expect(evaluate(visible, { id: 'someone_else', manager_id: 'u_mgr' })).toBe(true);
278+
// An SSO-only person's manager is cleared here too; a SCIM-held row is the
279+
// endpoint's refusal, as for the set.
280+
expect(evaluate(visible, { id: 'someone_else', manager_id: 'u_mgr', source: 'idp_provisioned' })).toBe(true);
281+
expect(evaluate(visible, { id: 'someone_else', manager_id: null })).toBe(false);
282+
// The sparse face (no column projected) is not a fault, just not offered.
283+
expect(evaluate(visible, { id: 'someone_else' })).toBe(false);
284+
const member = { id: 'm_1', isPlatformAdmin: false, positions: [] as string[] };
285+
const r = celEngine.evaluate(
286+
{ dialect: 'cel', source: visible },
287+
{ record: { id: 'someone_else', manager_id: 'u_mgr' }, extra: { current_user: member, user: member, ctx: { user: member }, os: { user: member }, features: {} } },
288+
);
289+
expect(r.ok && r.value).toBe(false);
290+
});
291+
292+
it('stays human-only: no `ai` block, like every action after the ADR-0011 assessment', () => {
293+
expect(REMOVE.ai).toBeUndefined();
294+
});
295+
});

‎packages/platform-objects/src/pages/sys-user-details-tab.test.ts‎

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import { describe, expect, it } from 'vitest';
21-
import { PageSchema } from '@objectstack/spec/ui';
21+
import { PageSchema, RecordRelatedListProps } from '@objectstack/spec/ui';
2222
import { SysUserDetailPage } from './sys-user.page.js';
2323

2424
type Rec = Record<string, unknown>;
@@ -38,6 +38,11 @@ const SECTIONS = [
3838
// #27859: a saved Locale is shown; the renderer draws only authored sections.
3939
fields: ['name', 'image', 'locale'],
4040
},
41+
{
42+
// The reporting line: who this person reports to (see the describe below).
43+
label: { en: 'Reporting Line', 'zh-CN': '汇报关系', 'ja-JP': 'レポートライン', 'es-ES': 'Línea de reporte', 'zh-Hant': '匯報關係', ar: 'التسلسل الإداري', fr: 'Ligne hiérarchique', 'pt-BR': 'Linha de reporte', ru: 'Подчинённость', de: 'Berichtslinie', ko: '보고 라인' },
44+
fields: ['manager_id'],
45+
},
4146
{
4247
// #27859: a banned user reads as banned, with the reason, not as active.
4348
label: { en: 'Account Status', 'zh-CN': '账号状态', 'ja-JP': 'アカウントの状態', 'es-ES': 'Estado de la cuenta', 'zh-Hant': '帳號狀態', ar: 'حالة الحساب', fr: 'État du compte', 'pt-BR': 'Status da conta', ru: 'Статус учётной записи', de: 'Kontostatus', ko: '계정 상태' },
@@ -65,11 +70,12 @@ describe('sys_user_detail — the details body lives in the first tab', () => {
6570
expect(tabs.type).toBe('page:tabs');
6671
});
6772

68-
it('carries the `record:details` as the only child of the FIRST tab item, sections and hidden fields intact', () => {
73+
it('carries the `record:details` as the FIRST child of the FIRST tab item, sections and hidden fields intact', () => {
6974
const first = items[0]!;
7075
expect((first.label as Rec).en).toBe('Details');
7176
const children = first.children as Rec[];
72-
expect(children.map((c) => c.type)).toEqual(['record:details']);
77+
// The details grid, then the Direct Reports list (pinned below).
78+
expect(children.map((c) => c.type)).toEqual(['record:details', 'record:related_list']);
7379
const props = children[0]!.properties as Rec;
7480
expect(props.hideFields).toEqual(HIDE_FIELDS);
7581
expect(props.sections).toEqual(SECTIONS);
@@ -96,3 +102,59 @@ describe('sys_user_detail — the details body lives in the first tab', () => {
96102
expect(found).toHaveLength(1);
97103
});
98104
});
105+
106+
/**
107+
* The reporting line is read back on the record: who this person reports to,
108+
* and who reports to them.
109+
*
110+
* `sys_user.manager_id` is `readonly` (ADR-0092 D4) and written only by the
111+
* admin endpoint behind Set Manager / Remove Manager, and the renderer draws
112+
* only the sections a page names. Before, no section named it and no list
113+
* showed its reverse, so an admin who had set a manager could not see it
114+
* anywhere in Setup. Decision batch #127 item 1: the manager is this explicit
115+
* link alone; a business unit's head is not read here.
116+
*/
117+
describe('sys_user_detail — the reporting line is shown in the Details tab', () => {
118+
const parsed = PageSchema.parse(SysUserDetailPage);
119+
const strip = (parsed.regions![0]!.components as Rec[]).find((c) => c.type === 'page:tabs') as Rec;
120+
const details = ((strip.properties as Rec).items as Rec[])[0]!;
121+
const children = details.children as Rec[];
122+
123+
it('a Details section names `manager_id`, and nothing hides it', () => {
124+
const props = children.find((c) => c.type === 'record:details')!.properties as Rec;
125+
const sections = props.sections as { label: Rec; fields: string[] }[];
126+
const holding = sections.filter((s) => s.fields.includes('manager_id'));
127+
expect(holding.map((s) => s.label.en)).toEqual(['Reporting Line']);
128+
expect(props.hideFields).not.toContain('manager_id');
129+
});
130+
131+
it('the Direct Reports list reads `sys_user` rows whose `manager_id` is this record\'s id', () => {
132+
const lists = children.filter((c) => c.type === 'record:related_list');
133+
expect(lists).toHaveLength(1);
134+
const props = lists[0]!.properties as Rec;
135+
expect((props.title as Rec).en).toBe('Direct Reports');
136+
expect(props.objectName).toBe('sys_user');
137+
expect(props.relationshipField).toBe('manager_id');
138+
// The parent value the relationship field is matched against is the
139+
// record's id: nothing is authored, and the props contract's default is
140+
// `id` (the page envelope serves `properties` verbatim, so the default is
141+
// read through the block's own schema).
142+
expect(props).not.toHaveProperty('relationshipValueField');
143+
const contract = RecordRelatedListProps.safeParse(props);
144+
expect(contract.success, JSON.stringify(contract.error?.issues ?? [])).toBe(true);
145+
expect(contract.data!.relationshipValueField).toBe('id');
146+
// No authored filter narrows it, and no `add` picker: the link is the
147+
// admin endpoint's to write, never a related-list insert.
148+
expect(props.filter).toBeUndefined();
149+
expect(props.add).toBeUndefined();
150+
});
151+
152+
it('both labels carry the same locales as the tab they sit in', () => {
153+
const tabLocales = Object.keys(details.label as Rec).sort();
154+
const props = children.find((c) => c.type === 'record:details')!.properties as Rec;
155+
const section = (props.sections as { label: Rec; fields: string[] }[]).find((s) => s.fields.includes('manager_id'))!;
156+
const list = children.find((c) => c.type === 'record:related_list')!.properties as Rec;
157+
expect(Object.keys(section.label).sort()).toEqual(tabLocales);
158+
expect(Object.keys(list.title as Rec).sort()).toEqual(tabLocales);
159+
});
160+
});

‎packages/runtime/src/platform-admin-action-gate.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,37 @@ describe('[#30771] a hidden action is still refused when called', () => {
165165
}
166166
});
167167

168+
describe('sys_user.remove_user_manager: the clear reaches the endpoint as `managerId: null`', () => {
169+
// The endpoint clears the link on `managerId: null` and refuses an ABSENT
170+
// key, so the null has to survive the door's body assembly: the declared
171+
// `bodyExtra` is merged last, after the row id. Driven over the real
172+
// declaration; the target is faked so the forwarded body can be read.
173+
const forwardOf = (request: ReturnType<typeof boot>['request']) =>
174+
(request.mock.calls as unknown as Array<[string, RequestInit]>)[0]!;
175+
176+
it('the admin\'s click is forwarded to set-user-manager with the row id and the key present and null', async () => {
177+
const { dispatcher, request } = boot();
178+
const res = await dispatcher.handleActions(`/${OBJECT}/remove_user_manager`, 'POST', { recordId: 'u_target', params: {} }, ADMIN());
179+
expect(res?.response?.status).toBe(200);
180+
expect(request).toHaveBeenCalledTimes(1);
181+
const [url, init] = forwardOf(request);
182+
expect(url).toBe('http://localhost/api/v1/auth/admin/set-user-manager');
183+
expect(String(init.method).toUpperCase()).toBe('POST');
184+
const body = JSON.parse(String(init.body));
185+
expect(body.userId).toBe('u_target');
186+
expect(Object.prototype.hasOwnProperty.call(body, 'managerId')).toBe(true);
187+
expect(body.managerId).toBeNull();
188+
});
189+
190+
it('a plain member is refused 403 at the door with the set action\'s gate, nothing forwarded', async () => {
191+
const { dispatcher, request } = boot();
192+
const refused = await dispatcher.handleActions(`/${OBJECT}/remove_user_manager`, 'POST', { recordId: 'u_target', params: {} }, MEMBER());
193+
expect(refused?.response?.status).toBe(403);
194+
expect(String(refused?.response?.body?.error?.message)).toContain('requires capability [manage_users]');
195+
expect(request).not.toHaveBeenCalled();
196+
});
197+
});
198+
168199
describe('[#30771] capabilityRefusal: why the scoped MCP pre-screen finds an action missing', () => {
169200
it('answers the gate\'s refusal for an exposed action the member cannot run — the one run_action throws by name', async () => {
170201
const { dispatcher, request } = boot();

0 commit comments

Comments
 (0)