mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
Feature: Slack - receive messages, create threads, send replies (#974)
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import axios from 'axios';
|
||||
import { actions } from '../../integrations';
|
||||
import * as types from '../../../mutation-types';
|
||||
import integrationsList 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: integrationsList });
|
||||
await actions.get({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isFetching: true }],
|
||||
[types.default.SET_INTEGRATIONS, integrationsList.payload],
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
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_INTEGRATIONS_UI_FLAG, { isFetching: true }],
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#connectSlack:', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
let data = { id: 'slack', enabled: true };
|
||||
axios.post.mockResolvedValue({ data: data });
|
||||
await actions.connectSlack({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: true }],
|
||||
[types.default.ADD_INTEGRATION, data],
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.connectSlack({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: true }],
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deleteIntegration:', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
let data = { id: 'slack', enabled: false };
|
||||
axios.delete.mockResolvedValue({ data: data });
|
||||
await actions.deleteIntegration({ commit }, data.id);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: true }],
|
||||
[types.default.DELETE_INTEGRATION, data],
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.deleteIntegration({ commit });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: true }],
|
||||
[types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
export default {
|
||||
payload: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'test1',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'test2',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
import { getters } from '../../integrations';
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getIntegrations', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'test1',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'test2',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(getters.getIntegrations(state)).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
name: 'test1',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'test2',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('getUIFlags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isUpdating: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getUIFlags(state)).toEqual({
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isUpdating: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import * as types from '../../../mutation-types';
|
||||
import { mutations } from '../../integrations';
|
||||
|
||||
describe('#mutations', () => {
|
||||
describe('#GET_INTEGRATIONS', () => {
|
||||
it('set integrations records', () => {
|
||||
const state = { records: [] };
|
||||
mutations[types.default.SET_INTEGRATIONS](state, [
|
||||
{
|
||||
id: 1,
|
||||
name: 'test1',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
expect(state.records).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
name: 'test1',
|
||||
logo: 'test',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user