(value: unknown, expected: unknown)
| 11 | describe.each(supportedDataTypes)('rpcLink: $name', ({ value, expected }) => { |
| 12 | describe.each(['GET', 'POST'] as const)('method: %s', (method) => { |
| 13 | async function assertSuccessCase(value: unknown, expected: unknown): Promise<true> { |
| 14 | const handler = vi.fn(({ input }) => input) |
| 15 | |
| 16 | const rpcHandler = new RPCHandler(os.handler(handler), { |
| 17 | strictGetMethodPluginEnabled: false, |
| 18 | }) |
| 19 | |
| 20 | const rpcLink = new RPCLink({ |
| 21 | url: 'http://api.example.com', |
| 22 | method, |
| 23 | fetch: async (request) => { |
| 24 | const { matched, response } = await rpcHandler.handle(request) |
| 25 | |
| 26 | if (matched) { |
| 27 | return response |
| 28 | } |
| 29 | |
| 30 | throw new Error('No procedure match') |
| 31 | }, |
| 32 | }) |
| 33 | |
| 34 | const output = await rpcLink.call([], value, { context: {} }) |
| 35 | |
| 36 | expect(output).toEqual(expected) |
| 37 | expect(handler).toHaveBeenCalledTimes(1) |
| 38 | expect(handler).toHaveBeenCalledWith(expect.objectContaining({ input: expected })) |
| 39 | |
| 40 | return true |
| 41 | } |
| 42 | |
| 43 | async function assertErrorCase(value: unknown, expected: unknown): Promise<true> { |
| 44 | const handler = vi.fn(({ input }) => { |
no test coverage detected