Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 11:27:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 11:27:35 +0300
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /spec/frontend/vuex_shared
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/frontend/vuex_shared')
-rw-r--r--spec/frontend/vuex_shared/modules/members/actions_spec.js134
-rw-r--r--spec/frontend/vuex_shared/modules/members/mutations_spec.js67
2 files changed, 135 insertions, 66 deletions
diff --git a/spec/frontend/vuex_shared/modules/members/actions_spec.js b/spec/frontend/vuex_shared/modules/members/actions_spec.js
index 833bd4cc175..c7048a9c421 100644
--- a/spec/frontend/vuex_shared/modules/members/actions_spec.js
+++ b/spec/frontend/vuex_shared/modules/members/actions_spec.js
@@ -3,79 +3,121 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { members, group } from 'jest/vue_shared/components/members/mock_data';
import testAction from 'helpers/vuex_action_helper';
+import { useFakeDate } from 'helpers/fake_date';
import httpStatusCodes from '~/lib/utils/http_status';
import * as types from '~/vuex_shared/modules/members/mutation_types';
import {
updateMemberRole,
showRemoveGroupLinkModal,
hideRemoveGroupLinkModal,
+ updateMemberExpiration,
} from '~/vuex_shared/modules/members/actions';
describe('Vuex members actions', () => {
- let mock;
+ describe('update member actions', () => {
+ let mock;
- beforeEach(() => {
- mock = new MockAdapter(axios);
- });
-
- afterEach(() => {
- mock.restore();
- });
-
- describe('updateMemberRole', () => {
- const memberId = members[0].id;
- const accessLevel = { integerValue: 30, stringValue: 'Developer' };
-
- const payload = {
- memberId,
- accessLevel,
- };
const state = {
members,
memberPath: '/groups/foo-bar/-/group_members/:id',
requestFormatter: noop,
- removeGroupLinkModalVisible: false,
- groupLinkToRemove: null,
};
- describe('successful request', () => {
- it(`commits ${types.RECEIVE_MEMBER_ROLE_SUCCESS} mutation`, async () => {
- let requestPath;
- mock.onPut().replyOnce(config => {
- requestPath = config.url;
- return [httpStatusCodes.OK, {}];
- });
-
- await testAction(updateMemberRole, payload, state, [
- {
- type: types.RECEIVE_MEMBER_ROLE_SUCCESS,
- payload,
- },
- ]);
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
- expect(requestPath).toBe('/groups/foo-bar/-/group_members/238');
- });
+ afterEach(() => {
+ mock.restore();
});
- describe('unsuccessful request', () => {
- beforeEach(() => {
- mock.onPut().replyOnce(httpStatusCodes.BAD_REQUEST, { message: 'Bad request' });
- });
+ 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);
- it(`commits ${types.RECEIVE_MEMBER_ROLE_ERROR} mutation`, async () => {
- try {
await testAction(updateMemberRole, payload, state, [
{
type: types.RECEIVE_MEMBER_ROLE_SUCCESS,
+ payload,
},
]);
- } catch {
- // Do nothing
- }
+
+ 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 () => {
+ mock.onPut().networkError();
+
+ await expect(
+ testAction(updateMemberRole, payload, state, [
+ {
+ type: types.RECEIVE_MEMBER_ROLE_ERROR,
+ },
+ ]),
+ ).rejects.toThrowError(new Error('Network Error'));
+ });
+ });
+ });
+
+ 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 },
+ },
+ ]);
+ });
+ });
});
- it('throws error', async () => {
- await expect(testAction(updateMemberRole, payload, state)).rejects.toThrowError();
+ describe('unsuccessful request', () => {
+ it(`commits ${types.RECEIVE_MEMBER_EXPIRATION_ERROR} mutation and throws error`, async () => {
+ mock.onPut().networkError();
+
+ await expect(
+ testAction(updateMemberExpiration, { memberId, expiresAt }, state, [
+ {
+ type: types.RECEIVE_MEMBER_EXPIRATION_ERROR,
+ },
+ ]),
+ ).rejects.toThrowError(new Error('Network Error'));
+ });
});
});
});
diff --git a/spec/frontend/vuex_shared/modules/members/mutations_spec.js b/spec/frontend/vuex_shared/modules/members/mutations_spec.js
index 7338b19cfc9..710d43b8990 100644
--- a/spec/frontend/vuex_shared/modules/members/mutations_spec.js
+++ b/spec/frontend/vuex_shared/modules/members/mutations_spec.js
@@ -3,36 +3,63 @@ import mutations from '~/vuex_shared/modules/members/mutations';
import * as types from '~/vuex_shared/modules/members/mutation_types';
describe('Vuex members mutations', () => {
- describe(types.RECEIVE_MEMBER_ROLE_SUCCESS, () => {
- it('updates member', () => {
- const state = {
+ describe('update member mutations', () => {
+ let state;
+
+ beforeEach(() => {
+ state = {
members,
+ showError: false,
+ errorMessage: '',
};
+ });
- const accessLevel = { integerValue: 30, stringValue: 'Developer' };
+ describe(types.RECEIVE_MEMBER_ROLE_SUCCESS, () => {
+ it('updates member', () => {
+ const accessLevel = { integerValue: 30, stringValue: 'Developer' };
- mutations[types.RECEIVE_MEMBER_ROLE_SUCCESS](state, {
- memberId: members[0].id,
- accessLevel,
+ mutations[types.RECEIVE_MEMBER_ROLE_SUCCESS](state, {
+ memberId: members[0].id,
+ accessLevel,
+ });
+
+ expect(state.members[0].accessLevel).toEqual(accessLevel);
});
+ });
+
+ describe(types.RECEIVE_MEMBER_ROLE_ERROR, () => {
+ it('shows error message', () => {
+ mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state);
- expect(state.members[0].accessLevel).toEqual(accessLevel);
+ expect(state.showError).toBe(true);
+ expect(state.errorMessage).toBe(
+ "An error occurred while updating the member's role, please try again.",
+ );
+ });
});
- });
- describe(types.RECEIVE_MEMBER_ROLE_ERROR, () => {
- it('shows error message', () => {
- const state = {
- showError: false,
- errorMessage: '',
- };
+ describe(types.RECEIVE_MEMBER_EXPIRATION_SUCCESS, () => {
+ it('updates member', () => {
+ const expiresAt = '2020-03-17T00:00:00Z';
- mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state);
+ mutations[types.RECEIVE_MEMBER_EXPIRATION_SUCCESS](state, {
+ memberId: members[0].id,
+ expiresAt,
+ });
- expect(state.showError).toBe(true);
- expect(state.errorMessage).toBe(
- "An error occurred while updating the member's role, please try again.",
- );
+ expect(state.members[0].expiresAt).toEqual(expiresAt);
+ });
+ });
+
+ describe(types.RECEIVE_MEMBER_EXPIRATION_ERROR, () => {
+ it('shows error message', () => {
+ mutations[types.RECEIVE_MEMBER_EXPIRATION_ERROR](state);
+
+ expect(state.showError).toBe(true);
+ expect(state.errorMessage).toBe(
+ "An error occurred while updating the member's expiration date, please try again.",
+ );
+ });
});
});