2021-06-18 14:38:58 +00:00
|
|
|
import contactAPI, { buildContactParams } from '../contacts';
|
2020-01-13 05:47:03 +00:00
|
|
|
import ApiClient from '../ApiClient';
|
2021-05-25 08:30:21 +00:00
|
|
|
import describeWithAPIMock from './apiSpecHelper';
|
2020-01-13 05:47:03 +00:00
|
|
|
|
|
|
|
describe('#ContactsAPI', () => {
|
|
|
|
it('creates correct instance', () => {
|
2021-05-25 08:30:21 +00:00
|
|
|
expect(contactAPI).toBeInstanceOf(ApiClient);
|
|
|
|
expect(contactAPI).toHaveProperty('get');
|
|
|
|
expect(contactAPI).toHaveProperty('show');
|
|
|
|
expect(contactAPI).toHaveProperty('create');
|
|
|
|
expect(contactAPI).toHaveProperty('update');
|
|
|
|
expect(contactAPI).toHaveProperty('delete');
|
|
|
|
expect(contactAPI).toHaveProperty('getConversations');
|
2021-12-03 03:12:44 +00:00
|
|
|
expect(contactAPI).toHaveProperty('filter');
|
2022-07-12 08:03:16 +00:00
|
|
|
expect(contactAPI).toHaveProperty('destroyAvatar');
|
2021-05-25 08:30:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describeWithAPIMock('API calls', context => {
|
|
|
|
it('#get', () => {
|
2021-06-18 14:38:58 +00:00
|
|
|
contactAPI.get(1, 'name', 'customer-support');
|
2021-05-25 08:30:21 +00:00
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
2021-07-23 13:09:24 +00:00
|
|
|
'/api/v1/contacts?include_contact_inboxes=false&page=1&sort=name&labels[]=customer-support'
|
2021-05-25 08:30:21 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#getConversations', () => {
|
|
|
|
contactAPI.getConversations(1);
|
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/1/conversations'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#getContactableInboxes', () => {
|
|
|
|
contactAPI.getContactableInboxes(1);
|
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/1/contactable_inboxes'
|
|
|
|
);
|
|
|
|
});
|
2021-06-14 05:06:00 +00:00
|
|
|
|
|
|
|
it('#getContactLabels', () => {
|
|
|
|
contactAPI.getContactLabels(1);
|
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/1/labels'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#updateContactLabels', () => {
|
|
|
|
const labels = ['support-query'];
|
|
|
|
contactAPI.updateContactLabels(1, labels);
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/1/labels',
|
|
|
|
{
|
|
|
|
labels,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-05-25 08:30:21 +00:00
|
|
|
it('#search', () => {
|
2021-06-18 14:38:58 +00:00
|
|
|
contactAPI.search('leads', 1, 'date', 'customer-support');
|
2021-05-25 08:30:21 +00:00
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
2021-07-23 13:09:24 +00:00
|
|
|
'/api/v1/contacts/search?include_contact_inboxes=false&page=1&sort=date&q=leads&labels[]=customer-support'
|
2021-05-25 08:30:21 +00:00
|
|
|
);
|
|
|
|
});
|
2021-09-29 06:31:58 +00:00
|
|
|
|
2021-11-11 09:53:33 +00:00
|
|
|
it('#destroyCustomAttributes', () => {
|
|
|
|
contactAPI.destroyCustomAttributes(1, ['cloudCustomer']);
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/1/destroy_custom_attributes',
|
|
|
|
{
|
|
|
|
custom_attributes: ['cloudCustomer'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-09-29 06:31:58 +00:00
|
|
|
it('#importContacts', () => {
|
|
|
|
const file = 'file';
|
|
|
|
contactAPI.importContacts(file);
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/import',
|
|
|
|
expect.any(FormData),
|
|
|
|
{
|
|
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2021-12-03 03:12:44 +00:00
|
|
|
|
|
|
|
it('#filter', () => {
|
|
|
|
const queryPayload = {
|
|
|
|
payload: [
|
|
|
|
{
|
|
|
|
attribute_key: 'email',
|
|
|
|
filter_operator: 'contains',
|
|
|
|
values: ['fayaz'],
|
|
|
|
query_operator: null,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
contactAPI.filter(1, 'name', queryPayload);
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/filter?include_contact_inboxes=false&page=1&sort=name',
|
|
|
|
queryPayload
|
|
|
|
);
|
|
|
|
});
|
2022-07-12 08:03:16 +00:00
|
|
|
|
|
|
|
it('#destroyAvatar', () => {
|
|
|
|
contactAPI.destroyAvatar(1);
|
|
|
|
expect(context.axiosMock.delete).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/contacts/1/avatar'
|
|
|
|
);
|
|
|
|
});
|
2020-01-13 05:47:03 +00:00
|
|
|
});
|
|
|
|
});
|
2021-06-18 14:38:58 +00:00
|
|
|
|
|
|
|
describe('#buildContactParams', () => {
|
|
|
|
it('returns correct string', () => {
|
2021-07-23 13:09:24 +00:00
|
|
|
expect(buildContactParams(1, 'name', '', '')).toBe(
|
|
|
|
'include_contact_inboxes=false&page=1&sort=name'
|
|
|
|
);
|
2021-06-18 14:38:58 +00:00
|
|
|
expect(buildContactParams(1, 'name', 'customer-support', '')).toBe(
|
2021-07-23 13:09:24 +00:00
|
|
|
'include_contact_inboxes=false&page=1&sort=name&labels[]=customer-support'
|
2021-06-18 14:38:58 +00:00
|
|
|
);
|
|
|
|
expect(
|
|
|
|
buildContactParams(1, 'name', 'customer-support', 'message-content')
|
2021-07-23 13:09:24 +00:00
|
|
|
).toBe(
|
|
|
|
'include_contact_inboxes=false&page=1&sort=name&q=message-content&labels[]=customer-support'
|
|
|
|
);
|
2021-06-18 14:38:58 +00:00
|
|
|
});
|
|
|
|
});
|