MCPcopy
hub / github.com/tsrpc/tsrpc / testApi

Function testApi

test/ws.test.ts:21–63  ·  view source on GitHub ↗
(server: WsServer<ServiceType>, client: WsClient<ServiceType>)

Source from the content-addressed store, hash-verified

19})
20
21async function testApi(server: WsServer<ServiceType>, client: WsClient<ServiceType>) {
22 // Succ
23 assert.deepStrictEqual(await client.callApi('Test', {
24 name: 'Req1'
25 }), {
26 reply: 'Test reply: Req1'
27 });
28 assert.deepStrictEqual(await client.callApi('a/b/c/Test', {
29 name: 'Req2'
30 }), {
31 reply: 'a/b/c/Test reply: Req2'
32 });
33
34 // Inner error
35 for (let v of ['Test', 'a/b/c/Test']) {
36 assert.deepStrictEqual(await client.callApi(v as any, {
37 name: 'InnerError'
38 }).catch(e => ({
39 isSucc: false,
40 message: e.message,
41 info: e.info
42 })), {
43 isSucc: false,
44 message: 'Internal server error',
45 info: 'INTERNAL_ERR'
46 });
47 }
48
49 // TsrpcError
50 for (let v of ['Test', 'a/b/c/Test']) {
51 assert.deepStrictEqual(await client.callApi(v as any, {
52 name: 'TsrpcError'
53 }).catch(e => ({
54 isSucc: false,
55 message: e.message,
56 info: e.info
57 })), {
58 isSucc: false,
59 message: v + ' TsrpcError',
60 info: 'ErrInfo ' + v
61 });
62 }
63}
64
65describe('WsClient', function () {
66 it('implement API manually', async function () {

Callers 1

ws.test.tsFile · 0.70

Calls 1

callApiMethod · 0.45

Tested by

no test coverage detected