diff --git a/test/parser_test.js b/test/parser_test.js index a58d582..d5757b6 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -24,12 +24,12 @@ afterEach(() => { describe('Parser', () => { it('should throw an error with a generic message if one is not returned on the response', async () => { - nock(`http://${config.bitcoin.host}:${config.bitcoin.port}/`) + nock(`http://${config.bitgesell.host}:${config.bitgesell.port}/`) .post('/') .reply(200, '{ "result": null, "error": { "code": -32601 }, "id": "69837016239933"}'); try { - await new Client(config.bitcoin).command('foobar'); + await new Client(config.bitgesell).command('foobar'); should.fail(); } catch (e) { @@ -40,12 +40,12 @@ describe('Parser', () => { }); it('should throw an error if the response does not include a `result`', async () => { - nock(`http://${config.bitcoin.host}:${config.bitcoin.port}/`) + nock(`http://${config.bitgesell.host}:${config.bitgesell.port}/`) .post('/') .reply(200, '{ "error": null, "id": "69837016239933"}'); try { - await new Client(config.bitcoin).command('foobar2'); + await new Client(config.bitgesell).command('foobar2'); should.fail(); } catch (e) { @@ -56,8 +56,12 @@ describe('Parser', () => { }); it('should throw an error if the response is not successful but is json-formatted', async () => { + nock(`http://${config.bitgesellMultiWallet.host}:${config.bitgesellMultiWallet.port}/`) + .post('/wallet/foobar') + .reply(200, '{ "result": null, "error": { "code": -18, "message": "Requested wallet does not exist or is not loaded" }, "id": "69837016239933"}'); + try { - await new Client(_.defaults({ wallet: 'foobar' }, config.bitcoinMultiWallet)).getWalletInfo(); + await new Client(_.defaults({ wallet: 'foobar' }, config.bitgesellMultiWallet)).getWalletInfo(); } catch (e) { should(e).be.an.instanceOf(RpcError); should(e.message).equal('Requested wallet does not exist or is not loaded'); @@ -67,7 +71,16 @@ describe('Parser', () => { describe('headers', () => { it('should return the response headers if `headers` is enabled', async () => { - const [info, headers] = await new Client(_.defaults({ headers: true }, config.bitcoin)).getNetworkInfo(); + nock(`http://${config.bitgesell.host}:${config.bitgesell.port}/`) + .post('/') + .reply(200, '{ "result": { "version": 180000 }, "error": null, "id": "69837016239933"}', { + connection: 'close', + 'content-length': '68', + 'content-type': 'application/json', + date: 'Mon, 08 Jun 2026 00:00:00 GMT' + }); + + const [info, headers] = await new Client(_.defaults({ headers: true }, config.bitgesell)).getNetworkInfo(); should(info).be.an.Object(); should(headers).have.keys('date', 'connection', 'content-length', 'content-type'); @@ -78,7 +91,20 @@ describe('Parser', () => { { method: 'getbalance' }, { method: 'getbalance' } ]; - const [addresses, headers] = await new Client(_.defaults({ headers: true }, config.bitcoin)).command(batch); + nock(`http://${config.bitgesell.host}:${config.bitgesell.port}/`) + .post('/') + .reply(200, (uri, body) => JSON.parse(body).map((request, index) => ({ + error: null, + id: request.id, + result: index + 1 + })), { + connection: 'close', + 'content-length': '107', + 'content-type': 'application/json', + date: 'Mon, 08 Jun 2026 00:00:00 GMT' + }); + + const [addresses, headers] = await new Client(_.defaults({ headers: true }, config.bitgesell)).command(batch); should(addresses).have.length(batch.length); should(headers).have.keys('date', 'connection', 'content-length', 'content-type');