1 |
|
2 |
|
3 |
|
4 |
|
5 | import { mockHttp, TEST_HTTP_URL } from '../../test/mockHttp';
|
6 |
|
7 | import Http from './index';
|
8 |
|
9 | describe('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 | });
|