chore: Add Assignable Agents API (#4722)
This commit is contained in:
16
app/javascript/dashboard/api/assignableAgents.js
Normal file
16
app/javascript/dashboard/api/assignableAgents.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/* global axios */
|
||||
import ApiClient from './ApiClient';
|
||||
|
||||
class AssignableAgents extends ApiClient {
|
||||
constructor() {
|
||||
super('assignable_agents', { accountScoped: true });
|
||||
}
|
||||
|
||||
get(inboxIds) {
|
||||
return axios.get(this.url, {
|
||||
params: { inbox_ids: inboxIds },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new AssignableAgents();
|
||||
@@ -6,10 +6,6 @@ class Inboxes extends ApiClient {
|
||||
super('inboxes', { accountScoped: true });
|
||||
}
|
||||
|
||||
getAssignableAgents(inboxId) {
|
||||
return axios.get(`${this.url}/${inboxId}/assignable_agents`);
|
||||
}
|
||||
|
||||
getCampaigns(inboxId) {
|
||||
return axios.get(`${this.url}/${inboxId}/campaigns`);
|
||||
}
|
||||
|
||||
18
app/javascript/dashboard/api/specs/assignableAgents.spec.js
Normal file
18
app/javascript/dashboard/api/specs/assignableAgents.spec.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import assignableAgentsAPI from '../assignableAgents';
|
||||
import describeWithAPIMock from './apiSpecHelper';
|
||||
|
||||
describe('#AssignableAgentsAPI', () => {
|
||||
describeWithAPIMock('API calls', context => {
|
||||
it('#getAssignableAgents', () => {
|
||||
assignableAgentsAPI.get([1]);
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
'/api/v1/assignable_agents',
|
||||
{
|
||||
params: {
|
||||
inbox_ids: [1],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -10,17 +10,9 @@ describe('#InboxesAPI', () => {
|
||||
expect(inboxesAPI).toHaveProperty('create');
|
||||
expect(inboxesAPI).toHaveProperty('update');
|
||||
expect(inboxesAPI).toHaveProperty('delete');
|
||||
expect(inboxesAPI).toHaveProperty('getAssignableAgents');
|
||||
expect(inboxesAPI).toHaveProperty('getCampaigns');
|
||||
});
|
||||
describeWithAPIMock('API calls', context => {
|
||||
it('#getAssignableAgents', () => {
|
||||
inboxesAPI.getAssignableAgents(1);
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
'/api/v1/inboxes/1/assignable_agents'
|
||||
);
|
||||
});
|
||||
|
||||
it('#getCampaigns', () => {
|
||||
inboxesAPI.getCampaigns(2);
|
||||
expect(context.axiosMock.get).toHaveBeenCalledWith(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
import InboxesAPI from 'dashboard/api/inboxes.js';
|
||||
import AssignableAgentsAPI from '../../api/assignableAgents';
|
||||
|
||||
const state = {
|
||||
records: {},
|
||||
@@ -31,7 +31,7 @@ export const actions = {
|
||||
try {
|
||||
const {
|
||||
data: { payload },
|
||||
} = await InboxesAPI.getAssignableAgents(inboxId);
|
||||
} = await AssignableAgentsAPI.get([inboxId]);
|
||||
commit(types.SET_INBOX_ASSIGNABLE_AGENTS, { inboxId, members: payload });
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
|
||||
Reference in New Issue
Block a user