2020-06-09 10:56:33 +00:00
|
|
|
import conversationAPI from '../../inbox/conversation';
|
|
|
|
import ApiClient from '../../ApiClient';
|
2021-05-25 08:30:21 +00:00
|
|
|
import describeWithAPIMock from '../apiSpecHelper';
|
2020-06-09 10:56:33 +00:00
|
|
|
|
|
|
|
describe('#ConversationAPI', () => {
|
|
|
|
it('creates correct instance', () => {
|
|
|
|
expect(conversationAPI).toBeInstanceOf(ApiClient);
|
|
|
|
expect(conversationAPI).toHaveProperty('get');
|
|
|
|
expect(conversationAPI).toHaveProperty('show');
|
|
|
|
expect(conversationAPI).toHaveProperty('create');
|
|
|
|
expect(conversationAPI).toHaveProperty('update');
|
|
|
|
expect(conversationAPI).toHaveProperty('delete');
|
|
|
|
expect(conversationAPI).toHaveProperty('toggleStatus');
|
|
|
|
expect(conversationAPI).toHaveProperty('assignAgent');
|
2021-03-15 13:07:03 +00:00
|
|
|
expect(conversationAPI).toHaveProperty('assignTeam');
|
2020-06-09 10:56:33 +00:00
|
|
|
expect(conversationAPI).toHaveProperty('markMessageRead');
|
|
|
|
expect(conversationAPI).toHaveProperty('toggleTyping');
|
|
|
|
expect(conversationAPI).toHaveProperty('mute');
|
2020-10-08 06:32:08 +00:00
|
|
|
expect(conversationAPI).toHaveProperty('unmute');
|
2020-06-09 10:56:33 +00:00
|
|
|
expect(conversationAPI).toHaveProperty('meta');
|
2020-08-17 05:55:13 +00:00
|
|
|
expect(conversationAPI).toHaveProperty('sendEmailTranscript');
|
2020-06-09 10:56:33 +00:00
|
|
|
});
|
2020-10-08 06:32:08 +00:00
|
|
|
|
2021-05-25 08:30:21 +00:00
|
|
|
describeWithAPIMock('API calls', context => {
|
|
|
|
it('#get conversations', () => {
|
|
|
|
conversationAPI.get({
|
|
|
|
inboxId: 1,
|
|
|
|
status: 'open',
|
|
|
|
assigneeType: 'me',
|
|
|
|
page: 1,
|
|
|
|
labels: [],
|
|
|
|
teamId: 1,
|
|
|
|
});
|
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/conversations',
|
|
|
|
{
|
|
|
|
params: {
|
|
|
|
inbox_id: 1,
|
|
|
|
team_id: 1,
|
|
|
|
status: 'open',
|
|
|
|
assignee_type: 'me',
|
|
|
|
page: 1,
|
|
|
|
labels: [],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#search', () => {
|
|
|
|
conversationAPI.search({
|
|
|
|
q: 'leads',
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/conversations/search',
|
|
|
|
{
|
|
|
|
params: {
|
|
|
|
q: 'leads',
|
|
|
|
page: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#toggleStatus', () => {
|
|
|
|
conversationAPI.toggleStatus({ conversationId: 12, status: 'online' });
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
`/api/v1/conversations/12/toggle_status`,
|
|
|
|
{
|
|
|
|
status: 'online',
|
2021-07-23 09:54:07 +00:00
|
|
|
snoozed_until: null,
|
2021-05-25 08:30:21 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#assignAgent', () => {
|
|
|
|
conversationAPI.assignAgent({ conversationId: 12, agentId: 34 });
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
`/api/v1/conversations/12/assignments?assignee_id=34`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#assignTeam', () => {
|
|
|
|
conversationAPI.assignTeam({ conversationId: 12, teamId: 1 });
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
`/api/v1/conversations/12/assignments`,
|
|
|
|
{
|
|
|
|
team_id: 1,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2020-10-08 06:32:08 +00:00
|
|
|
|
2021-05-25 08:30:21 +00:00
|
|
|
it('#markMessageRead', () => {
|
|
|
|
conversationAPI.markMessageRead({ id: 12 });
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
`/api/v1/conversations/12/update_last_seen`
|
|
|
|
);
|
|
|
|
});
|
2020-10-08 06:32:08 +00:00
|
|
|
|
2021-05-25 08:30:21 +00:00
|
|
|
it('#toggleTyping', () => {
|
|
|
|
conversationAPI.toggleTyping({
|
|
|
|
conversationId: 12,
|
|
|
|
status: 'typing_on',
|
|
|
|
});
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
`/api/v1/conversations/12/toggle_typing_status`,
|
|
|
|
{
|
|
|
|
typing_status: 'typing_on',
|
|
|
|
}
|
|
|
|
);
|
2020-10-08 06:32:08 +00:00
|
|
|
});
|
|
|
|
|
2021-05-25 08:30:21 +00:00
|
|
|
it('#mute', () => {
|
|
|
|
conversationAPI.mute(45);
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/conversations/45/mute'
|
|
|
|
);
|
2020-10-08 06:32:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('#unmute', () => {
|
|
|
|
conversationAPI.unmute(45);
|
2021-05-25 08:30:21 +00:00
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
2020-10-08 06:32:08 +00:00
|
|
|
'/api/v1/conversations/45/unmute'
|
|
|
|
);
|
|
|
|
});
|
2021-05-25 08:30:21 +00:00
|
|
|
|
|
|
|
it('#meta', () => {
|
|
|
|
conversationAPI.meta({
|
|
|
|
inboxId: 1,
|
|
|
|
status: 'open',
|
|
|
|
assigneeType: 'me',
|
|
|
|
labels: [],
|
|
|
|
teamId: 1,
|
|
|
|
});
|
|
|
|
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/conversations/meta',
|
|
|
|
{
|
|
|
|
params: {
|
|
|
|
inbox_id: 1,
|
|
|
|
team_id: 1,
|
|
|
|
status: 'open',
|
|
|
|
assignee_type: 'me',
|
|
|
|
labels: [],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('#sendEmailTranscript', () => {
|
|
|
|
conversationAPI.sendEmailTranscript({
|
|
|
|
conversationId: 45,
|
|
|
|
email: 'john@acme.inc',
|
|
|
|
});
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/conversations/45/transcript',
|
|
|
|
{
|
|
|
|
email: 'john@acme.inc',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2021-10-30 01:39:46 +00:00
|
|
|
|
|
|
|
it('#updateCustomAttributes', () => {
|
|
|
|
conversationAPI.updateCustomAttributes({
|
|
|
|
conversationId: 45,
|
|
|
|
customAttributes: { order_d: '1001' },
|
|
|
|
});
|
|
|
|
expect(context.axiosMock.post).toHaveBeenCalledWith(
|
|
|
|
'/api/v1/conversations/45/custom_attributes',
|
|
|
|
{
|
|
|
|
custom_attributes: { order_d: '1001' },
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2020-10-08 06:32:08 +00:00
|
|
|
});
|
2020-06-09 10:56:33 +00:00
|
|
|
});
|