7f26b17652
* Improve error message when using invalid client_id during code exchange * Extract SPA example OAuth client in own package * wip * remove dependency on get-port * Properly configure jest to only transpile "get-port" from node_modules https://jestjs.io/docs/configuration#transformignorepatterns-arraystring * Use dynamically assigned port number during tests * use puppeteer to run tests * remove login input "id" attribute * code style * add missing declaration * tidy * headless * remove get-port dependency * fix tests/proxied/admin.test.ts * fix tests * Allow unsecure oauth providers through configuration * transpile "lande" during ozone tests * Cache Puppeteer browser binaries * Use puppeteer cache during all workflow steps * remove use of set-output * use get-port in xrpc-server tests * Renamed to allowHttp * tidy * tidy
97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import * as http from 'node:http'
|
|
import { AddressInfo } from 'node:net'
|
|
import { LexiconDoc } from '@atproto/lexicon'
|
|
import { XrpcClient } from '@atproto/xrpc'
|
|
import { CID } from 'multiformats/cid'
|
|
import { createServer, closeServer } from './_util'
|
|
import * as xrpcServer from '../src'
|
|
|
|
const LEXICONS: LexiconDoc[] = [
|
|
{
|
|
lexicon: 1,
|
|
id: 'io.example.ipld',
|
|
defs: {
|
|
main: {
|
|
type: 'procedure',
|
|
input: {
|
|
encoding: 'application/json',
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
cid: {
|
|
type: 'cid-link',
|
|
},
|
|
bytes: {
|
|
type: 'bytes',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
output: {
|
|
encoding: 'application/json',
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
cid: {
|
|
type: 'cid-link',
|
|
},
|
|
bytes: {
|
|
type: 'bytes',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
describe('Ipld vals', () => {
|
|
let s: http.Server
|
|
const server = xrpcServer.createServer(LEXICONS)
|
|
server.method(
|
|
'io.example.ipld',
|
|
(ctx: { input?: xrpcServer.HandlerInput }) => {
|
|
const asCid = CID.asCID(ctx.input?.body.cid)
|
|
if (!(asCid instanceof CID)) {
|
|
throw new Error('expected cid')
|
|
}
|
|
const bytes = ctx.input?.body.bytes
|
|
if (!(bytes instanceof Uint8Array)) {
|
|
throw new Error('expected bytes')
|
|
}
|
|
return { encoding: 'application/json', body: ctx.input?.body }
|
|
},
|
|
)
|
|
|
|
let client: XrpcClient
|
|
beforeAll(async () => {
|
|
s = await createServer(server)
|
|
const { port } = s.address() as AddressInfo
|
|
client = new XrpcClient(`http://localhost:${port}`, LEXICONS)
|
|
})
|
|
afterAll(async () => {
|
|
await closeServer(s)
|
|
})
|
|
|
|
it('can send and receive ipld vals', async () => {
|
|
const cid = CID.parse(
|
|
'bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a',
|
|
)
|
|
const bytes = new Uint8Array([0, 1, 2, 3])
|
|
const res = await client.call(
|
|
'io.example.ipld',
|
|
{},
|
|
{
|
|
cid,
|
|
bytes,
|
|
},
|
|
{ encoding: 'application/json' },
|
|
)
|
|
expect(res.success).toBeTruthy()
|
|
expect(res.headers['content-type']).toBe('application/json; charset=utf-8')
|
|
expect(cid.equals(res.data.cid)).toBeTruthy()
|
|
expect(bytes).toEqual(res.data.bytes)
|
|
})
|
|
})
|