Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing unit tests after merging v5 into v6 #2525

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let MySecuredField;

const myCSF = {
state: { type: 'card', hasSeparateDateFields: null, securedFields: {} as SecuredFields, iframeCount: 0, originalNumIframes: 2, numIframes: 2 },
config: { shouldDisableIOSArrowKeys: null },
props: { rootNode: null, i18n: new Language('en-US', {}) },
config: {},
props: { rootNode: null, i18n: new Language('en-US', {}), shouldDisableIOSArrowKeys: null },
callbacks: {
onLoad: jest.fn(() => {}),
onTouchstartIOS: jest.fn(() => {})
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('Testing CSFs setupSecuredField functionality', () => {
'Calling setupSecuredField to see that expected onTouchstartCallback is set. Running it sees that because myCSF is not configured to allow it ' +
'- the callback function and postMessageToAllIframes are not called',
() => {
myCSF.config.shouldDisableIOSArrowKeys = true;
myCSF.props.shouldDisableIOSArrowKeys = true;
myCSF.hasGenuineTouchEvents = false;

myCSF.setupSecuredField(makeDiv(ENCRYPTED_CARD_NUMBER));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import postMessageToIframe from '../utils/iframes/postMessageToIframe';
import { addEncryptedElements } from '../utils/encryptedElements';
import { handleEncryption } from './handleEncryption';

jest.mock('../utils/encryptedElements');
jest.mock('../utils/iframes/postMessageToIframe');

const mockedAddEncryptedElementMock = addEncryptedElements as jest.Mock;
const mockedPostMessageToIframe = postMessageToIframe as jest.Mock;

let fieldToFocus = null;
Expand Down Expand Up @@ -161,16 +158,11 @@ const expected_callbackObj_onFieldValid_PAN = {
};

describe('Testing CSFs handleEncryption functionality', () => {
const addEncryptedElementMock = jest.fn((obj, id) => console.log('### handleEncryption.test::Mock FN call to addEncryptedElement:: ', obj, id));
const postMessageToIframeMock = jest.fn(obj => console.log('### handleEncryption.test::Mock FN call to postMessageToIframe:: ', obj));

beforeEach(() => {
console.log = jest.fn(() => {});

mockedAddEncryptedElementMock.mockReset();
mockedAddEncryptedElementMock.mockImplementation((obj, id) => addEncryptedElementMock(obj, id));
addEncryptedElementMock.mockClear();

mockedPostMessageToIframe.mockReset();
mockedPostMessageToIframe.mockImplementation(obj => postMessageToIframeMock(obj));
postMessageToIframeMock.mockClear();
Expand All @@ -193,9 +185,6 @@ describe('Testing CSFs handleEncryption functionality', () => {

expect(myCSF.state.securedFields.encryptedSecurityCode.isEncrypted).toEqual(true);

// check for a call to addEncryptedElement
expect(addEncryptedElementMock).toHaveBeenCalled();

expect(myCSF.callbacks.onError).not.toHaveBeenCalled();

expect(myCSF.callbacks.onFieldValid).toHaveBeenCalled();
Expand All @@ -216,9 +205,6 @@ describe('Testing CSFs handleEncryption functionality', () => {

expect(myCSF.state.securedFields.encryptedExpiryDate.isEncrypted).toEqual(true);

// check call to addEncryptedElement not made
expect(addEncryptedElementMock).not.toHaveBeenCalled();

expect(myCSF.callbacks.onError).not.toHaveBeenCalled();

expect(myCSF.callbacks.onFieldValid).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { removeEncryptedElement } from '../utils/encryptedElements';
import { handleValidation } from './handleValidation';
import { SFFeedbackObj } from '../../types';

jest.mock('../utils/encryptedElements');

const mockedRemoveEncryptedElementMock = removeEncryptedElement as jest.Mock;

let callbackObj_error = null;
let callbackObj_fieldValid = null;

Expand Down Expand Up @@ -98,15 +93,9 @@ const expected_callbackObj_onFieldValid_PAN = {
};

describe('Testing CSFs handleValidation functionality', () => {
const removeEncryptedElementMock = jest.fn((obj, id) => console.log('### handleValidation.test::FN call:: ', obj, id));

beforeEach(() => {
console.log = jest.fn(() => {});

mockedRemoveEncryptedElementMock.mockReset();
mockedRemoveEncryptedElementMock.mockImplementation((obj, id) => removeEncryptedElementMock(obj, id));
removeEncryptedElementMock.mockClear();

myCSF.validateForm = jest.fn(() => {});

myCSF.callbacks.onError = jest.fn(obj => {
Expand Down Expand Up @@ -163,9 +152,6 @@ describe('Testing CSFs handleValidation functionality', () => {

expect(myCSF.validateForm).toHaveBeenCalledTimes(1);

// check for a call to removeEncryptedElement
expect(removeEncryptedElementMock).toHaveBeenCalled();

expect(myCSF.callbacks.onFieldValid).toHaveBeenCalled();
expect(callbackObj_fieldValid).toEqual(expected_callbackObj_onFieldValid);

Expand All @@ -187,9 +173,6 @@ describe('Testing CSFs handleValidation functionality', () => {

expect(myCSF.validateForm).toHaveBeenCalledTimes(1);

// check call to addEncryptedElement not made
expect(removeEncryptedElementMock).not.toHaveBeenCalled();

expect(myCSF.callbacks.onFieldValid).toHaveBeenCalled();
expect(callbackObj_fieldValid).toEqual(expected_callbackObj_onFieldValid_PAN);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ export interface CSFReturnObject {
/**
* Base interface for CSFSetupObject & CSFConfigObject
*
<<<<<<< HEAD
* These are the props that are passed from SFP when CSF is initialised and which end up as props in (CSF) this.config: CSFConfigObject
=======
* These are the props that are passed from SFP when CSF is initialised but which also end up
* as props in CSF--this.config: CSFConfigObject
>>>>>>> main
*/
interface CSFCommonProps {
autoFocus?: boolean | string;
Expand Down Expand Up @@ -61,11 +56,7 @@ export interface CSFConfigObject extends CSFCommonProps {
/**
* The object sent when SecuredFieldsProvider initialises CSF
*
<<<<<<< HEAD
* The properties defined here are ones that will *not* end up on (CSF) this.config
=======
* The properties defined here are ones that will not end up on CSF--this.config
>>>>>>> main
*/
export interface CSFSetupObject extends CSFCommonProps {
type: string;
Expand Down
31 changes: 15 additions & 16 deletions packages/playground/src/pages/Cards/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,21 @@ getPaymentMethods({ amount, shopperLocale }).then(async paymentMethodsResponse =
}

if (onlyShowCard || showComps.card) {
window.card = checkout
.create('card', {
challengeWindowSize: '01',
_disableClickToPay: true,
// hasHolderName: true,
// holderNameRequired: true,
// maskSecurityCode: true,
// enableStoreDetails: true
onError: obj => {
console.log('### Cards::onError:: obj=', obj);
},
onBinLookup: obj => {
console.log('### Cards::onBinLookup:: obj=', obj);
}
})
.mount('.card-field');
window.card = new Card({
core: checkout,
challengeWindowSize: '01',
_disableClickToPay: true,
// hasHolderName: true,
// holderNameRequired: true,
// maskSecurityCode: true,
// enableStoreDetails: true
onError: obj => {
console.log('### Cards::onError:: obj=', obj);
},
onBinLookup: obj => {
console.log('### Cards::onBinLookup:: obj=', obj);
}
}).mount('.card-field');
}

// Credit card with installments
Expand Down
Loading