|
| 1 | +import { describe, it } from 'node:test'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | + |
| 4 | +import { |
| 5 | + computeLinearPath, |
| 6 | + normalizeLinearObjectType, |
| 7 | + normalizeNangoLinearModel, |
| 8 | + tryNormalizeLinearObjectType, |
| 9 | +} from '../path-mapper.js'; |
| 10 | + |
| 11 | +describe('linear path-mapper', () => { |
| 12 | + describe('normalizeLinearObjectType', () => { |
| 13 | + it('accepts canonical types', () => { |
| 14 | + assert.equal(normalizeLinearObjectType('issue'), 'issue'); |
| 15 | + assert.equal(normalizeLinearObjectType('TEAM'), 'team'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('accepts plural aliases', () => { |
| 19 | + assert.equal(normalizeLinearObjectType('issues'), 'issue'); |
| 20 | + assert.equal(normalizeLinearObjectType('teams'), 'team'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('accepts Nango-style PascalCase model names', () => { |
| 24 | + assert.equal(normalizeLinearObjectType('LinearTeam'), 'team'); |
| 25 | + assert.equal(normalizeLinearObjectType('LinearUser'), 'user'); |
| 26 | + assert.equal(normalizeLinearObjectType('LinearIssue'), 'issue'); |
| 27 | + assert.equal(normalizeLinearObjectType('LinearComment'), 'comment'); |
| 28 | + assert.equal(normalizeLinearObjectType('LinearCycle'), 'cycle'); |
| 29 | + assert.equal(normalizeLinearObjectType('LinearMilestone'), 'milestone'); |
| 30 | + assert.equal(normalizeLinearObjectType('LinearProject'), 'project'); |
| 31 | + assert.equal(normalizeLinearObjectType('LinearRoadmap'), 'roadmap'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('throws on unknown types', () => { |
| 35 | + assert.throws(() => normalizeLinearObjectType('flarb')); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('tryNormalizeLinearObjectType', () => { |
| 40 | + it('returns undefined on unknown types', () => { |
| 41 | + assert.equal(tryNormalizeLinearObjectType('flarb'), undefined); |
| 42 | + }); |
| 43 | + |
| 44 | + it('returns the resolved type for known input', () => { |
| 45 | + assert.equal(tryNormalizeLinearObjectType('LinearIssue'), 'issue'); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe('normalizeNangoLinearModel', () => { |
| 50 | + // Each Nango sync emits a single PascalCase model — see |
| 51 | + // cloud/nango-integrations/linear-relay/syncs/*.ts. This test pins those |
| 52 | + // contracts so any future sync rename surfaces here as a failure. |
| 53 | + it('maps every Nango linear-relay sync model', () => { |
| 54 | + assert.equal(normalizeNangoLinearModel('LinearComment'), 'comment'); |
| 55 | + assert.equal(normalizeNangoLinearModel('LinearCycle'), 'cycle'); |
| 56 | + assert.equal(normalizeNangoLinearModel('LinearIssue'), 'issue'); |
| 57 | + assert.equal(normalizeNangoLinearModel('LinearMilestone'), 'milestone'); |
| 58 | + assert.equal(normalizeNangoLinearModel('LinearProject'), 'project'); |
| 59 | + assert.equal(normalizeNangoLinearModel('LinearRoadmap'), 'roadmap'); |
| 60 | + assert.equal(normalizeNangoLinearModel('LinearTeam'), 'team'); |
| 61 | + assert.equal(normalizeNangoLinearModel('LinearUser'), 'user'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('falls back to alias-map normalization for non-Nango input', () => { |
| 65 | + assert.equal(normalizeNangoLinearModel('issues'), 'issue'); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('computeLinearPath', () => { |
| 70 | + it('produces Nango-driven paths from PascalCase model names', () => { |
| 71 | + assert.equal( |
| 72 | + computeLinearPath('LinearTeam', '50cf92f3-f53c-4ab6-bf05-ea76ebd21692'), |
| 73 | + '/linear/teams/50cf92f3-f53c-4ab6-bf05-ea76ebd21692.json', |
| 74 | + ); |
| 75 | + assert.equal( |
| 76 | + computeLinearPath('LinearUser', 'usr_123'), |
| 77 | + '/linear/users/usr_123.json', |
| 78 | + ); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments