Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
test: Added Stripe payment form tests (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdrussell2015 authored Jan 31, 2023
1 parent 40c96bd commit 6d4fef2
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 88 deletions.
34 changes: 21 additions & 13 deletions src/payment/checkout/Checkout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import { submitPayment } from '../data/actions';
import '../__factories__/basket.factory';
import '../__factories__/userAccount.factory';
import { transformResults } from '../data/service';
import { getPerformanceProperties } from '../performanceEventing';

jest.mock('@edx/frontend-platform/analytics', () => ({
sendTrackEvent: jest.fn(),
}));

jest.useFakeTimers('modern');

configureI18n({
config: {
ENVIRONMENT: process.env.ENVIRONMENT,
Expand Down Expand Up @@ -106,19 +109,24 @@ describe('<Checkout />', () => {

// Apple Pay temporarily disabled per REV-927 - https://github.com/openedx/frontend-app-payment/pull/256

// TODO: Disabling for now update once we can swap between stripe and cybersource
// it('submits and tracks the payment form', () => {
// const formSubmitButton = wrapper.find('form button[type="submit"]').hostNodes();
// formSubmitButton.simulate('click');

// expect(sendTrackEvent).toHaveBeenCalledWith('edx.bi.ecommerce.basket.payment_selected', {
// type: 'click',
// category: 'checkout',
// paymentMethod: 'Credit Card',
// checkoutType: 'client_side',
// flexMicroformEnabled: true,
// });
// });
it('submits and tracks the payment form', () => {
expect(sendTrackEvent).toHaveBeenCalledWith('edx.bi.ecommerce.payment_mfe.payment_form_rendered', {
...getPerformanceProperties(),
paymentProcessor: 'Cybersource',
});
const formSubmitButton = wrapper.find('form button[type="submit"]').hostNodes();
formSubmitButton.simulate('click');

expect(sendTrackEvent).toHaveBeenCalledWith('edx.bi.ecommerce.basket.payment_selected', {
type: 'click',
category: 'checkout',
paymentMethod: 'Credit Card',
checkoutType: 'client_side',
flexMicroformEnabled: true,
stripeEnabled: false,

});
});

it('fires an action when handling a cybersource submission', () => {
const formData = { name: 'test' };
Expand Down
143 changes: 69 additions & 74 deletions src/payment/checkout/payment-form/CardHolderInformation.test.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/* eslint-disable react/jsx-no-constructed-context-values */
// import React from 'react';
// import { Provider } from 'react-redux';
// import { mount } from 'enzyme';
import React from 'react';
import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import {
// IntlProvider,
IntlProvider,
configure as configureI18n,
} from '@edx/frontend-platform/i18n';
// import { AppContext } from '@edx/frontend-platform/react';
// import { Factory } from 'rosie';
// import { createStore } from 'redux';
import { AppContext } from '@edx/frontend-platform/react';
import { Factory } from 'rosie';
import { createStore } from 'redux';

// import CardHolderInformation, { CardHolderInformationComponent } from './CardHolderInformation';
// import PaymentForm from './PaymentForm';
// import createRootReducer from '../../../data/reducers';
import CardHolderInformation, { CardHolderInformationComponent } from './CardHolderInformation';
import PaymentForm from './PaymentForm';
import createRootReducer from '../../../data/reducers';

import '../../__factories__/userAccount.factory';
// import { iteratee } from 'lodash';

jest.mock('@edx/frontend-platform/analytics', () => ({
sendTrackEvent: jest.fn(),
Expand Down Expand Up @@ -47,70 +46,66 @@ configureI18n({
},
});

it('is using stripe', () => {
expect(null).toEqual(null);
});
// TODO: Disabling for now update once we can swap between stripe and cybersource
// describe('<CardHolderInformation />', () => {
// let store;
describe('<CardHolderInformation />', () => {
let store;

// describe('handleSelectCountry', () => {
// it('updates state with selected country', () => {
// const authenticatedUser = Factory.build('userAccount');
describe('handleSelectCountry', () => {
it('updates state with selected country', () => {
const authenticatedUser = Factory.build('userAccount');

// store = createStore(createRootReducer(), {});
// const component = (
// <IntlProvider locale="en">
// <AppContext.Provider value={{ authenticatedUser }}>
// <Provider store={store}>
// <PaymentForm onSubmitPayment={() => {}} onSubmitButtonClick={() => {}}>
// <CardHolderInformation />
// </PaymentForm>
// </Provider>
// </AppContext.Provider>
// </IntlProvider>
// );
// const wrapper = mount(component);
// const cardHolderInformation = wrapper
// .find(CardHolderInformationComponent)
// .first()
// .instance();
// const eventMock = jest.fn();
store = createStore(createRootReducer(), {});
const component = (
<IntlProvider locale="en">
<AppContext.Provider value={{ authenticatedUser }}>
<Provider store={store}>
<PaymentForm onSubmitPayment={() => {}} onSubmitButtonClick={() => {}}>
<CardHolderInformation />
</PaymentForm>
</Provider>
</AppContext.Provider>
</IntlProvider>
);
const wrapper = mount(component);
const cardHolderInformation = wrapper
.find(CardHolderInformationComponent)
.first()
.instance();
const eventMock = jest.fn();

// cardHolderInformation.handleSelectCountry(eventMock, 'US');
cardHolderInformation.handleSelectCountry(eventMock, 'US');

// expect(cardHolderInformation.state).toEqual({ selectedCountry: 'US' });
// });
// });
// describe('purchasedForOrganization field', () => {
// it('renders for bulk purchase', () => {
// const wrapper = mount((
// <IntlProvider locale="en">
// <Provider store={store}>
// <PaymentForm
// isBulkOrder
// handleSubmit={() => {}}
// onSubmitPayment={() => {}}
// onSubmitButtonClick={() => {}}
// />
// </Provider>
// </IntlProvider>
// ));
// expect(wrapper.exists('#purchasedForOrganization')).toEqual(true);
// });
// it('does not render if not bulk purchase', () => {
// const wrapper = mount((
// <IntlProvider locale="en">
// <Provider store={store}>
// <PaymentForm
// handleSubmit={() => {}}
// onSubmitPayment={() => {}}
// onSubmitButtonClick={() => {}}
// />
// </Provider>
// </IntlProvider>
// ));
// expect(wrapper.exists('#purchasedForOrganization')).toEqual(false);
// });
// });
// });
expect(cardHolderInformation.state).toEqual({ selectedCountry: 'US' });
});
});
describe('purchasedForOrganization field', () => {
it('renders for bulk purchase', () => {
const wrapper = mount((
<IntlProvider locale="en">
<Provider store={store}>
<PaymentForm
isBulkOrder
handleSubmit={() => {}}
onSubmitPayment={() => {}}
onSubmitButtonClick={() => {}}
/>
</Provider>
</IntlProvider>
));
expect(wrapper.exists('#purchasedForOrganization')).toEqual(true);
});
it('does not render if not bulk purchase', () => {
const wrapper = mount((
<IntlProvider locale="en">
<Provider store={store}>
<PaymentForm
handleSubmit={() => {}}
onSubmitPayment={() => {}}
onSubmitButtonClick={() => {}}
/>
</Provider>
</IntlProvider>
));
expect(wrapper.exists('#purchasedForOrganization')).toEqual(false);
});
});
});
2 changes: 1 addition & 1 deletion src/payment/checkout/payment-form/PaymentForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('<PaymentForm />', () => {
lastName: '',
address: '',
city: '',
country: 'UK',
country: 'GB',
cardExpirationMonth: '',
cardExpirationYear: '',
optionalField: '',
Expand Down
Loading

0 comments on commit 6d4fef2

Please sign in to comment.