|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | +// |
| 3 | +// Add Member opened from a team carries that team. |
| 4 | +// |
| 5 | +// `sys_team_member.add_team_member` sits on the membership list's toolbar, |
| 6 | +// where no team is in hand, so its dialog asks for the team as well as the |
| 7 | +// user. The team-side copy on `sys_team` binds the team from the row it is |
| 8 | +// opened on (`recordIdParam: 'teamId'`), so the dialog asks for the user |
| 9 | +// alone. Both copies call the same endpoint behind the same gates; this file |
| 10 | +// pins that the two agree on everything except where the team comes from. |
| 11 | +import { describe, expect, it } from 'vitest'; |
| 12 | +import { SysTeam } from './sys-team.object.js'; |
| 13 | +import { SysTeamMember } from './sys-team-member.object.js'; |
| 14 | + |
| 15 | +interface ParamLike { |
| 16 | + name?: string; |
| 17 | + field?: string; |
| 18 | + objectOverride?: string; |
| 19 | + required?: boolean; |
| 20 | + defaultFromRow?: boolean; |
| 21 | +} |
| 22 | + |
| 23 | +interface ActionLike { |
| 24 | + name?: string; |
| 25 | + type?: string; |
| 26 | + target?: string; |
| 27 | + recordIdParam?: string; |
| 28 | + locations?: string[]; |
| 29 | + visible?: { source?: string }; |
| 30 | + params?: ParamLike[]; |
| 31 | +} |
| 32 | + |
| 33 | +function action(object: { actions?: unknown[] }, name: string): ActionLike { |
| 34 | + const found = ((object.actions ?? []) as ActionLike[]).find((a) => a.name === name); |
| 35 | + expect(found, `${name} is declared`).toBeDefined(); |
| 36 | + return found as ActionLike; |
| 37 | +} |
| 38 | + |
| 39 | +describe('sys_team.add_team_member — Add Member opened from a team', () => { |
| 40 | + const fromTeam = action(SysTeam, 'add_team_member'); |
| 41 | + const fromList = action(SysTeamMember, 'add_team_member'); |
| 42 | + |
| 43 | + it('is offered on the team row and the team record header', () => { |
| 44 | + expect(fromTeam.locations).toEqual(['list_item', 'record_header']); |
| 45 | + }); |
| 46 | + |
| 47 | + it('binds the team from the row it is opened on, as teamId', () => { |
| 48 | + expect(fromTeam.recordIdParam).toBe('teamId'); |
| 49 | + // The team is not asked for: no dialog param submits teamId. |
| 50 | + expect((fromTeam.params ?? []).map((p) => p.name)).not.toContain('teamId'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('asks only for the user, through the membership row\'s sys_user lookup', () => { |
| 54 | + expect(fromTeam.params).toEqual([ |
| 55 | + { name: 'userId', field: 'user_id', objectOverride: 'sys_team_member', required: true }, |
| 56 | + ]); |
| 57 | + }); |
| 58 | + |
| 59 | + it('calls the same endpoint behind the same gate as the membership-list copy', () => { |
| 60 | + expect(fromTeam.type).toBe('api'); |
| 61 | + expect(fromTeam.target).toBe('/api/v1/auth/organization/add-team-member'); |
| 62 | + expect(fromTeam.target).toBe(fromList.target); |
| 63 | + expect(fromTeam.visible?.source).toBeDefined(); |
| 64 | + expect(fromTeam.visible?.source).toBe(fromList.visible?.source); |
| 65 | + }); |
| 66 | + |
| 67 | + it('leaves the membership-list copy asking for the team, where none is in hand', () => { |
| 68 | + expect(fromList.locations).toEqual(['list_toolbar']); |
| 69 | + expect(fromList.recordIdParam).toBeUndefined(); |
| 70 | + expect((fromList.params ?? []).map((p) => p.name)).toEqual(['teamId', 'userId']); |
| 71 | + }); |
| 72 | +}); |
0 commit comments