Refactor: Inbox store, remove inboxes from sidebar (#387)
* Refactor: Inbox store, remove inboxes from sidebar * Add a new page for inbox settings * Show inboxes on sidebar * Add inbox_members API * Disable similar-code check * Fix codeclimate scss issues * Add widget_color update API and actions * Add specs for inbox store * Fix Facebook auth flow * Fix agent loading, inbox name
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import axios from 'axios';
|
||||
import { actions } from '../../inboxes';
|
||||
import * as types from '../../../mutation-types';
|
||||
import inboxList from './fixtures';
|
||||
|
||||
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: inboxList } });
|
||||
await actions.get({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isFetching: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isFetching: false }],
|
||||
[types.default.SET_INBOXES, inboxList],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.get({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isFetching: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createWebsiteChannel', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.post.mockResolvedValue({ data: inboxList[0] });
|
||||
await actions.createWebsiteChannel({ commit }, inboxList[0]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: true }],
|
||||
[types.default.ADD_INBOXES, inboxList[0]],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.createWebsiteChannel({ commit })).rejects.toThrow(
|
||||
Error
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createFBChannel', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.post.mockResolvedValue({ data: inboxList[0] });
|
||||
await actions.createFBChannel({ commit }, inboxList[0]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: true }],
|
||||
[types.default.ADD_INBOXES, inboxList[0]],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.createFBChannel({ commit })).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateWebsiteChannel', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.patch.mockResolvedValue({ data: inboxList[0] });
|
||||
await actions.updateWebsiteChannel({ commit }, inboxList[0]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: true }],
|
||||
[types.default.EDIT_INBOXES, inboxList[0]],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.updateWebsiteChannel({ commit }, inboxList[0])
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.delete.mockResolvedValue({ data: inboxList[0] });
|
||||
await actions.delete({ commit }, inboxList[0].id);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isDeleting: true }],
|
||||
[types.default.DELETE_INBOXES, inboxList[0].id],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.delete({ commit }, inboxList[0].id)).rejects.toThrow(
|
||||
Error
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isDeleting: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
export default [
|
||||
{
|
||||
id: 1,
|
||||
channel_id: 1,
|
||||
name: 'Test FacebookPage 1',
|
||||
channel_type: 'Channel::FacebookPage',
|
||||
avatar_url: 'random_image.png',
|
||||
page_id: '12345',
|
||||
widget_color: null,
|
||||
website_token: null,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
channel_id: 2,
|
||||
name: 'Test Widget 1',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
avatar_url: null,
|
||||
page_id: null,
|
||||
widget_color: '#7B64FF',
|
||||
website_token: 'randomid123',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
channel_id: 3,
|
||||
name: 'Test Widget 2',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
avatar_url: null,
|
||||
page_id: null,
|
||||
widget_color: '#68BC00',
|
||||
website_token: 'randomid124',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
channel_id: 4,
|
||||
name: 'Test Widget 3',
|
||||
channel_type: 'Channel::WebWidget',
|
||||
avatar_url: null,
|
||||
page_id: null,
|
||||
widget_color: '#68BC00',
|
||||
website_token: 'randomid125',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,46 @@
|
||||
import { getters } from '../../inboxes';
|
||||
import inboxList from './fixtures';
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getInboxes', () => {
|
||||
const state = {
|
||||
records: inboxList,
|
||||
};
|
||||
expect(getters.getInboxes(state)).toEqual(inboxList);
|
||||
});
|
||||
|
||||
it('getInbox', () => {
|
||||
const state = {
|
||||
records: inboxList,
|
||||
};
|
||||
expect(getters.getInbox(state)(1)).toEqual({
|
||||
id: 1,
|
||||
channel_id: 1,
|
||||
name: 'Test FacebookPage 1',
|
||||
channel_type: 'Channel::FacebookPage',
|
||||
avatar_url: 'random_image.png',
|
||||
page_id: '12345',
|
||||
widget_color: null,
|
||||
website_token: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('getUIFlags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getUIFlags(state)).toEqual({
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import * as types from '../../../mutation-types';
|
||||
import { mutations } from '../../inboxes';
|
||||
import inboxList from './fixtures';
|
||||
|
||||
describe('#mutations', () => {
|
||||
describe('#SET_INBOXES', () => {
|
||||
it('set inbox records', () => {
|
||||
const state = { records: [] };
|
||||
mutations[types.default.SET_INBOXES](state, inboxList);
|
||||
expect(state.records).toEqual(inboxList);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_INBOXES_ITEM', () => {
|
||||
it('push inbox if inbox doesnot exist to the store', () => {
|
||||
const state = {
|
||||
records: [],
|
||||
};
|
||||
mutations[types.default.SET_INBOXES_ITEM](state, inboxList[0]);
|
||||
expect(state.records).toEqual([inboxList[0]]);
|
||||
});
|
||||
|
||||
it('update inbox if it exists to the store', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
channel_id: 1,
|
||||
name: 'Test FacebookPage',
|
||||
channel_type: 'Channel::FacebookPage',
|
||||
avatar_url: 'random_image1.png',
|
||||
page_id: '1235',
|
||||
widget_color: null,
|
||||
website_token: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
mutations[types.default.SET_INBOXES_ITEM](state, inboxList[0]);
|
||||
expect(state.records).toEqual([inboxList[0]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_INBOXES', () => {
|
||||
it('push new record in the inbox store', () => {
|
||||
const state = {
|
||||
records: [],
|
||||
};
|
||||
mutations[types.default.ADD_INBOXES](state, inboxList[0]);
|
||||
expect(state.records).toEqual([inboxList[0]]);
|
||||
});
|
||||
});
|
||||
describe('#EDIT_INBOXES', () => {
|
||||
it('update inbox in the store', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
channel_id: 1,
|
||||
name: 'Test FacebookPage',
|
||||
channel_type: 'Channel::FacebookPage',
|
||||
avatar_url: 'random_image1.png',
|
||||
page_id: '1235',
|
||||
widget_color: null,
|
||||
website_token: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
mutations[types.default.EDIT_INBOXES](state, inboxList[0]);
|
||||
expect(state.records).toEqual([inboxList[0]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_INBOXES', () => {
|
||||
it('delete inbox from store', () => {
|
||||
const state = {
|
||||
records: [inboxList[0]],
|
||||
};
|
||||
mutations[types.default.DELETE_INBOXES](state, 1);
|
||||
expect(state.records).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_INBOXES', () => {
|
||||
it('delete inbox from store', () => {
|
||||
const state = {
|
||||
uiFlags: { isFetchingItem: false },
|
||||
};
|
||||
mutations[types.default.SET_INBOXES_UI_FLAG](state, {
|
||||
isFetchingItem: true,
|
||||
});
|
||||
expect(state.uiFlags).toEqual({ isFetchingItem: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user