import { describe, expect, test } from 'vitest'; import { domainToLexiconDns, nsidToDomain, nsidToDomains, } from '../src/authority.js'; describe('authority', () => { describe('nsidToDomain', () => { test('reverses every segment but the last, per spec', () => { expect(nsidToDomain('app.bsky.feed.post')).toBe('feed.bsky.app'); }); test('converts com.atproto.repo.createRecord to repo.atproto.com', () => { expect(nsidToDomain('com.atproto.repo.createRecord')).toBe( 'repo.atproto.com', ); }); test('handles a two-segment authority', () => { expect(nsidToDomain('com.germnetwork.declaration')).toBe( 'germnetwork.com', ); }); }); describe('nsidToDomains', () => { test('offers the spec form first, then the two-segment fallback', () => { expect(nsidToDomains('app.bsky.feed.post')).toEqual([ 'feed.bsky.app', 'bsky.app', ]); }); test('does not repeat itself when the two forms coincide', () => { expect(nsidToDomains('com.germnetwork.declaration')).toEqual([ 'germnetwork.com', ]); }); // com.atproto.lexicon.schema publishes only at lexicon.atproto.com, so the // two-segment form alone can't resolve it. test('reaches a deep authority that the short form misses', () => { expect(nsidToDomains('com.atproto.lexicon.schema')).toEqual([ 'lexicon.atproto.com', 'atproto.com', ]); }); }); describe('domainToLexiconDns', () => { test('prepends _lexicon to domain', () => { expect(domainToLexiconDns('bsky.app')).toBe('_lexicon.bsky.app'); }); }); });