Commit 7b0bcbda authored by Paul Slaughter's avatar Paul Slaughter

Clean subscriptions new specs

**Notes:**
- localVue is only needed if we `use` something
- constants.*_URL don't exist anymore which
  was hurting our test coverage that the
  right calls were being made
- overwriting constants is a scary thing to do
  so added a mock for the constants to replace
  with a test STEPS array
parent 2b392239
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Component from 'ee/subscriptions/new/components/checkout/progress_bar.vue'; import Component from 'ee/subscriptions/new/components/checkout/progress_bar.vue';
describe('Progress Bar', () => { describe('Progress Bar', () => {
const localVue = createLocalVue();
let wrapper; let wrapper;
const createComponent = propsData => { const createComponent = propsData => {
wrapper = shallowMount(Component, { wrapper = shallowMount(Component, {
propsData, propsData,
localVue,
}); });
}; };
......
...@@ -4,14 +4,24 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -4,14 +4,24 @@ import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import * as actions from 'ee/subscriptions/new/store/actions'; import * as actions from 'ee/subscriptions/new/store/actions';
import * as constants from 'ee/subscriptions/new/constants'; import * as constants from 'ee/subscriptions/new/constants';
import Api from 'ee/api';
jest.mock('~/flash'); const {
countriesPath,
constants.STEPS = ['firstStep', 'secondStep']; countryStatesPath,
paymentFormPath,
paymentMethodPath,
confirmOrderPath,
} = Api;
let mock; jest.mock('~/flash');
jest.mock('ee/subscriptions/new/constants', () => ({
STEPS: ['firstStep', 'secondStep'],
}));
describe('Subscriptions Actions', () => { describe('Subscriptions Actions', () => {
let mock;
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -119,7 +129,7 @@ describe('Subscriptions Actions', () => { ...@@ -119,7 +129,7 @@ describe('Subscriptions Actions', () => {
describe('fetchCountries', () => { describe('fetchCountries', () => {
it('calls fetchCountriesSuccess with the returned data on success', done => { it('calls fetchCountriesSuccess with the returned data on success', done => {
mock.onGet(constants.COUNTRIES_URL).replyOnce(200, ['Netherlands', 'NL']); mock.onGet(countriesPath).replyOnce(200, ['Netherlands', 'NL']);
testAction( testAction(
actions.fetchCountries, actions.fetchCountries,
...@@ -132,7 +142,7 @@ describe('Subscriptions Actions', () => { ...@@ -132,7 +142,7 @@ describe('Subscriptions Actions', () => {
}); });
it('calls fetchCountriesError on error', done => { it('calls fetchCountriesError on error', done => {
mock.onGet(constants.COUNTRIES_URL).replyOnce(500); mock.onGet(countriesPath).replyOnce(500);
testAction(actions.fetchCountries, null, {}, [], [{ type: 'fetchCountriesError' }], done); testAction(actions.fetchCountries, null, {}, [], [{ type: 'fetchCountriesError' }], done);
}); });
...@@ -174,7 +184,7 @@ describe('Subscriptions Actions', () => { ...@@ -174,7 +184,7 @@ describe('Subscriptions Actions', () => {
describe('fetchStates', () => { describe('fetchStates', () => {
it('calls resetStates and fetchStatesSuccess with the returned data on success', done => { it('calls resetStates and fetchStatesSuccess with the returned data on success', done => {
mock mock
.onGet(constants.STATES_URL, { params: { country: 'NL' } }) .onGet(countryStatesPath, { params: { country: 'NL' } })
.replyOnce(200, { utrecht: 'UT' }); .replyOnce(200, { utrecht: 'UT' });
testAction( testAction(
...@@ -188,13 +198,13 @@ describe('Subscriptions Actions', () => { ...@@ -188,13 +198,13 @@ describe('Subscriptions Actions', () => {
}); });
it('only calls resetStates when no country selected', done => { it('only calls resetStates when no country selected', done => {
mock.onGet(constants.STATES_URL).replyOnce(500); mock.onGet(countryStatesPath).replyOnce(500);
testAction(actions.fetchStates, null, { country: null }, [], [{ type: 'resetStates' }], done); testAction(actions.fetchStates, null, { country: null }, [], [{ type: 'resetStates' }], done);
}); });
it('calls resetStates and fetchStatesError on error', done => { it('calls resetStates and fetchStatesError on error', done => {
mock.onGet(constants.STATES_URL).replyOnce(500); mock.onGet(countryStatesPath).replyOnce(500);
testAction( testAction(
actions.fetchStates, actions.fetchStates,
...@@ -350,7 +360,7 @@ describe('Subscriptions Actions', () => { ...@@ -350,7 +360,7 @@ describe('Subscriptions Actions', () => {
describe('fetchPaymentFormParams', () => { describe('fetchPaymentFormParams', () => {
it('fetches paymentFormParams and calls fetchPaymentFormParamsSuccess with the returned data on success', done => { it('fetches paymentFormParams and calls fetchPaymentFormParamsSuccess with the returned data on success', done => {
mock mock
.onGet(constants.PAYMENT_FORM_URL, { params: { id: constants.PAYMENT_FORM_ID } }) .onGet(paymentFormPath, { params: { id: constants.PAYMENT_FORM_ID } })
.replyOnce(200, { token: 'x' }); .replyOnce(200, { token: 'x' });
testAction( testAction(
...@@ -364,7 +374,7 @@ describe('Subscriptions Actions', () => { ...@@ -364,7 +374,7 @@ describe('Subscriptions Actions', () => {
}); });
it('calls fetchPaymentFormParamsError on error', done => { it('calls fetchPaymentFormParamsError on error', done => {
mock.onGet(constants.PAYMENT_FORM_URL).replyOnce(500); mock.onGet(paymentFormPath).replyOnce(500);
testAction( testAction(
actions.fetchPaymentFormParams, actions.fetchPaymentFormParams,
...@@ -492,7 +502,7 @@ describe('Subscriptions Actions', () => { ...@@ -492,7 +502,7 @@ describe('Subscriptions Actions', () => {
describe('fetchPaymentMethodDetails', () => { describe('fetchPaymentMethodDetails', () => {
it('fetches paymentMethodDetails and calls fetchPaymentMethodDetailsSuccess with the returned data on success and updates isLoadingPaymentMethod to false', done => { it('fetches paymentMethodDetails and calls fetchPaymentMethodDetailsSuccess with the returned data on success and updates isLoadingPaymentMethod to false', done => {
mock mock
.onGet(constants.PAYMENT_METHOD_URL, { params: { id: 'paymentMethodId' } }) .onGet(paymentMethodPath, { params: { id: 'paymentMethodId' } })
.replyOnce(200, { token: 'x' }); .replyOnce(200, { token: 'x' });
testAction( testAction(
...@@ -506,7 +516,7 @@ describe('Subscriptions Actions', () => { ...@@ -506,7 +516,7 @@ describe('Subscriptions Actions', () => {
}); });
it('calls fetchPaymentMethodDetailsError on error and updates isLoadingPaymentMethod to false', done => { it('calls fetchPaymentMethodDetailsError on error and updates isLoadingPaymentMethod to false', done => {
mock.onGet(constants.PAYMENT_METHOD_URL).replyOnce(500); mock.onGet(paymentMethodPath).replyOnce(500);
testAction( testAction(
actions.fetchPaymentMethodDetails, actions.fetchPaymentMethodDetails,
...@@ -559,16 +569,8 @@ describe('Subscriptions Actions', () => { ...@@ -559,16 +569,8 @@ describe('Subscriptions Actions', () => {
}); });
describe('confirmOrder', () => { describe('confirmOrder', () => {
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
it('calls confirmOrderSuccess with a redirect location on success', done => { it('calls confirmOrderSuccess with a redirect location on success', done => {
mock.onPost(constants.CONFIRM_ORDER_URL).replyOnce(200, { location: 'x' }); mock.onPost(confirmOrderPath).replyOnce(200, { location: 'x' });
testAction( testAction(
actions.confirmOrder, actions.confirmOrder,
...@@ -581,7 +583,7 @@ describe('Subscriptions Actions', () => { ...@@ -581,7 +583,7 @@ describe('Subscriptions Actions', () => {
}); });
it('calls confirmOrderError with the errors on error', done => { it('calls confirmOrderError with the errors on error', done => {
mock.onPost(constants.CONFIRM_ORDER_URL).replyOnce(200, { errors: 'errors' }); mock.onPost(confirmOrderPath).replyOnce(200, { errors: 'errors' });
testAction( testAction(
actions.confirmOrder, actions.confirmOrder,
...@@ -594,7 +596,7 @@ describe('Subscriptions Actions', () => { ...@@ -594,7 +596,7 @@ describe('Subscriptions Actions', () => {
}); });
it('calls confirmOrderError on failure', done => { it('calls confirmOrderError on failure', done => {
mock.onPost(constants.CONFIRM_ORDER_URL).replyOnce(500); mock.onPost(confirmOrderPath).replyOnce(500);
testAction( testAction(
actions.confirmOrder, actions.confirmOrder,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment