|
| 1 | +import { |
| 2 | + PLATFORM_ADMIN_ROLE as AUTH_PLATFORM_ADMIN_ROLE, |
| 3 | + isOrgParticipant as authIsOrgParticipant, |
| 4 | +} from '@trycompai/auth/participation'; |
| 5 | +import { |
| 6 | + isOrgParticipant, |
| 7 | + PLATFORM_ADMIN_ROLE, |
| 8 | +} from './org-participation-rule'; |
| 9 | + |
| 10 | +describe('org-participation-rule (API mirror)', () => { |
| 11 | + it('excludes platform admins in a customer org', () => { |
| 12 | + expect(isOrgParticipant(PLATFORM_ADMIN_ROLE, { orgIsInternal: false })).toBe( |
| 13 | + false, |
| 14 | + ); |
| 15 | + }); |
| 16 | + |
| 17 | + it('includes platform admins in an internal org', () => { |
| 18 | + expect(isOrgParticipant(PLATFORM_ADMIN_ROLE, { orgIsInternal: true })).toBe( |
| 19 | + true, |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + it('includes non-admin and null roles in a customer org', () => { |
| 24 | + expect(isOrgParticipant('user', { orgIsInternal: false })).toBe(true); |
| 25 | + expect(isOrgParticipant('owner', { orgIsInternal: false })).toBe(true); |
| 26 | + expect(isOrgParticipant(null, { orgIsInternal: false })).toBe(true); |
| 27 | + expect(isOrgParticipant(undefined, { orgIsInternal: false })).toBe(true); |
| 28 | + }); |
| 29 | +}); |
| 30 | + |
| 31 | +// Drift guard: this API-local rule is a deliberate dependency-free mirror of |
| 32 | +// `@trycompai/auth/participation` (files in the Trigger.dev bundle can't import |
| 33 | +// the auth package — its dist isn't built in that deploy). Fail CI if the two |
| 34 | +// ever diverge. |
| 35 | +describe('API rule stays in sync with @trycompai/auth', () => { |
| 36 | + const roles: Array<string | null | undefined> = [ |
| 37 | + 'admin', |
| 38 | + 'owner', |
| 39 | + 'user', |
| 40 | + 'auditor', |
| 41 | + '', |
| 42 | + null, |
| 43 | + undefined, |
| 44 | + ]; |
| 45 | + |
| 46 | + it('matches the canonical predicate for every role × internal flag', () => { |
| 47 | + expect(PLATFORM_ADMIN_ROLE).toBe(AUTH_PLATFORM_ADMIN_ROLE); |
| 48 | + for (const role of roles) { |
| 49 | + for (const orgIsInternal of [true, false]) { |
| 50 | + expect(isOrgParticipant(role, { orgIsInternal })).toBe( |
| 51 | + authIsOrgParticipant(role, { orgIsInternal }), |
| 52 | + ); |
| 53 | + } |
| 54 | + } |
| 55 | + }); |
| 56 | +}); |
0 commit comments