// com.atproto.repo.describeRepo — the bridge previously returned MethodNotImplemented. PeerFront now
// derives collections from the replicated repo and reports did/handle/handleIsCorrect keylessly.
import test from 'brittle'
import { DidPeer } from 'atproto-did-peer'
function makeFront (records, { did = 'did:plc:desc', handle = 'desc.7rnx.net' } = {}) {
const f = new DidPeer({}, { did, verifyKey: new Uint8Array(32), handle })
f.repo = { records: async () => records }
return f
}
test('describeRepo: distinct collections derived from repo keys, correct shape', async (t) => {
const front = makeFront([
{ key: 'app.bsky.feed.post/3a' },
{ key: 'app.bsky.feed.post/3b' },
{ key: 'app.bsky.graph.follow/x' },
{ key: 'chat.bsky.actor.declaration/self' }
])
const d = await front.describeRepo({}) // no doFetch -> didDoc null (best-effort)
t.is(d.did, 'did:plc:desc', 'did reported')
t.is(d.handle, 'desc.7rnx.net', 'handle reported')
t.is(d.handleIsCorrect, true, 'handleIsCorrect true when a handle is declared')
t.is(d.didDoc, null, 'didDoc null without a doFetch (best-effort)')
t.alike(d.collections.sort(), ['app.bsky.feed.post', 'app.bsky.graph.follow', 'chat.bsky.actor.declaration'], 'distinct collections, deduped')
})
test('describeRepo: didDoc populated from a server-shaped doFetch', async (t) => {
const front = makeFront([{ key: 'app.bsky.feed.post/3a' }])
const doFetch = async () => ({ status: 200, body: Buffer.from(JSON.stringify({ id: 'did:plc:desc', service: [] })) })
const d = await front.describeRepo({ doFetch })
t.is(d.didDoc && d.didDoc.id, 'did:plc:desc', 'didDoc parsed from PLC fetch')
})
test('describeRepo: empty repo -> no collections, no crash', async (t) => {
const front = makeFront([], { handle: null })
const d = await front.describeRepo({})
t.alike(d.collections, [], 'no collections')
t.is(d.handleIsCorrect, false, 'handleIsCorrect false when no handle declared')
})