|
@@ -1,20 +1,18 @@
|
|
|
/* eslint-disable prefer-reflect */
|
|
/* eslint-disable prefer-reflect */
|
|
|
import { testSaga } from 'redux-saga-test-plan';
|
|
import { testSaga } from 'redux-saga-test-plan';
|
|
|
-import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
|
- apiRequest,
|
|
|
|
|
createDoc,
|
|
createDoc,
|
|
|
- createListener,
|
|
|
|
|
readDoc,
|
|
readDoc,
|
|
|
- readListener,
|
|
|
|
|
updateDoc,
|
|
updateDoc,
|
|
|
- updateListener,
|
|
|
|
|
deleteDoc,
|
|
deleteDoc,
|
|
|
- deleteListener,
|
|
|
|
|
crudSaga
|
|
crudSaga
|
|
|
} from 'sagas/crud';
|
|
} from 'sagas/crud';
|
|
|
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ apiRequest
|
|
|
|
|
+} from 'sagas/api';
|
|
|
|
|
+
|
|
|
import {
|
|
import {
|
|
|
DOC_CREATED,
|
|
DOC_CREATED,
|
|
|
DOC_READ,
|
|
DOC_READ,
|
|
@@ -34,44 +32,6 @@ import {
|
|
|
} from 'actions/crud';
|
|
} from 'actions/crud';
|
|
|
|
|
|
|
|
describe('crudSaga', () => {
|
|
describe('crudSaga', () => {
|
|
|
- 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 });
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
describe('createDoc', () => {
|
|
describe('createDoc', () => {
|
|
|
const route = 'employees';
|
|
const route = 'employees';
|
|
|
const pendingId = '<pendingId>';
|
|
const pendingId = '<pendingId>';
|