2020-11-10 09:55:26 +00:00
|
|
|
import types from '../../../mutation-types';
|
|
|
|
import Contacts from '../../contacts';
|
|
|
|
const { mutations } = Contacts;
|
2020-01-01 17:00:43 +00:00
|
|
|
|
|
|
|
describe('#mutations', () => {
|
|
|
|
describe('#SET_CONTACTS', () => {
|
|
|
|
it('set contact records', () => {
|
2020-06-02 17:29:02 +00:00
|
|
|
const state = { records: {} };
|
2020-11-10 09:55:26 +00:00
|
|
|
mutations[types.SET_CONTACTS](state, [
|
2020-01-01 17:00:43 +00:00
|
|
|
{ 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
|
|
|
};
|
2020-11-10 09:55:26 +00:00
|
|
|
mutations[types.SET_CONTACT_ITEM](state, {
|
2020-01-01 17:00:43 +00:00
|
|
|
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
|
|
|
};
|
2020-11-10 09:55:26 +00:00
|
|
|
mutations[types.EDIT_CONTACT](state, {
|
2020-01-01 17:00:43 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|