2021-01-03 14:25:43 +05:30
|
|
|
import axios from 'axios';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { noop } from 'lodash';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { useFakeDate } from 'helpers/fake_date';
|
2021-03-11 19:13:27 +05:30
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2021-10-27 15:23:28 +05:30
|
|
|
import { members, group, modalData } from 'jest/members/mock_data';
|
2021-01-03 14:25:43 +05:30
|
|
|
import httpStatusCodes from '~/lib/utils/http_status';
|
|
|
|
import {
|
|
|
|
updateMemberRole,
|
|
|
|
showRemoveGroupLinkModal,
|
|
|
|
hideRemoveGroupLinkModal,
|
2021-10-27 15:23:28 +05:30
|
|
|
showRemoveMemberModal,
|
|
|
|
hideRemoveMemberModal,
|
2021-01-29 00:20:46 +05:30
|
|
|
updateMemberExpiration,
|
2021-02-22 17:27:13 +05:30
|
|
|
} from '~/members/store/actions';
|
2021-03-11 19:13:27 +05:30
|
|
|
import * as types from '~/members/store/mutation_types';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('Vuex members actions', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('update member actions', () => {
|
|
|
|
let mock;
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
const state = {
|
|
|
|
members,
|
|
|
|
memberPath: '/groups/foo-bar/-/group_members/:id',
|
|
|
|
requestFormatter: noop,
|
|
|
|
};
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
await testAction(updateMemberRole, payload, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_ROLE_SUCCESS,
|
2021-01-29 00:20:46 +05:30
|
|
|
payload,
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
]);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
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-03-11 19:13:27 +05:30
|
|
|
const error = new Error('Network Error');
|
|
|
|
mock.onPut().reply(() => Promise.reject(error));
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
await expect(
|
|
|
|
testAction(updateMemberRole, payload, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_ROLE_ERROR,
|
2021-03-11 19:13:27 +05:30
|
|
|
payload: { error },
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
]),
|
2021-03-11 19:13:27 +05:30
|
|
|
).rejects.toThrowError(error);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 },
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('unsuccessful request', () => {
|
|
|
|
it(`commits ${types.RECEIVE_MEMBER_EXPIRATION_ERROR} mutation and throws error`, async () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
const error = new Error('Network Error');
|
|
|
|
mock.onPut().reply(() => Promise.reject(error));
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
await expect(
|
|
|
|
testAction(updateMemberExpiration, { memberId, expiresAt }, state, [
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_MEMBER_EXPIRATION_ERROR,
|
2021-03-11 19:13:27 +05:30
|
|
|
payload: { error },
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
]),
|
2021-03-11 19:13:27 +05:30
|
|
|
).rejects.toThrowError(error);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|