2021-02-22 17:27:13 +05:30
|
|
|
import { members, group } from 'jest/members/mock_data';
|
|
|
|
import * as types from '~/members/store/mutation_types';
|
2021-03-11 19:13:27 +05:30
|
|
|
import mutations from '~/members/store/mutations';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('Vuex members mutations', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('update member mutations', () => {
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
2021-01-03 14:25:43 +05:30
|
|
|
members,
|
2021-01-29 00:20:46 +05:30
|
|
|
showError: false,
|
|
|
|
errorMessage: '',
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe(types.RECEIVE_MEMBER_ROLE_SUCCESS, () => {
|
|
|
|
it('updates member', () => {
|
|
|
|
const accessLevel = { integerValue: 30, stringValue: 'Developer' };
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
mutations[types.RECEIVE_MEMBER_ROLE_SUCCESS](state, {
|
|
|
|
memberId: members[0].id,
|
|
|
|
accessLevel,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.members[0].accessLevel).toEqual(accessLevel);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.RECEIVE_MEMBER_ROLE_ERROR, () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('when error does not have a message', () => {
|
|
|
|
it('shows default error message', () => {
|
|
|
|
mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state, {
|
|
|
|
error: new Error('Network Error'),
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.showError).toBe(true);
|
|
|
|
expect(state.errorMessage).toBe(
|
|
|
|
"An error occurred while updating the member's role, please try again.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when error has a message', () => {
|
|
|
|
it('shows error message', () => {
|
|
|
|
const error = new Error('Request failed with status code 422');
|
2021-08-04 16:29:09 +05:30
|
|
|
const message = 'User email does not match the allowed domain of example.com';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
error.response = {
|
|
|
|
data: { message },
|
|
|
|
};
|
|
|
|
mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state, { error });
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(state.showError).toBe(true);
|
|
|
|
expect(state.errorMessage).toBe(message);
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe(types.RECEIVE_MEMBER_EXPIRATION_SUCCESS, () => {
|
|
|
|
it('updates member', () => {
|
|
|
|
const expiresAt = '2020-03-17T00:00:00Z';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
mutations[types.RECEIVE_MEMBER_EXPIRATION_SUCCESS](state, {
|
|
|
|
memberId: members[0].id,
|
|
|
|
expiresAt,
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(state.members[0].expiresAt).toEqual(expiresAt);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.RECEIVE_MEMBER_EXPIRATION_ERROR, () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('when error does not have a message', () => {
|
|
|
|
it('shows default error message', () => {
|
|
|
|
mutations[types.RECEIVE_MEMBER_EXPIRATION_ERROR](state, {
|
|
|
|
error: new Error('Network Error'),
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.showError).toBe(true);
|
|
|
|
expect(state.errorMessage).toBe(
|
|
|
|
"An error occurred while updating the member's expiration date, please try again.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('when error has a message', () => {
|
|
|
|
it('shows error message', () => {
|
|
|
|
const error = new Error('Request failed with status code 422');
|
2021-08-04 16:29:09 +05:30
|
|
|
const message = 'User email does not match the allowed domain of example.com';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
error.response = {
|
|
|
|
data: { message },
|
|
|
|
};
|
|
|
|
mutations[types.RECEIVE_MEMBER_EXPIRATION_ERROR](state, { error });
|
|
|
|
|
|
|
|
expect(state.showError).toBe(true);
|
|
|
|
expect(state.errorMessage).toBe(message);
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.HIDE_ERROR, () => {
|
|
|
|
it('sets `showError` to `false`', () => {
|
|
|
|
const state = {
|
|
|
|
showError: true,
|
|
|
|
errorMessage: 'foo bar',
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.HIDE_ERROR](state);
|
|
|
|
|
|
|
|
expect(state.showError).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets `errorMessage` to an empty string', () => {
|
|
|
|
const state = {
|
|
|
|
showError: true,
|
|
|
|
errorMessage: 'foo bar',
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.HIDE_ERROR](state);
|
|
|
|
|
|
|
|
expect(state.errorMessage).toBe('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.SHOW_REMOVE_GROUP_LINK_MODAL, () => {
|
|
|
|
it('sets `removeGroupLinkModalVisible` and `groupLinkToRemove`', () => {
|
|
|
|
const state = {
|
|
|
|
removeGroupLinkModalVisible: false,
|
|
|
|
groupLinkToRemove: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.SHOW_REMOVE_GROUP_LINK_MODAL](state, group);
|
|
|
|
|
|
|
|
expect(state).toEqual({
|
|
|
|
removeGroupLinkModalVisible: true,
|
|
|
|
groupLinkToRemove: group,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.HIDE_REMOVE_GROUP_LINK_MODAL, () => {
|
|
|
|
it('sets `removeGroupLinkModalVisible` to `false`', () => {
|
|
|
|
const state = {
|
|
|
|
removeGroupLinkModalVisible: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations[types.HIDE_REMOVE_GROUP_LINK_MODAL](state);
|
|
|
|
|
|
|
|
expect(state.removeGroupLinkModalVisible).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|