|
1 | 1 | import { assert } from 'chai';
|
2 | 2 | import * as HTTPMethods from '../../src/constants/http-methods';
|
3 |
| -import superagentAdapter, { createRequest } from '../../src/adapters/superagent'; |
| 3 | +import superagentAdapter from '../../src/adapters/superagent'; |
4 | 4 |
|
5 | 5 | describe('superagent adapter', () => {
|
6 |
| - it('must return an object with both execute and abort functions', () => { |
| 6 | + it('must return an object with both execute and abort functions, as well as the request instance', () => { |
7 | 7 | const adapter = superagentAdapter('http://localhost', HTTPMethods.GET);
|
8 | 8 | assert.isFunction(adapter.execute);
|
9 | 9 | assert.isFunction(adapter.abort);
|
| 10 | + assert(adapter.instance); |
10 | 11 | });
|
11 | 12 |
|
12 |
| - describe('createRequest', () => { |
13 |
| - it('must return a DELETE request when supplied a DELETE method', () => { |
14 |
| - const request = createRequest('http://localhost', HTTPMethods.DELETE); |
15 |
| - assert.equal(request.method, HTTPMethods.DELETE); |
16 |
| - }); |
17 |
| - |
18 |
| - it('must return a GET request when supplied a GET method', () => { |
19 |
| - const request = createRequest('http://localhost', HTTPMethods.GET); |
20 |
| - assert.equal(request.method, HTTPMethods.GET); |
21 |
| - }); |
22 |
| - |
23 |
| - it('must return a PATCH request when supplied a PATCH method', () => { |
24 |
| - const request = createRequest('http://localhost', HTTPMethods.PATCH); |
25 |
| - assert.equal(request.method, HTTPMethods.PATCH); |
26 |
| - }); |
27 |
| - |
28 |
| - it('must return a POST request when supplied a POST method', () => { |
29 |
| - const request = createRequest('http://localhost', HTTPMethods.POST); |
30 |
| - assert.equal(request.method, HTTPMethods.POST); |
31 |
| - }); |
32 |
| - |
33 |
| - it('must return a PUT request when supplied a PUT method', () => { |
34 |
| - const request = createRequest('http://localhost', HTTPMethods.PUT); |
35 |
| - assert.equal(request.method, HTTPMethods.PUT); |
36 |
| - }); |
37 |
| - |
38 |
| - it('must throw an error when supplied an invalid HTTP method', () => { |
39 |
| - const request = () => createRequest('http://localhost', 'abc'); |
40 |
| - assert.throws(request, /Unsupported HTTP method/); |
41 |
| - }); |
| 13 | + it('must return a HEAD request when supplied a HEAD method', () => { |
| 14 | + const { instance } = superagentAdapter('http://localhost', HTTPMethods.HEAD); |
| 15 | + assert.equal(instance.method, HTTPMethods.HEAD); |
| 16 | + }); |
| 17 | + |
| 18 | + it('must return a DELETE request when supplied a DELETE method', () => { |
| 19 | + const { instance } = superagentAdapter('http://localhost', HTTPMethods.DELETE); |
| 20 | + assert.equal(instance.method, HTTPMethods.DELETE); |
| 21 | + }); |
| 22 | + |
| 23 | + it('must return a GET request when supplied a GET method', () => { |
| 24 | + const { instance } = superagentAdapter('http://localhost', HTTPMethods.GET); |
| 25 | + assert.equal(instance.method, HTTPMethods.GET); |
| 26 | + }); |
| 27 | + |
| 28 | + it('must return a PATCH request when supplied a PATCH method', () => { |
| 29 | + const { instance } = superagentAdapter('http://localhost', HTTPMethods.PATCH); |
| 30 | + assert.equal(instance.method, HTTPMethods.PATCH); |
| 31 | + }); |
| 32 | + |
| 33 | + it('must return a POST request when supplied a POST method', () => { |
| 34 | + const { instance } = superagentAdapter('http://localhost', HTTPMethods.POST); |
| 35 | + assert.equal(instance.method, HTTPMethods.POST); |
| 36 | + }); |
| 37 | + |
| 38 | + it('must return a PUT request when supplied a PUT method', () => { |
| 39 | + const { instance } = superagentAdapter('http://localhost', HTTPMethods.PUT); |
| 40 | + assert.equal(instance.method, HTTPMethods.PUT); |
| 41 | + }); |
| 42 | + |
| 43 | + it('must throw an error when supplied an invalid HTTP method', () => { |
| 44 | + const invalid = () => superagentAdapter('http://localhost', 'abc'); |
| 45 | + assert.throws(invalid, /Unsupported HTTP method/); |
42 | 46 | });
|
43 | 47 | });
|
0 commit comments