2020-10-14 14:08:47 -04:00
|
|
|
import axios from 'axios';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { noop } from 'lodash';
|
2020-10-20 11:08:57 -04:00
|
|
|
import { useFakeDate } from 'helpers/fake_date';
|
2021-02-14 13:09:20 -05:00
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2021-07-22 08:10:04 -04:00
|
|
|
import { members, group, modalData } from 'jest/members/mock_data';
|
2020-10-14 14:08:47 -04:00
|
|
|
import httpStatusCodes from '~/lib/utils/http_status';
|
2020-10-16 11:08:46 -04:00
|
|
|
import {
|
|
|
|
updateMemberRole,
|
|
|
|
showRemoveGroupLinkModal,
|
|
|
|
hideRemoveGroupLinkModal,
|
2021-07-22 08:10:04 -04:00
|
|
|
showRemoveMemberModal,
|
|
|
|
hideRemoveMemberModal,
|
2020-10-20 11:08:57 -04:00
|
|
|
updateMemberExpiration,
|
2020-11-19 07:09:26 -05:00
|
|
|
} from '~/members/store/actions';
|
2021-02-14 13:09:20 -05:00
|
|
|
import * as types from '~/members/store/mutation_types';
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
describe('Vuex members actions', () => {
|
2020-10-20 11:08:57 -04:00
|
|
|
describe('update member actions', () => {
|
|
|
|
let mock;
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
members,
|
|
|
|
memberPath: '/groups/foo-bar/-/group_members/:id',
|
|
|
|
requestFormatter: noop,
|
|
|
|
};
|
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
describe('updateMemberRole', () => {
|
|
|
|
const memberId = members[0].id;
|
|
|
|
const accessLevel = { integerValue: 30, stringValue: 'Developer' };
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
memberId,
|
|
|
|
accessLevel,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('successful request', () => {
|
|
|
|
it(`commits ${types.RECEIVE_MEMBER_ROLE_SUCCESS} mutation`, async () => {
|
|
|
|
mock.onPut().replyOnce(httpStatusCodes.OK);
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
await testAction(updateMemberRole, payload, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_ROLE_SUCCESS,
|
2020-10-20 11:08:57 -04:00
|
|
|
payload,
|
2020-10-14 14:08:47 -04:00
|
|
|
},
|
|
|
|
]);
|
2020-10-20 11:08:57 -04:00
|
|
|
|
|
|
|
expect(mock.history.put[0].url).toBe('/groups/foo-bar/-/group_members/238');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unsuccessful request', () => {
|
|
|
|
it(`commits ${types.RECEIVE_MEMBER_ROLE_ERROR} mutation and throws error`, async () => {
|
2021-01-28 16:09:04 -05:00
|
|
|
const error = new Error('Network Error');
|
|
|
|
mock.onPut().reply(() => Promise.reject(error));
|
2020-10-20 11:08:57 -04:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
testAction(updateMemberRole, payload, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_ROLE_ERROR,
|
2021-01-28 16:09:04 -05:00
|
|
|
payload: { error },
|
2020-10-20 11:08:57 -04:00
|
|
|
},
|
|
|
|
]),
|
2021-01-28 16:09:04 -05:00
|
|
|
).rejects.toThrowError(error);
|
2020-10-20 11:08:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateMemberExpiration', () => {
|
|
|
|
useFakeDate(2020, 2, 15, 3);
|
|
|
|
|
|
|
|
const memberId = members[0].id;
|
|
|
|
const expiresAt = '2020-3-17';
|
|
|
|
|
|
|
|
describe('successful request', () => {
|
|
|
|
describe('changing expiration date', () => {
|
|
|
|
it(`commits ${types.RECEIVE_MEMBER_EXPIRATION_SUCCESS} mutation`, async () => {
|
|
|
|
mock.onPut().replyOnce(httpStatusCodes.OK);
|
|
|
|
|
|
|
|
await testAction(updateMemberExpiration, { memberId, expiresAt }, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_EXPIRATION_SUCCESS,
|
|
|
|
payload: { memberId, expiresAt: '2020-03-17T00:00:00Z' },
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(mock.history.put[0].url).toBe('/groups/foo-bar/-/group_members/238');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removing the expiration date', () => {
|
|
|
|
it(`commits ${types.RECEIVE_MEMBER_EXPIRATION_SUCCESS} mutation`, async () => {
|
|
|
|
mock.onPut().replyOnce(httpStatusCodes.OK);
|
|
|
|
|
|
|
|
await testAction(updateMemberExpiration, { memberId, expiresAt: null }, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_EXPIRATION_SUCCESS,
|
|
|
|
payload: { memberId, expiresAt: null },
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
|
|
|
|
2020-10-20 11:08:57 -04:00
|
|
|
describe('unsuccessful request', () => {
|
|
|
|
it(`commits ${types.RECEIVE_MEMBER_EXPIRATION_ERROR} mutation and throws error`, async () => {
|
2021-01-28 16:09:04 -05:00
|
|
|
const error = new Error('Network Error');
|
|
|
|
mock.onPut().reply(() => Promise.reject(error));
|
2020-10-20 11:08:57 -04:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
testAction(updateMemberExpiration, { memberId, expiresAt }, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_EXPIRATION_ERROR,
|
2021-01-28 16:09:04 -05:00
|
|
|
payload: { error },
|
2020-10-20 11:08:57 -04:00
|
|
|
},
|
|
|
|
]),
|
2021-01-28 16:09:04 -05:00
|
|
|
).rejects.toThrowError(error);
|
2020-10-20 11:08:57 -04:00
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-16 11:08:46 -04:00
|
|
|
|
|
|
|
describe('Group Link Modal', () => {
|
|
|
|
const state = {
|
|
|
|
removeGroupLinkModalVisible: false,
|
|
|
|
groupLinkToRemove: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('showRemoveGroupLinkModal', () => {
|
|
|
|
it(`commits ${types.SHOW_REMOVE_GROUP_LINK_MODAL} mutation`, () => {
|
|
|
|
testAction(showRemoveGroupLinkModal, group, state, [
|
|
|
|
{
|
|
|
|
type: types.SHOW_REMOVE_GROUP_LINK_MODAL,
|
|
|
|
payload: group,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hideRemoveGroupLinkModal', () => {
|
|
|
|
it(`commits ${types.HIDE_REMOVE_GROUP_LINK_MODAL} mutation`, () => {
|
|
|
|
testAction(hideRemoveGroupLinkModal, group, state, [
|
|
|
|
{
|
|
|
|
type: types.HIDE_REMOVE_GROUP_LINK_MODAL,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-07-22 08:10:04 -04:00
|
|
|
|
|
|
|
describe('Remove member modal', () => {
|
|
|
|
const state = {
|
|
|
|
removeMemberModalVisible: false,
|
|
|
|
removeMemberModalData: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('showRemoveMemberModal', () => {
|
|
|
|
it(`commits ${types.SHOW_REMOVE_MEMBER_MODAL} mutation`, () => {
|
|
|
|
testAction(showRemoveMemberModal, modalData, state, [
|
|
|
|
{
|
|
|
|
type: types.SHOW_REMOVE_MEMBER_MODAL,
|
|
|
|
payload: modalData,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hideRemoveMemberModal', () => {
|
|
|
|
it(`commits ${types.HIDE_REMOVE_MEMBER_MODAL} mutation`, () => {
|
|
|
|
testAction(hideRemoveMemberModal, undefined, state, [
|
|
|
|
{
|
|
|
|
type: types.HIDE_REMOVE_MEMBER_MODAL,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|