Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto
Something went wrong. Try again.
3.2 kB · 83 lines
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import { describe, expect, it } from 'vitest'import { CASES, checkCase } from './smoke-test.mjs'
const pub = (over = {}) => ({ uri: 'at://did:plc:abc/site.standard.publication/self', did: 'did:plc:abc', verified: true, record: { name: 'Example Publication', url: 'https://example.test' }, ...over,})const detected = { name: 't', route: 'r', expect: { publication: true, verified: true } }const control = { name: 'c', route: 'r', expect: { publication: false } }
describe('CASES', () => { it('covers every detection route plus a negative control', () => { expect(CASES.filter((c) => c.expect.publication).length).toBeGreaterThanOrEqual(3) expect(CASES.some((c) => !c.expect.publication)).toBe(true) })
it('gives every case a url and a stated route', () => { for (const c of CASES) { expect(c.url).toMatch(/^https:\/\//) expect(c.route).toBeTruthy() } })})
describe('checkCase: a publication is expected', () => { it('passes a verified publication seen while signed out', () => { expect(checkCase(detected, { pub: pub() }, 'signedout')).toEqual([]) })
// The shape the broken-build control produced: the hint found the record, // but the well-known check that proves the site owns it did not pass. it('fails a publication that was found but not verified', () => { const problems = checkCase(detected, { pub: pub({ verified: false }) }, 'signedout-unverified') expect(problems).toEqual([ expect.stringContaining('not verified'), expect.stringContaining('signedout'), ]) })
it('fails when nothing was detected, and says so with the error', () => { expect(checkCase(detected, { error: 'fetch-failed' }, 'failed')).toEqual([ expect.stringContaining('fetch-failed'), ]) })
it('fails a did that is not the one the case pinned', () => { const c = { ...detected, expect: { ...detected.expect, did: 'did:plc:expected' } } expect(checkCase(c, { pub: pub() }, 'signedout')).toEqual([ expect.stringContaining('did:plc:expected'), ]) })
// A record that resolved to nothing still renders an empty card, so an // unnamed publication is a failure rather than a pass with a blank. it('fails a record that carries no name', () => { const problems = checkCase(detected, { pub: pub({ record: {} }) }, 'signedout') expect(problems).toEqual([expect.stringContaining('no name')]) })})
describe('checkCase: the control', () => { it('passes a page with no publication that finished looking', () => { expect(checkCase(control, { url: 'https://example.test/' }, 'none')).toEqual([]) })
it('fails if a publication turns up on the control page', () => { expect(checkCase(control, { pub: pub() }, 'signedout')).toEqual([ expect.stringContaining('expected no publication'), expect.stringContaining('none'), ]) })
// "Found nothing" and "could not look" are different answers, and only one // of them means the control passed. it('fails a control page where detection errored rather than concluded', () => { expect(checkCase(control, { error: 'fetch-failed' }, 'failed')).toEqual([ expect.stringContaining('expected icon state "none"'), ]) })})