recording-fence.test.ts2.7 KBView on GitHub
import { parseRecording } from '@/modules/documents/recording/recording-fence';
import { parseMoment } from '@/modules/documents/coaching/moment-fence';

describe('recording fence', () => {
  it('parses the header keys the player needs', () => {
    const r = parseRecording(
      [
        'provider: Fathom',
        'externalId: 177047966',
        'title: Adapt Insurance // Cedar onboarding',
        'at: 12:40',
        'recording: https://fathom.video/share/5mga_KS6Xbvz',
      ].join('\n'),
    )!;

    expect(r.externalId).toBe('177047966');
    // The provider is stored in both spellings in production ('Fathom' and 'fathom'), so the
    // fence lowercases it rather than leaving the card to compare against both.
    expect(r.provider).toBe('fathom');
    expect(r.title).toBe('Adapt Insurance // Cedar onboarding');
    expect(r.at).toBe('12:40');
    expect(r.recording).toBe('https://fathom.video/share/5mga_KS6Xbvz');
  });

  it('keeps a value containing colons intact', () => {
    const r = parseRecording('externalId: 1\ntitle: Acme: the renewal call')!;
    expect(r.title).toBe('Acme: the renewal call');
  });

  it('returns null without an externalId, so the node renders raw instead of empty', () => {
    expect(parseRecording('provider: fathom\nat: 12:40')).toBeNull();
    expect(parseRecording('')).toBeNull();
    expect(parseRecording('just some prose')).toBeNull();
  });

  it('tolerates a fence with only the id', () => {
    const r = parseRecording('externalId: 177047966')!;
    expect(r.externalId).toBe('177047966');
    expect(r.at).toBeUndefined();
    expect(r.recording).toBeUndefined();
  });
});

describe('moment fence — recording keys', () => {
  const withIds = [
    'deal: Works Progress Architecture',
    'meeting: Pirros | Works Progress',
    'at: 04:10',
    'externalId: 177047966',
    'provider: Fathom',
    'verdict: bad',
    'coaching: Stay on the PyRevit claim.',
    '',
    '## moment',
    '**Michael** (04:10) I am fairly confident we may not be moving forward.',
  ].join('\n');

  it('carries externalId and a normalised provider', () => {
    const m = parseMoment(withIds)!;
    expect(m.externalId).toBe('177047966');
    expect(m.provider).toBe('fathom');
  });

  it('still parses a moment written before those keys existed', () => {
    // Documents already in production carry a link and no id. They must keep rendering —
    // they simply get the old anchor instead of a player.
    const legacy = withIds
      .split('\n')
      .filter((l) => !l.startsWith('externalId:') && !l.startsWith('provider:'))
      .join('\n');
    const m = parseMoment(legacy)!;
    expect(m.externalId).toBeUndefined();
    expect(m.provider).toBeUndefined();
    expect(m.verdict).toBe('bad');
  });
});