feat: SLA reports store (#9185)
- Added sla reports actions, getters and mutations.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import axios from 'axios';
|
||||
import { actions } from '../../SLAReports';
|
||||
import appliedSlas from './fixtures';
|
||||
import types from '../../../mutation-types';
|
||||
|
||||
const commit = jest.fn();
|
||||
global.axios = axios;
|
||||
jest.mock('axios');
|
||||
|
||||
describe('#actions', () => {
|
||||
describe('#get', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({
|
||||
data: { payload: appliedSlas, meta: { count: 1 } },
|
||||
});
|
||||
await actions.get({ commit }, {});
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_SLA_REPORTS, appliedSlas],
|
||||
[types.SET_SLA_REPORTS_META, { count: 1 }],
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.get({ commit }, { teamId: 1 })).rejects.toThrow(
|
||||
Error
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMetrics', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({ data: { metrics: { count: 1 } } });
|
||||
await actions.getMetrics({ commit }, {});
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetchingMetrics: true }],
|
||||
[types.SET_SLA_REPORTS_METRICS, { metrics: { count: 1 } }],
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetchingMetrics: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.getMetrics({ commit }, { teamId: 1 });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetchingMetrics: true }],
|
||||
[types.SET_SLA_REPORTS_UI_FLAG, { isFetchingMetrics: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
export default [
|
||||
{
|
||||
id: 23,
|
||||
sla_policy_id: 7,
|
||||
conversation_id: 152,
|
||||
sla_status: 'active_with_misses',
|
||||
created_at: '2024-03-31T07:50:53.518Z',
|
||||
updated_at: '2024-03-31T07:55:06.451Z',
|
||||
conversation: {
|
||||
id: 152,
|
||||
uuid: '2f9a988d-418f-47d9-b4dc-c441f28da7c2',
|
||||
account_id: 1,
|
||||
},
|
||||
sla_events: [
|
||||
{
|
||||
id: 14,
|
||||
event_type: 'frt',
|
||||
meta: {},
|
||||
updated_at: 1711871706,
|
||||
created_at: 1711871706,
|
||||
},
|
||||
{
|
||||
id: 15,
|
||||
event_type: 'rt',
|
||||
meta: {},
|
||||
updated_at: 1711871706,
|
||||
created_at: 1711871706,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 24,
|
||||
sla_policy_id: 7,
|
||||
conversation_id: 153,
|
||||
sla_status: 'active_with_misses',
|
||||
created_at: '2024-03-31T07:57:49.659Z',
|
||||
updated_at: '2024-03-31T08:00:31.627Z',
|
||||
conversation: {
|
||||
id: 153,
|
||||
uuid: 'd5d97961-4341-469e-accf-f13f25a14c3c',
|
||||
},
|
||||
sla_events: [
|
||||
{
|
||||
id: 16,
|
||||
event_type: 'rt',
|
||||
meta: {},
|
||||
updated_at: 1711872031,
|
||||
created_at: 1711872031,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,24 @@
|
||||
import { getters } from '../../SLAReports';
|
||||
import appliedSlas from './fixtures';
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getAppliedSlas', () => {
|
||||
const state = {
|
||||
records: [appliedSlas[0]],
|
||||
};
|
||||
expect(getters.getAll(state)).toEqual([appliedSlas[0]]);
|
||||
});
|
||||
|
||||
it('getUIFlags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isFetchingMetrics: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getUIFlags(state)).toEqual({
|
||||
isFetching: false,
|
||||
isFetchingMetrics: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { mutations } from '../../SLAReports';
|
||||
import appliedSlas from './fixtures';
|
||||
import types from '../../../mutation-types';
|
||||
|
||||
describe('#mutations', () => {
|
||||
describe('#SET_SLA_REPORTS', () => {
|
||||
it('Adds sla reports', () => {
|
||||
const state = { records: {} };
|
||||
mutations[types.SET_SLA_REPORTS](state, appliedSlas);
|
||||
expect(state.records).toEqual(appliedSlas);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_SLA_REPORTS_UI_FLAG', () => {
|
||||
it('set ui flags', () => {
|
||||
const state = { uiFlags: {} };
|
||||
mutations[types.SET_SLA_REPORTS_UI_FLAG](state, { isFetching: true });
|
||||
expect(state.uiFlags).toEqual({ isFetching: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_SLA_REPORTS_METRICS', () => {
|
||||
it('set metrics', () => {
|
||||
const state = { metrics: {} };
|
||||
mutations[types.SET_SLA_REPORTS_METRICS](state, {
|
||||
number_of_sla_breaches: 1,
|
||||
hit_rate: '100%',
|
||||
});
|
||||
expect(state.metrics).toEqual({
|
||||
numberOfSLABreaches: 1,
|
||||
hitRate: '100%',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_SLA_REPORTS_META', () => {
|
||||
it('set meta', () => {
|
||||
const state = { meta: {} };
|
||||
mutations[types.SET_SLA_REPORTS_META](state, {
|
||||
total_applied_slas: 1,
|
||||
current_page: 1,
|
||||
});
|
||||
expect(state.meta).toEqual({
|
||||
count: 1,
|
||||
currentPage: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user