|
1 | | -import { assertEquals, assertObjectMatch } from 'std/assert/mod.ts' |
2 | | -import { JSONRPCClient, JSONRPCServer } from './index.ts' |
| 1 | +import { |
| 2 | + assertEquals, |
| 3 | + assertInstanceOf, |
| 4 | + assertObjectMatch, |
| 5 | +} from 'std/assert/mod.ts' |
| 6 | +import { |
| 7 | + JSONRPCClient, |
| 8 | + JSONRPCFulfilledResult, |
| 9 | + JSONRPCServer, |
| 10 | +} from './index.ts' |
3 | 11 |
|
4 | 12 | Deno.test('JSONRPCClient/JSONRPCServer', async () => { |
5 | 13 | const methodSet = { |
@@ -45,3 +53,31 @@ Deno.test('JSONRPCClient/JSONRPCServer', async () => { |
45 | 53 | }], |
46 | 54 | ) |
47 | 55 | }) |
| 56 | + |
| 57 | +Deno.test({ |
| 58 | + name: 'JSONRPCClient/aria2', |
| 59 | + // also need to run `aria2c --enable-rpc` |
| 60 | + ignore: Deno.permissions.querySync({ name: 'net', host: 'localhost:6800' }) |
| 61 | + .state !== |
| 62 | + 'granted', |
| 63 | + fn: async () => { |
| 64 | + const client = new JSONRPCClient((json) => |
| 65 | + fetch('http://localhost:6800/jsonrpc', { |
| 66 | + method: 'POST', |
| 67 | + body: json, |
| 68 | + }).then((res) => res.text()) |
| 69 | + ) |
| 70 | + |
| 71 | + assertInstanceOf(await client.request('system.listMethods'), Array) |
| 72 | + |
| 73 | + assertEquals(await client.notify('system.listMethods'), undefined) |
| 74 | + |
| 75 | + const [r1, r2] = await client.batch( |
| 76 | + client.createRequest('system.listMethods'), |
| 77 | + client.createRequest('system.listMethods'), |
| 78 | + ) as JSONRPCFulfilledResult[] |
| 79 | + |
| 80 | + assertObjectMatch(r1, { status: 'fulfilled' }) |
| 81 | + assertObjectMatch(r2, { status: 'fulfilled' }) |
| 82 | + }, |
| 83 | +}) |
0 commit comments