| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /* eslint-disable prefer-reflect */
- import { testSaga } from 'redux-saga-test-plan';
- import axios from 'axios';
- import {
- apiRequest
- } from 'sagas/api';
- describe('API sagas', () => {
- describe('apiRequest', () => {
- const route = 'employees';
- const fields = {
- name: 'John Doe',
- email: 'john.doe@mubaloo.com'
- };
- it('should make an API POST request', () => {
- const response = { isResponse: true };
- testSaga(apiRequest, 'post', route, [], fields)
- .next()
- .call([axios, 'post'], '/api1/employees', fields)
- .next(response)
- .returns({ response, err: null });
- });
- it('should handle errors', () => {
- const err = new Error('something bad happened');
- testSaga(apiRequest, 'post', route, [], fields)
- .next()
- .call([axios, 'post'], '/api1/employees', fields)
- .throw(err)
- .returns({ response: null, err });
- });
- it('should make an API GET request', () => {
- const response = { isResponse: true };
- testSaga(apiRequest, 'get', route, ['a0b'])
- .next()
- .call([axios, 'get'], '/api1/employees/a0b')
- .next(response)
- .returns({ response, err: null });
- });
- });
- });
|