|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { appRouteSegment, matchAppBySegment } from '../appRoute'; |
| 3 | + |
| 4 | +/** |
| 5 | + * ADR-0048 (option A) — package-id route segment. |
| 6 | + */ |
| 7 | +describe('appRouteSegment', () => { |
| 8 | + it('returns the package id when present', () => { |
| 9 | + expect(appRouteSegment({ name: 'crm', _packageId: 'com.acme.crm' })).toBe('com.acme.crm'); |
| 10 | + }); |
| 11 | + it('falls back to the app name when no package id', () => { |
| 12 | + expect(appRouteSegment({ name: 'crm' })).toBe('crm'); |
| 13 | + }); |
| 14 | + it('returns undefined for nullish input', () => { |
| 15 | + expect(appRouteSegment(undefined)).toBeUndefined(); |
| 16 | + expect(appRouteSegment(null)).toBeUndefined(); |
| 17 | + }); |
| 18 | +}); |
| 19 | + |
| 20 | +describe('matchAppBySegment', () => { |
| 21 | + const crm = { name: 'crm', _packageId: 'com.acme.crm' }; |
| 22 | + const hr = { name: 'crm', _packageId: 'com.beta.crm' }; // same display name, different vendor |
| 23 | + const apps = [crm, hr]; |
| 24 | + |
| 25 | + it('matches by package id (disambiguates same-named apps)', () => { |
| 26 | + expect(matchAppBySegment(apps, 'com.acme.crm')).toBe(crm); |
| 27 | + expect(matchAppBySegment(apps, 'com.beta.crm')).toBe(hr); |
| 28 | + }); |
| 29 | + it('falls back to matching by name (legacy/alias URL)', () => { |
| 30 | + expect(matchAppBySegment([{ name: 'sales' }], 'sales')).toEqual({ name: 'sales' }); |
| 31 | + }); |
| 32 | + it('prefers a package-id match over a name match', () => { |
| 33 | + const byName = { name: 'com.acme.crm' }; // pathological: an app literally named like a pkg id |
| 34 | + expect(matchAppBySegment([byName, crm], 'com.acme.crm')).toBe(crm); |
| 35 | + }); |
| 36 | + it('returns undefined for missing inputs', () => { |
| 37 | + expect(matchAppBySegment(apps, undefined)).toBeUndefined(); |
| 38 | + expect(matchAppBySegment(null, 'com.acme.crm')).toBeUndefined(); |
| 39 | + }); |
| 40 | +}); |
0 commit comments