9af7a2d122
* Password based agent implementation * tidy * tidy * wip * tidy * wip * tidy * wip * tests * tidy * websocket * tidy * tidy * tidy * tidy * tidy * tidy * tidy * tidy * changeset * codegen * tidy * tidy * tidy * tidy * tests * tidy * tidy * tests * tidy * tidy * tidy * wip * tidy * memoize * tidy * tests * tidy * files reorg * Ensure that default values match constraints * wip * use vitest to test lex * Add readme * fix lint * add vitest workspace config * vitest config * vitest-cfg * tests * ignore coverage * tidy
24 lines
873 B
TypeScript
24 lines
873 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { ui8Equals } from '@atproto/lex-data'
|
|
import { jsonToLex, lexToJson } from '@atproto/lex-json'
|
|
import { cidForLex, decodeAll, encode } from '../src/index.js'
|
|
import fixtures from './data-model-fixtures.json' with { type: 'json' }
|
|
|
|
describe('fixtures', () => {
|
|
for (const fixture of fixtures) {
|
|
it(fixture.cid, async () => {
|
|
const lex = jsonToLex(fixture.json, { strict: true })
|
|
const cid = await cidForLex(lex)
|
|
expect(cid.toString()).toBe(fixture.cid)
|
|
const encoded = encode(lex)
|
|
expect(encoded).toBeInstanceOf(Uint8Array)
|
|
expect(
|
|
ui8Equals(encoded, Buffer.from(fixture.cbor_base64, 'base64')),
|
|
).toBe(true)
|
|
const [decoded, ...rest] = decodeAll(encoded)
|
|
expect(rest.length).toBe(0)
|
|
expect(lexToJson(decoded)).toEqual(fixture.json)
|
|
})
|
|
}
|
|
})
|