import { expect } from 'chai'; import { DOC_CREATED, DOC_CREATE_RESPONDED, DOC_READ, DOC_READ_RESPONDED, DOC_UPDATED, DOC_UPDATE_RESPONDED, DOC_DELETED, DOC_DELETE_RESPONDED } from 'constants/actions'; import { docCreated, docCreateResponded, docRead, docReadResponded, docUpdated, docUpdateResponded, docDeleted, docDeleteResponded } from 'actions/crud'; describe('CRUD actions', () => { describe('docCreated', () => { it('should return DOC_CREATED with fields', () => { const route = 'employees'; const pendingId = 'mypendingid'; const fields = { name: 'Foo', email: 'foo@mubaloo.com' }; const action = docCreated(route, pendingId, fields); expect(action).to.deep.equal({ type: DOC_CREATED, route, pendingId, fields }); }); }); describe('docCreateResponded', () => { it('should return DOC_CREATE_RESPONDED with error / response', () => { const route = 'employees'; const pendingId = 'mypendingid'; const error = { error: true }; const response = { response: true }; const action = docCreateResponded(route, pendingId, error, response); expect(action).to.deep.equal({ type: DOC_CREATE_RESPONDED, route, pendingId, err: error, response }); }); }); describe('docRead', () => { it('should return DOC_READ', () => { const route = 'employees'; const action = docRead(route); expect(action).to.deep.equal({ type: DOC_READ, route }); }); }); describe('docReadResponded', () => { it('should return DOC_READ_RESPONDED with error / response', () => { const route = 'employees'; const error = { error: true }; const response = { response: true }; const action = docReadResponded(route, error, response); expect(action).to.deep.equal({ type: DOC_READ_RESPONDED, route, err: error, response }); }); }); describe('docUpdated', () => { it('should return DOC_UPDATED', () => { const route = 'employees'; const id = 'a8b8ce23'; const fields = { name: 'Bar' }; const action = docUpdated(route, id, fields); expect(action).to.deep.equal({ type: DOC_UPDATED, route, id, fields }); }); }); describe('docUpdateResponded', () => { it('should return DOC_UPDATE_RESPONDED with error / response', () => { const route = 'employees'; const id = 'a0fb56'; const error = { error: true }; const response = { response: true }; const action = docUpdateResponded(route, id, error, response); expect(action).to.deep.equal({ type: DOC_UPDATE_RESPONDED, route, id, err: error, response }); }); }); describe('docDeleted', () => { it('should return DOC_DELETED', () => { const route = 'employees'; const id = 'a8b8ce23'; const action = docDeleted(route, id); expect(action).to.deep.equal({ type: DOC_DELETED, route, id }); }); }); describe('docDeleteResponded', () => { it('should return DOC_DELETE_RESPONDED with error', () => { const route = 'employees'; const id = 'a0fb56'; const error = { error: true }; const action = docDeleteResponded(route, id, error); expect(action).to.deep.equal({ type: DOC_DELETE_RESPONDED, route, id, err: error }); }); }); });