This repository has no description
1import { describe, expect, it, vi } from 'vitest';
2import * as knot from './knot';
3import { ClientResponseError, createBobbinClient, type BobbinContext } from './client';
4
5const jsonResponse = (body: unknown, init: ResponseInit = {}): Response =>
6 new Response(JSON.stringify(body), {
7 status: 200,
8 headers: { 'content-type': 'application/json' },
9 ...init
10 });
11
12const makeCtx = (fetchMock: typeof globalThis.fetch): BobbinContext =>
13 createBobbinClient({ serviceUrl: 'https://bobbin.test', fetch: fetchMock });
14
15describe('knot.archive (binary passthrough)', () => {
16 it('throws ClientResponseError on a non-2xx archive response', async () => {
17 const fetchMock = vi
18 .fn<typeof globalThis.fetch>()
19 .mockResolvedValue(jsonResponse({ error: 'UpstreamGone' }, { status: 502 }));
20 const err = await knot
21 .archive(makeCtx(fetchMock), { repo: 'did:plc:x/r', ref: 'main' })
22 .catch((e: unknown) => e);
23 expect(err).toBeInstanceOf(ClientResponseError);
24 expect((err as ClientResponseError).status).toBe(502);
25 });
26});