UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

21 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const deserialize_rpc_response_1 = require("./deserialize-rpc-response"); const run_and_catch_1 = require("@carnesen/run-and-catch"); const coded_error_1 = require("@carnesen/coded-error"); describe(deserialize_rpc_response_1.deserializeRpcResponse.name, () => { it('returns the "result" field if there is one', () => { const result = deserialize_rpc_response_1.deserializeRpcResponse(JSON.stringify({ result: 'foo' })); expect(result).toBe('foo'); }); it('throws "no result" if the response has neither "result" nor "message"', async () => { const ex = await run_and_catch_1.runAndCatch(deserialize_rpc_response_1.deserializeRpcResponse, '{}'); expect(ex.message).toMatch(/no result/i); }); it('throws an error constructed from the response message', async () => { const response = { message: 'hello', code: 'HI', data: 'foo' }; const ex = await run_and_catch_1.runAndCatch(deserialize_rpc_response_1.deserializeRpcResponse, JSON.stringify(response)); expect(ex).toEqual(new coded_error_1.CodedError('hello', 'HI', 'foo')); }); }); //# sourceMappingURL=deserialize-rpc-response.test.js.map