UNPKG

1.18 kBJavaScriptView Raw
1// Copyright 2017-2018 @polkadot/api-provider authors & contributors
2// This software may be modified and distributed under the terms
3// of the ISC license. See the LICENSE file for details.
4
5import { mockHttp, TEST_HTTP_URL } from '../../test/mockHttp';
6
7import Http from './index';
8
9describe('send', () => {
10 let http;
11 let mock;
12
13 beforeEach(() => {
14 http = new Http(TEST_HTTP_URL);
15 });
16
17 afterEach(() => {
18 if (mock) {
19 mock.done();
20 mock = null;
21 }
22 });
23
24 it('passes the body through correctly', () => {
25 mock = mockHttp([{
26 method: 'test_body',
27 reply: {
28 result: 'ok'
29 }
30 }]);
31
32 return http
33 .send('test_body', ['param'])
34 .then((result) => {
35 expect(mock.body['test_body']).toEqual({
36 id: 1,
37 jsonrpc: '2.0',
38 method: 'test_body',
39 params: ['param']
40 });
41 });
42 });
43
44 it('throws error when !response.ok', () => {
45 mock = mockHttp([{
46 code: 500,
47 method: 'test_error'
48 }]);
49
50 return http
51 .send('test_error', [])
52 .catch((error) => {
53 expect(error.message).toMatch(/\[500\]: Internal Server/);
54 });
55 });
56});