chore: Allow admins to choose the agent bot from the UI (#5895)

This commit is contained in:
Pranav Raj S
2022-11-18 08:54:32 -08:00
committed by GitHub
parent 33aacb3401
commit 16bfd68d95
11 changed files with 261 additions and 958 deletions

View File

@@ -90,4 +90,46 @@ describe('#actions', () => {
]);
});
});
describe('#setAgentBotInbox', () => {
it('sends correct actions if API is success', async () => {
axios.post.mockResolvedValue({ data: {} });
await actions.setAgentBotInbox({ commit }, { inboxId: 2, botId: 3 });
expect(commit.mock.calls).toEqual([
[types.SET_AGENT_BOT_UI_FLAG, { isSettingAgentBot: true }],
[types.SET_AGENT_BOT_INBOX, { inboxId: 2, agentBotId: 3 }],
[types.SET_AGENT_BOT_UI_FLAG, { isSettingAgentBot: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.post.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.setAgentBotInbox({ commit }, { inboxId: 2, botId: 3 })
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.SET_AGENT_BOT_UI_FLAG, { isSettingAgentBot: true }],
[types.SET_AGENT_BOT_UI_FLAG, { isSettingAgentBot: false }],
]);
});
});
describe('#fetchAgentBotInbox', () => {
it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: { agent_bot: { id: 3 } } });
await actions.fetchAgentBotInbox({ commit }, 2);
expect(commit.mock.calls).toEqual([
[types.SET_AGENT_BOT_UI_FLAG, { isFetchingAgentBot: true }],
[types.SET_AGENT_BOT_INBOX, { inboxId: 2, agentBotId: 3 }],
[types.SET_AGENT_BOT_UI_FLAG, { isFetchingAgentBot: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.fetchAgentBotInbox({ commit }, { inboxId: 2, agentBotId: 3 })
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.SET_AGENT_BOT_UI_FLAG, { isFetchingAgentBot: true }],
[types.SET_AGENT_BOT_UI_FLAG, { isFetchingAgentBot: false }],
]);
});
});
});

View File

@@ -41,4 +41,14 @@ describe('#mutations', () => {
expect(state.records).toEqual([agentBotRecords[0]]);
});
});
describe('#SET_AGENT_BOT_INBOX', () => {
it('set agent bot in the object', () => {
const state = { agentBotInbox: {} };
mutations[types.SET_AGENT_BOT_INBOX](state, {
agentBotId: 2,
inboxId: 3,
});
expect(state.agentBotInbox).toEqual({ 3: 2 });
});
});
});