diff options
Diffstat (limited to 'spec/frontend/import_projects/store/actions_spec.js')
-rw-r--r-- | spec/frontend/import_projects/store/actions_spec.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/spec/frontend/import_projects/store/actions_spec.js b/spec/frontend/import_projects/store/actions_spec.js index 1f2882a2532..fd6fbcbfce0 100644 --- a/spec/frontend/import_projects/store/actions_spec.js +++ b/spec/frontend/import_projects/store/actions_spec.js @@ -1,4 +1,5 @@ import MockAdapter from 'axios-mock-adapter'; +import createFlash from '~/flash'; import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'helpers/test_constants'; import axios from '~/lib/utils/axios_utils'; @@ -22,6 +23,8 @@ import { } from '~/import_projects/store/actions'; import state from '~/import_projects/store/state'; +jest.mock('~/flash'); + describe('import_projects store actions', () => { let localState; const repos = [{ id: 1 }, { id: 2 }]; @@ -130,10 +133,28 @@ describe('import_projects store actions', () => { ); }); - it('commits REQUEST_IMPORT and RECEIVE_IMPORT_ERROR on an unsuccessful request', () => { + it('commits REQUEST_IMPORT and RECEIVE_IMPORT_ERROR and shows generic error message on an unsuccessful request', async () => { mock.onPost(`${TEST_HOST}/endpoint.json`).reply(500); - return testAction( + await testAction( + fetchImport, + importPayload, + localState, + [ + { type: REQUEST_IMPORT, payload: importPayload.repo.id }, + { type: RECEIVE_IMPORT_ERROR, payload: importPayload.repo.id }, + ], + [], + ); + + expect(createFlash).toHaveBeenCalledWith('Importing the project failed'); + }); + + it('commits REQUEST_IMPORT and RECEIVE_IMPORT_ERROR and shows detailed error message on an unsuccessful request with errors fields in response', async () => { + const ERROR_MESSAGE = 'dummy'; + mock.onPost(`${TEST_HOST}/endpoint.json`).reply(500, { errors: ERROR_MESSAGE }); + + await testAction( fetchImport, importPayload, localState, @@ -143,6 +164,8 @@ describe('import_projects store actions', () => { ], [], ); + + expect(createFlash).toHaveBeenCalledWith(`Importing the project failed: ${ERROR_MESSAGE}`); }); }); |