[Refactor] Cleanup agent store and actions (#373)
* Cleanup agent store and actions * Move set/create/update/destroy to helpers * Update mutation specs * Add specs for API helper * Fix edit/delete action visibility * Add actions specs * Remove unused API helpers * Remove duplicates * Remove duplicates * Fix duplicate
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import * as types from '../../../mutation-types';
|
||||
import { mutations } from '../../agents';
|
||||
|
||||
describe('#mutations', () => {
|
||||
describe('#SET_AGENTS', () => {
|
||||
it('set agent records', () => {
|
||||
const state = { records: [] };
|
||||
mutations[types.default.SET_AGENTS](state, [
|
||||
{ id: 1, name: 'Agent1', email: 'agent1@chatwoot.com' },
|
||||
]);
|
||||
expect(state.records).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent1',
|
||||
email: 'agent1@chatwoot.com',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_AGENT', () => {
|
||||
it('push newly created agent data to the store', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Agent1', email: 'agent1@chatwoot.com' }],
|
||||
};
|
||||
mutations[types.default.ADD_AGENT](state, {
|
||||
id: 2,
|
||||
name: 'Agent2',
|
||||
email: 'agent2@chatwoot.com',
|
||||
});
|
||||
expect(state.records).toEqual([
|
||||
{ id: 1, name: 'Agent1', email: 'agent1@chatwoot.com' },
|
||||
{ id: 2, name: 'Agent2', email: 'agent2@chatwoot.com' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#EDIT_AGENT', () => {
|
||||
it('sets allMessagesLoaded flag if payload is empty', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Agent1', email: 'agent1@chatwoot.com' }],
|
||||
};
|
||||
mutations[types.default.EDIT_AGENT](state, {
|
||||
id: 1,
|
||||
name: 'Agent2',
|
||||
email: 'agent2@chatwoot.com',
|
||||
});
|
||||
expect(state.records).toEqual([
|
||||
{ id: 1, name: 'Agent2', email: 'agent2@chatwoot.com' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_AGENT', () => {
|
||||
it('sets allMessagesLoaded flag if payload is empty', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Agent1', email: 'agent1@chatwoot.com' }],
|
||||
};
|
||||
mutations[types.default.DELETE_AGENT](state, 1);
|
||||
expect(state.records).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user