2020-11-19 07:09:26 -05:00
|
|
|
import { members, group } from 'jest/members/mock_data';
|
|
|
|
import * as types from '~/members/store/mutation_types';
|
2021-02-14 13:09:20 -05:00
|
|
|
import mutations from '~/members/store/mutations';
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
describe('Vuex members mutations', () => {
|
2020-10-20 11:08:57 -04:00
|
|
|
describe('update member mutations', () => {
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
2020-10-14 14:08:47 -04:00
|
|
|
members,
|
2020-10-20 11:08:57 -04:00
|
|
|
showError: false,
|
|
|
|
errorMessage: '',
|
2020-10-14 14:08:47 -04:00
|
|
|
};
|
2020-10-20 11:08:57 -04:00
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
describe(types.RECEIVE_MEMBER_ROLE_SUCCESS, () => {
|
|
|
|
it('updates member', () => {
|
|
|
|
const accessLevel = { integerValue: 30, stringValue: 'Developer' };
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
mutations[types.RECEIVE_MEMBER_ROLE_SUCCESS](state, {
|
|
|
|
memberId: members[0].id,
|
|
|
|
accessLevel,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.members[0].accessLevel).toEqual(accessLevel);
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
2020-10-20 11:08:57 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.RECEIVE_MEMBER_ROLE_ERROR, () => {
|
2021-01-28 16:09:04 -05:00
|
|
|
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');
|
|
|
|
const message =
|
|
|
|
'User email "john.smith@gmail.com" does not match the allowed domain of example.com';
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2021-01-28 16:09:04 -05:00
|
|
|
error.response = {
|
|
|
|
data: { message },
|
|
|
|
};
|
|
|
|
mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state, { error });
|
|
|
|
|
|
|
|
expect(state.showError).toBe(true);
|
|
|
|
expect(state.errorMessage).toBe(message);
|
|
|
|
});
|
2020-10-20 11:08:57 -04:00
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
describe(types.RECEIVE_MEMBER_EXPIRATION_SUCCESS, () => {
|
|
|
|
it('updates member', () => {
|
|
|
|
const expiresAt = '2020-03-17T00:00:00Z';
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
mutations[types.RECEIVE_MEMBER_EXPIRATION_SUCCESS](state, {
|
|
|
|
memberId: members[0].id,
|
|
|
|
expiresAt,
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
expect(state.members[0].expiresAt).toEqual(expiresAt);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(types.RECEIVE_MEMBER_EXPIRATION_ERROR, () => {
|
2021-01-28 16:09:04 -05:00
|
|
|
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.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when error has a message', () => {
|
|
|
|
it('shows error message', () => {
|
|
|
|
const error = new Error('Request failed with status code 422');
|
|
|
|
const message =
|
|
|
|
'User email "john.smith@gmail.com" does not match the allowed domain of example.com';
|
2020-10-20 11:08:57 -04:00
|
|
|
|
2021-01-28 16:09:04 -05:00
|
|
|
error.response = {
|
|
|
|
data: { message },
|
|
|
|
};
|
|
|
|
mutations[types.RECEIVE_MEMBER_EXPIRATION_ERROR](state, { error });
|
|
|
|
|
|
|
|
expect(state.showError).toBe(true);
|
|
|
|
expect(state.errorMessage).toBe(message);
|
|
|
|
});
|
2020-10-20 11:08:57 -04:00
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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('');
|
|
|
|
});
|
|
|
|
});
|
2020-10-16 11:08:46 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|