diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue index 878b54f7d5378d10cd5ab10b98e6f0c933e37740..c1584f3757efae2139d56fb248007a7e13777c6d 100644 --- a/app/assets/javascripts/diffs/components/app.vue +++ b/app/assets/javascripts/diffs/components/app.vue @@ -250,6 +250,7 @@ export default { if (this.glFeatures.diffsBatchLoad) { this.fetchDiffFilesMeta() .then(({ real_size }) => { + throw 'TODO! Please fix! We should not be receiving any data from an action.'; this.diffFilesLength = parseInt(real_size, 10); if (toggleTree) this.hideTreeListIfJustOneFile(); @@ -274,6 +275,7 @@ export default { } else { this.fetchDiffFiles() .then(({ real_size }) => { + throw 'TODO! Please fix! We should not be receiving any data from an action.'; this.diffFilesLength = parseInt(real_size, 10); if (toggleTree) { this.hideTreeListIfJustOneFile(); diff --git a/app/assets/javascripts/ide/stores/modules/clientside/actions.js b/app/assets/javascripts/ide/stores/modules/clientside/actions.js index eb3bcdff2ae275a3ea7fe8953614f1dda9e316d0..7beab5d2c6e27187bc54f88bb0346035784f3c96 100644 --- a/app/assets/javascripts/ide/stores/modules/clientside/actions.js +++ b/app/assets/javascripts/ide/stores/modules/clientside/actions.js @@ -5,7 +5,7 @@ export const pingUsage = ({ rootGetters }) => { const url = `${projectUrl}/usage_ping/web_ide_clientside_preview`; - return axios.post(url); + return axios.post(url).then(() => {}); }; // prevent babel-plugin-rewire from generating an invalid default during karma tests diff --git a/app/assets/javascripts/ide/stores/modules/file_templates/actions.js b/app/assets/javascripts/ide/stores/modules/file_templates/actions.js index 59ead8a3dcfdbf897137f89a302f78439f9d3103..cde3b6aec00e70591ae363721d50be2c766c13c9 100644 --- a/app/assets/javascripts/ide/stores/modules/file_templates/actions.js +++ b/app/assets/javascripts/ide/stores/modules/file_templates/actions.js @@ -43,7 +43,7 @@ export const fetchTemplateTypes = ({ dispatch, state, rootState }) => { }) .catch(() => dispatch('receiveTemplateTypesError')); - return fetchPages(); + return fetchPages().then(() => {}); }; export const setSelectedTemplateType = ({ commit, dispatch, rootGetters }, type) => { diff --git a/app/assets/javascripts/monitoring/components/dashboards_dropdown.vue b/app/assets/javascripts/monitoring/components/dashboards_dropdown.vue index 8f3e0a6ec750546f306bb7a08e1b2d567abbfbd4..0cc93df3e5d0d85850606ea1d4ebb75c954145bf 100644 --- a/app/assets/javascripts/monitoring/components/dashboards_dropdown.vue +++ b/app/assets/javascripts/monitoring/components/dashboards_dropdown.vue @@ -96,6 +96,8 @@ export default { const dashboard = this.form.branch === this.defaultBranch ? createdDashboard : this.selectedDashboard; this.$emit(events.selectDashboard, dashboard); + + throw 'TODO! Please fix! We should not be receiving any data from an action.'; }) .catch(error => { this.loading = false; diff --git a/app/assets/javascripts/monitoring/stores/actions.js b/app/assets/javascripts/monitoring/stores/actions.js index 29000475bd4bd15b8c3f138429b110c1d73ad911..2baa16a8c9d2c326ff2c4a50884f92cd9b9abfa1 100644 --- a/app/assets/javascripts/monitoring/stores/actions.js +++ b/app/assets/javascripts/monitoring/stores/actions.js @@ -239,8 +239,7 @@ export const duplicateSystemDashboard = ({ state }, payload) => { return axios .post(state.dashboardsEndpoint, params) - .then(response => response.data) - .then(data => data.dashboard) + .then(() => {}) .catch(error => { const { response } = error; if (response && response.data && response.data.error) { diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index f3dc6187c3fee684770294347e12ac7aa7d717b7..a62033ebc99404943ff998c06e7d585ca76a3409 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -253,6 +253,7 @@ export const saveNote = ({ commit, dispatch }, noteData) => { } const processQuickActions = res => { + throw 'TODO! We are using actions wrong if we are looking for a certain response from them... This is going to be a tough one to untangle though :/'; const { errors: { commands_only: message } = { commands_only: null } } = res; /* The following reply means that quick actions have been successfully applied: diff --git a/app/assets/javascripts/registry/list/stores/actions.js b/app/assets/javascripts/registry/list/stores/actions.js index 6afba6184863f975c000d5637fcf1c61453e4959..d8ea0cb9e17d0cdac5bef0e08316d710de299d09 100644 --- a/app/assets/javascripts/registry/list/stores/actions.js +++ b/app/assets/javascripts/registry/list/stores/actions.js @@ -34,9 +34,9 @@ export const fetchList = ({ commit }, { repo, page }) => { }); }; -export const deleteItem = (_, item) => axios.delete(item.destroyPath); +export const deleteItem = (_, item) => axios.delete(item.destroyPath).then(() => {}); export const multiDeleteItems = (_, { path, items }) => - axios.delete(path, { params: { ids: items } }); + axios.delete(path, { params: { ids: items } }).then(() => {}); export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data); export const setIsDeleteDisabled = ({ commit }, data) => commit(types.SET_IS_DELETE_DISABLED, data); diff --git a/ee/app/assets/javascripts/dependencies/store/actions.js b/ee/app/assets/javascripts/dependencies/store/actions.js index ded743bf0df317066292f36c8ff08c609e83fd9c..17be86e7fbc2a0085621b60f7f486168c1a1831f 100644 --- a/ee/app/assets/javascripts/dependencies/store/actions.js +++ b/ee/app/assets/javascripts/dependencies/store/actions.js @@ -7,12 +7,12 @@ export const setDependenciesEndpoint = ({ state, dispatch }, endpoint) => state.listTypes.map(({ namespace }) => dispatch(`${namespace}/setDependenciesEndpoint`, endpoint), ), - ); + ).then(() => {}); export const fetchDependencies = ({ state, dispatch }, payload) => Promise.all( state.listTypes.map(({ namespace }) => dispatch(`${namespace}/fetchDependencies`, payload)), - ); + ).then(() => {}); export const setCurrentList = ({ state, commit }, payload) => { if (state.listTypes.map(({ namespace }) => namespace).includes(payload)) { diff --git a/spec/frontend/helpers/vuex_action_helper.js b/spec/frontend/helpers/vuex_action_helper.js index 6c3569a2247d5207e9fae314433b075d0f21bc77..ee6e70f6ccbbbfd4d404967ecb763d920503a460 100644 --- a/spec/frontend/helpers/vuex_action_helper.js +++ b/spec/frontend/helpers/vuex_action_helper.js @@ -71,9 +71,13 @@ export default ( } actions.push(dispatchedAction); + + return Promise.resolve(); }; - const validateResults = () => { + const validateResults = returnValue => { + expect(returnValue).toBeUndefined(); + expect({ mutations, actions, @@ -95,7 +99,6 @@ export default ( throw error; }) .then(data => { - validateResults(); - return data; + validateResults(data); }); }; diff --git a/spec/frontend/helpers/vuex_action_helper_spec.js b/spec/frontend/helpers/vuex_action_helper_spec.js index 61d05762a04526fe33db0366bd67c0c0f14b318f..c7269acbf8f358999c2e2e2da4c81b144cb76e0a 100644 --- a/spec/frontend/helpers/vuex_action_helper_spec.js +++ b/spec/frontend/helpers/vuex_action_helper_spec.js @@ -4,30 +4,15 @@ import axios from '~/lib/utils/axios_utils'; import testAction from './vuex_action_helper'; describe('VueX test helper (testAction)', () => { - let originalExpect; - let assertion; let mock; const noop = () => {}; beforeEach(() => { mock = new MockAdapter(axios); - /** - * In order to test the helper properly, we need to overwrite the Jest - * `expect` helper. We test that the testAction helper properly passes the - * dispatched actions/committed mutations to the Jest helper. - */ - originalExpect = expect; - assertion = null; - global.expect = actual => ({ - toEqual: () => { - originalExpect(actual).toEqual(assertion); - }, - }); }); afterEach(() => { mock.restore(); - global.expect = originalExpect; }); it('properly passes state and payload to action', () => { @@ -35,13 +20,11 @@ describe('VueX test helper (testAction)', () => { const examplePayload = { BAZ: 73, BIZ: 55 }; const action = ({ state }, payload) => { - originalExpect(state).toEqual(exampleState); - originalExpect(payload).toEqual(examplePayload); + expect(state).toEqual(exampleState); + expect(payload).toEqual(examplePayload); }; - assertion = { mutations: [], actions: [] }; - - testAction(action, examplePayload, exampleState); + return testAction(action, examplePayload, exampleState); }); describe('given a sync action', () => { @@ -50,7 +33,7 @@ describe('VueX test helper (testAction)', () => { commit('MUTATION'); }; - assertion = { mutations: [{ type: 'MUTATION' }], actions: [] }; + const assertion = { mutations: [{ type: 'MUTATION' }], actions: [] }; testAction(action, null, {}, assertion.mutations, assertion.actions, noop); }); @@ -60,19 +43,19 @@ describe('VueX test helper (testAction)', () => { dispatch('ACTION'); }; - assertion = { actions: [{ type: 'ACTION' }], mutations: [] }; + const assertion = { actions: [{ type: 'ACTION' }], mutations: [] }; testAction(action, null, {}, assertion.mutations, assertion.actions, noop); }); it('works with done callback once finished', done => { - assertion = { mutations: [], actions: [] }; + const assertion = { mutations: [], actions: [] }; testAction(noop, null, {}, assertion.mutations, assertion.actions, done); }); it('returns a promise', done => { - assertion = { mutations: [], actions: [] }; + const assertion = { mutations: [], actions: [] }; testAction(noop, null, {}, assertion.mutations, assertion.actions) .then(done) @@ -82,7 +65,6 @@ describe('VueX test helper (testAction)', () => { describe('given an async action (returning a promise)', () => { let lastError; - const data = { FOO: 'BAR' }; const asyncAction = ({ commit, dispatch }) => { dispatch('ACTION'); @@ -96,7 +78,6 @@ describe('VueX test helper (testAction)', () => { }) .then(() => { commit('SUCCESS'); - return data; }); }; @@ -107,33 +88,32 @@ describe('VueX test helper (testAction)', () => { it('works with done callback once finished', done => { mock.onGet(TEST_HOST).replyOnce(200, 42); - assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; + const assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; testAction(asyncAction, null, {}, assertion.mutations, assertion.actions, done); }); - it('returns original data of successful promise while checking actions/mutations', done => { + it('fails spec if action returns data', () => { mock.onGet(TEST_HOST).replyOnce(200, 42); - assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; + const badAction = () => Promise.resolve('something'); - testAction(asyncAction, null, {}, assertion.mutations, assertion.actions) - .then(res => { - originalExpect(res).toEqual(data); - done(); - }) - .catch(done.fail); + return expect(testAction(badAction, null, {})).rejects.toThrow( + expect.objectContaining({ + message: expect.stringContaining('toBeUndefined'), + }), + ); }); it('returns original error of rejected promise while checking actions/mutations', done => { mock.onGet(TEST_HOST).replyOnce(500, ''); - assertion = { mutations: [{ type: 'ERROR' }], actions: [{ type: 'ACTION' }] }; + const assertion = { mutations: [{ type: 'ERROR' }], actions: [{ type: 'ACTION' }] }; testAction(asyncAction, null, {}, assertion.mutations, assertion.actions) .then(done.fail) .catch(error => { - originalExpect(error).toBe(lastError); + expect(error).toBe(lastError); done(); }); }); @@ -159,7 +139,7 @@ describe('VueX test helper (testAction)', () => { mock.onGet(TEST_HOST).replyOnce(200, 42); - assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; + const assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; testAction(asyncAction, null, {}, assertion.mutations, assertion.actions, done); }); diff --git a/spec/javascripts/helpers/vuex_action_helper.js b/spec/javascripts/helpers/vuex_action_helper.js index c5de31a413809ffd643d6c0cfaa8d9be83b85ad6..3911382a7a3705bf6401f56293b770f9bd64ee17 100644 --- a/spec/javascripts/helpers/vuex_action_helper.js +++ b/spec/javascripts/helpers/vuex_action_helper.js @@ -1,102 +1 @@ -const noop = () => {}; - -/** - * Helper for testing action with expected mutations inspired in - * https://vuex.vuejs.org/en/testing.html - * - * @param {Function} action to be tested - * @param {Object} payload will be provided to the action - * @param {Object} state will be provided to the action - * @param {Array} [expectedMutations=[]] mutations expected to be committed - * @param {Array} [expectedActions=[]] actions expected to be dispatched - * @param {Function} [done=noop] to be executed after the tests - * @return {Promise} - * - * @example - * testAction( - * actions.actionName, // action - * { }, // mocked payload - * state, //state - * // expected mutations - * [ - * { type: types.MUTATION} - * { type: types.MUTATION_1, payload: jasmine.any(Number)} - * ], - * // expected actions - * [ - * { type: 'actionName', payload: {param: 'foobar'}}, - * { type: 'actionName1'} - * ] - * done, - * ); - * - * @example - * testAction( - * actions.actionName, // action - * { }, // mocked payload - * state, //state - * [ { type: types.MUTATION} ], // expected mutations - * [], // expected actions - * ).then(done) - * .catch(done.fail); - */ -export default ( - action, - payload, - state, - expectedMutations = [], - expectedActions = [], - done = noop, -) => { - const mutations = []; - const actions = []; - - // mock commit - const commit = (type, mutationPayload) => { - const mutation = { type }; - - if (typeof mutationPayload !== 'undefined') { - mutation.payload = mutationPayload; - } - - mutations.push(mutation); - }; - - // mock dispatch - const dispatch = (type, actionPayload) => { - const dispatchedAction = { type }; - - if (typeof actionPayload !== 'undefined') { - dispatchedAction.payload = actionPayload; - } - - actions.push(dispatchedAction); - }; - - const validateResults = () => { - expect({ - mutations, - actions, - }).toEqual({ - mutations: expectedMutations, - actions: expectedActions, - }); - done(); - }; - - const result = action( - { commit, state, dispatch, rootState: state, rootGetters: state, getters: state }, - payload, - ); - - return new Promise(setImmediate) - .then(() => result) - .catch(error => { - validateResults(); - throw error; - }) - .then(data => { - validateResults(); - return data; - }); -}; +export { default } from '../../frontend/helpers/vuex_action_helper'; diff --git a/spec/javascripts/helpers/vuex_action_helper_spec.js b/spec/javascripts/helpers/vuex_action_helper_spec.js deleted file mode 100644 index 09f0bd395c3548ddf8b85ec9e8049e3af04f0e9d..0000000000000000000000000000000000000000 --- a/spec/javascripts/helpers/vuex_action_helper_spec.js +++ /dev/null @@ -1,166 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { TEST_HOST } from 'spec/test_constants'; -import axios from '~/lib/utils/axios_utils'; -import testAction from './vuex_action_helper'; - -describe('VueX test helper (testAction)', () => { - let originalExpect; - let assertion; - let mock; - const noop = () => {}; - - beforeAll(() => { - mock = new MockAdapter(axios); - /* - In order to test the helper properly, we need to overwrite the jasmine `expect` helper. - We test that the testAction helper properly passes the dispatched actions/committed mutations - to the jasmine helper. - */ - originalExpect = expect; - assertion = null; - global.expect = actual => ({ - toEqual: () => { - originalExpect(actual).toEqual(assertion); - }, - }); - }); - - afterAll(() => { - mock.restore(); - global.expect = originalExpect; - }); - - it('should properly pass on state and payload', () => { - const exampleState = { FOO: 12, BAR: 3 }; - const examplePayload = { BAZ: 73, BIZ: 55 }; - - const action = ({ state }, payload) => { - originalExpect(state).toEqual(exampleState); - originalExpect(payload).toEqual(examplePayload); - }; - - assertion = { mutations: [], actions: [] }; - - testAction(action, examplePayload, exampleState); - }); - - describe('should work with synchronous actions', () => { - it('committing mutation', () => { - const action = ({ commit }) => { - commit('MUTATION'); - }; - - assertion = { mutations: [{ type: 'MUTATION' }], actions: [] }; - - testAction(action, null, {}, assertion.mutations, assertion.actions, noop); - }); - - it('dispatching action', () => { - const action = ({ dispatch }) => { - dispatch('ACTION'); - }; - - assertion = { actions: [{ type: 'ACTION' }], mutations: [] }; - - testAction(action, null, {}, assertion.mutations, assertion.actions, noop); - }); - - it('work with jasmine done once finished', done => { - assertion = { mutations: [], actions: [] }; - - testAction(noop, null, {}, assertion.mutations, assertion.actions, done); - }); - - it('provide promise interface', done => { - assertion = { mutations: [], actions: [] }; - - testAction(noop, null, {}, assertion.mutations, assertion.actions) - .then(done) - .catch(done.fail); - }); - }); - - describe('should work with promise based actions (fetch action)', () => { - let lastError; - const data = { FOO: 'BAR' }; - - const promiseAction = ({ commit, dispatch }) => { - dispatch('ACTION'); - - return axios - .get(TEST_HOST) - .catch(error => { - commit('ERROR'); - lastError = error; - throw error; - }) - .then(() => { - commit('SUCCESS'); - return data; - }); - }; - - beforeEach(() => { - lastError = null; - }); - - it('work with jasmine done once finished', done => { - mock.onGet(TEST_HOST).replyOnce(200, 42); - - assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; - - testAction(promiseAction, null, {}, assertion.mutations, assertion.actions, done); - }); - - it('return original data of successful promise while checking actions/mutations', done => { - mock.onGet(TEST_HOST).replyOnce(200, 42); - - assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; - - testAction(promiseAction, null, {}, assertion.mutations, assertion.actions) - .then(res => { - originalExpect(res).toEqual(data); - done(); - }) - .catch(done.fail); - }); - - it('return original error of rejected promise while checking actions/mutations', done => { - mock.onGet(TEST_HOST).replyOnce(500, ''); - - assertion = { mutations: [{ type: 'ERROR' }], actions: [{ type: 'ACTION' }] }; - - testAction(promiseAction, null, {}, assertion.mutations, assertion.actions) - .then(done.fail) - .catch(error => { - originalExpect(error).toBe(lastError); - done(); - }); - }); - }); - - it('should work with async actions not returning promises', done => { - const data = { FOO: 'BAR' }; - - const promiseAction = ({ commit, dispatch }) => { - dispatch('ACTION'); - - axios - .get(TEST_HOST) - .then(() => { - commit('SUCCESS'); - return data; - }) - .catch(error => { - commit('ERROR'); - throw error; - }); - }; - - mock.onGet(TEST_HOST).replyOnce(200, 42); - - assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; - - testAction(promiseAction, null, {}, assertion.mutations, assertion.actions, done); - }); -});