diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 00:09:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 00:09:04 +0300 |
commit | c6c346e8c7f0865f0016a458511e9fabfc8b9c1a (patch) | |
tree | 5b3a734e945e18c88817935c359c191140a11010 /spec/frontend/members | |
parent | e1b9b92a49eea88ea7c3b101aec0315e64e94678 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/members')
-rw-r--r-- | spec/frontend/members/components/app_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/members/store/actions_spec.js | 12 | ||||
-rw-r--r-- | spec/frontend/members/store/mutations_spec.js | 64 |
3 files changed, 61 insertions, 17 deletions
diff --git a/spec/frontend/members/components/app_spec.js b/spec/frontend/members/components/app_spec.js index 7b95e5ebd44..8fac0f5c5e6 100644 --- a/spec/frontend/members/components/app_spec.js +++ b/spec/frontend/members/components/app_spec.js @@ -48,7 +48,7 @@ describe('MembersApp', () => { it('renders and scrolls to error alert', async () => { createComponent({ showError: false, errorMessage: '' }); - store.commit(RECEIVE_MEMBER_ROLE_ERROR); + store.commit(RECEIVE_MEMBER_ROLE_ERROR, { error: new Error('Network Error') }); await nextTick(); diff --git a/spec/frontend/members/store/actions_spec.js b/spec/frontend/members/store/actions_spec.js index 5424fee0750..b0f863e6163 100644 --- a/spec/frontend/members/store/actions_spec.js +++ b/spec/frontend/members/store/actions_spec.js @@ -57,15 +57,17 @@ describe('Vuex members actions', () => { describe('unsuccessful request', () => { it(`commits ${types.RECEIVE_MEMBER_ROLE_ERROR} mutation and throws error`, async () => { - mock.onPut().networkError(); + const error = new Error('Network Error'); + mock.onPut().reply(() => Promise.reject(error)); await expect( testAction(updateMemberRole, payload, state, [ { type: types.RECEIVE_MEMBER_ROLE_ERROR, + payload: { error }, }, ]), - ).rejects.toThrowError(new Error('Network Error')); + ).rejects.toThrowError(error); }); }); }); @@ -108,15 +110,17 @@ describe('Vuex members actions', () => { describe('unsuccessful request', () => { it(`commits ${types.RECEIVE_MEMBER_EXPIRATION_ERROR} mutation and throws error`, async () => { - mock.onPut().networkError(); + const error = new Error('Network Error'); + mock.onPut().reply(() => Promise.reject(error)); await expect( testAction(updateMemberExpiration, { memberId, expiresAt }, state, [ { type: types.RECEIVE_MEMBER_EXPIRATION_ERROR, + payload: { error }, }, ]), - ).rejects.toThrowError(new Error('Network Error')); + ).rejects.toThrowError(error); }); }); }); diff --git a/spec/frontend/members/store/mutations_spec.js b/spec/frontend/members/store/mutations_spec.js index 488bfdf15fd..a56e6a72d9e 100644 --- a/spec/frontend/members/store/mutations_spec.js +++ b/spec/frontend/members/store/mutations_spec.js @@ -28,13 +28,33 @@ describe('Vuex members mutations', () => { }); describe(types.RECEIVE_MEMBER_ROLE_ERROR, () => { - it('shows error message', () => { - mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state); + 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'; - expect(state.showError).toBe(true); - expect(state.errorMessage).toBe( - "An error occurred while updating the member's role, please try again.", - ); + error.response = { + data: { message }, + }; + mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state, { error }); + + expect(state.showError).toBe(true); + expect(state.errorMessage).toBe(message); + }); }); }); @@ -52,13 +72,33 @@ describe('Vuex members mutations', () => { }); describe(types.RECEIVE_MEMBER_EXPIRATION_ERROR, () => { - it('shows error message', () => { - mutations[types.RECEIVE_MEMBER_EXPIRATION_ERROR](state); + 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'; - expect(state.showError).toBe(true); - expect(state.errorMessage).toBe( - "An error occurred while updating the member's expiration date, please try again.", - ); + error.response = { + data: { message }, + }; + mutations[types.RECEIVE_MEMBER_EXPIRATION_ERROR](state, { error }); + + expect(state.showError).toBe(true); + expect(state.errorMessage).toBe(message); + }); }); }); }); |