2020-01-01 17:00:43 +00:00
|
|
|
import * as types from '../../../mutation-types';
|
|
|
|
import { mutations } from '../../contacts';
|
|
|
|
|
|
|
|
describe('#mutations', () => {
|
|
|
|
describe('#SET_CONTACTS', () => {
|
|
|
|
it('set contact records', () => {
|
2020-06-02 17:29:02 +00:00
|
|
|
const state = { records: {} };
|
2020-01-01 17:00:43 +00:00
|
|
|
mutations[types.default.SET_CONTACTS](state, [
|
|
|
|
{ id: 1, name: 'contact1', email: 'contact1@chatwoot.com' },
|
|
|
|
]);
|
2020-06-02 17:29:02 +00:00
|
|
|
expect(state.records).toEqual({
|
|
|
|
1: {
|
2020-01-01 17:00:43 +00:00
|
|
|
id: 1,
|
|
|
|
name: 'contact1',
|
|
|
|
email: 'contact1@chatwoot.com',
|
|
|
|
},
|
2020-06-02 17:29:02 +00:00
|
|
|
});
|
2020-01-01 17:00:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#SET_CONTACT_ITEM', () => {
|
|
|
|
it('push contact data to the store', () => {
|
|
|
|
const state = {
|
2020-06-02 17:29:02 +00:00
|
|
|
records: {
|
|
|
|
1: { id: 1, name: 'contact1', email: 'contact1@chatwoot.com' },
|
|
|
|
},
|
2020-01-01 17:00:43 +00:00
|
|
|
};
|
|
|
|
mutations[types.default.SET_CONTACT_ITEM](state, {
|
|
|
|
id: 2,
|
|
|
|
name: 'contact2',
|
|
|
|
email: 'contact2@chatwoot.com',
|
|
|
|
});
|
2020-06-02 17:29:02 +00:00
|
|
|
expect(state.records).toEqual({
|
|
|
|
1: { id: 1, name: 'contact1', email: 'contact1@chatwoot.com' },
|
|
|
|
2: { id: 2, name: 'contact2', email: 'contact2@chatwoot.com' },
|
|
|
|
});
|
2020-01-01 17:00:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#EDIT_CONTACT', () => {
|
|
|
|
it('update contact', () => {
|
|
|
|
const state = {
|
2020-06-02 17:29:02 +00:00
|
|
|
records: {
|
|
|
|
1: { id: 1, name: 'contact1', email: 'contact1@chatwoot.com' },
|
|
|
|
},
|
2020-01-01 17:00:43 +00:00
|
|
|
};
|
|
|
|
mutations[types.default.EDIT_CONTACT](state, {
|
|
|
|
id: 1,
|
|
|
|
name: 'contact2',
|
|
|
|
email: 'contact2@chatwoot.com',
|
|
|
|
});
|
2020-06-02 17:29:02 +00:00
|
|
|
expect(state.records).toEqual({
|
|
|
|
1: { id: 1, name: 'contact2', email: 'contact2@chatwoot.com' },
|
|
|
|
});
|
2020-01-01 17:00:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|