UNPKG

mir-client

Version:
49 lines (38 loc) 1.25 kB
import axios from 'axios' import MockAdapter from 'axios-mock-adapter' import post from '../src/post' import utils from '../src/utils' const mockAx = axios.create() const mock = new MockAdapter(mockAx) test('POST', () => { mock.onPost(/\/.*/).reply(201, { "_status": "OK", "_updated": "Fri May 18, 2018 15:22:27 GMT", "_id": "50ae43339fa12500024def5b", "_etag": "749093d334ebd05cf7f2b7dbfb7868605578db2c" }) var document = { 'test': true } const poster = post(mockAx, 'resource') return poster(document).send().then((result) => { expect(result.data).toEqual({ "_status": "OK", "_updated": "Fri May 18, 2018 15:22:27 GMT", "_id": "50ae43339fa12500024def5b", "_etag": "749093d334ebd05cf7f2b7dbfb7868605578db2c" }) expect(result.config.data).toEqual(JSON.stringify(document)) }) }) test('POST throws error if document is not object', () => { mock.onPost(/\/.*/).reply(201, { "_status": "OK", "_updated": "Fri May 18, 2018 15:22:27 GMT", "_id": "50ae43339fa12500024def5b", "_etag": "749093d334ebd05cf7f2b7dbfb7868605578db2c" }) var document = 'not json' const poster = post(mockAx, 'resource') expect(() => poster(document).send()).toThrow() })