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

INTER-3509-Add hide-credit-card-payment-option action #23

Merged
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
1 change: 1 addition & 0 deletions src/pigi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './sendAddPaymentAction';
export * from './sendClearErrorMessageAction';
export * from './sendDisplayErrorMessageAction';
export * from './sendHandleScaAction';
export * from './sendHideCreditCardOptionAction';
export * from './sendRefreshOrderAction';
export * from './sendSelectPaymentMethodAction';
export * from './sendUpdateLanguageAction';
Expand Down
24 changes: 24 additions & 0 deletions src/pigi/sendHideCreditCardOptionAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction, sendPigiActionAsync} from 'src';

const action: IPigiActionType = { actionType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION };
/**
* ## sendHideCreditCardOptionAction
*
* This action is to be sent after PIGI has been loaded. It causes the credit card
* fields in PIGI to be hidden.
*/
export function sendHideCreditCardOptionAction(): IApiReturnObject {
return sendPigiAction(action);
}

/**
* ## sendHideCreditCardOptionActionAsync
*
* This action is to be sent after PIGI has been loaded. It causes the credit card
* fields in PIGI to be hidden.
*
* This method waits for a response back from PIGI before returning.
*/
export async function sendHideCreditCardOptionActionAsync(): Promise<IPigiResponseType> {
return await sendPigiActionAsync(action);
}
1 change: 1 addition & 0 deletions src/types/apiInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface IPigiActionTypes {
PIGI_PAYMENT_ADDED: string;
PIGI_DISPLAY_IN_FULL_PAGE: string;
PIGI_DISPLAY_IN_FULL_PAGE_DONE: string;
PIGI_HIDE_CREDIT_CARD_OPTION: string;
}

export interface IExternalPaymentGatewayToParentActionTypes {
Expand Down
1 change: 1 addition & 0 deletions src/variables/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const pigiActionTypes: IPigiActionTypes = {
PIGI_PAYMENT_ADDED: 'PIGI_PAYMENT_ADDED',
PIGI_DISPLAY_IN_FULL_PAGE: 'PIGI_DISPLAY_IN_FULL_PAGE',
PIGI_DISPLAY_IN_FULL_PAGE_DONE: 'PIGI_DISPLAY_IN_FULL_PAGE_DONE',
PIGI_HIDE_CREDIT_CARD_OPTION: 'PIGI_HIDE_CREDIT_CARD_OPTION',
};

export const externalPaymentGatewayToParentActionTypes: IExternalPaymentGatewayToParentActionTypes = {
Expand Down
59 changes: 59 additions & 0 deletions tests/pigi/sendHideCreditCardOptionAction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendHideCreditCardOptionAction, sendHideCreditCardOptionActionAsync} from 'src';
import {pigi} from 'src/variables';
import * as sendPigiAction from 'src/pigi/sendPigiAction';

describe('testing send PIGI Hide Credit Card Action', () => {
pigi.iFrameId = 'PIGI';
const calledOnce = 1;
let sendPigiActionSpy: jest.SpyInstance;
let sendPigiActionAsyncSpy: jest.SpyInstance;
const expectedAction = { actionType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION };

beforeEach(() => {
jest.restoreAllMocks();
sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction');
sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync');
});

test('calling sendAddPaymentAction success', () => {
const tempReturnObject = {...baseReturnObject};
tempReturnObject.success = true;
sendPigiActionSpy.mockReturnValueOnce(tempReturnObject);

const res = sendHideCreditCardOptionAction();

expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce);
expect(sendPigiActionSpy).toHaveBeenCalledWith(expectedAction);
expect(res).not.toBeNull();
expect(res).toStrictEqual(tempReturnObject);
});

test('calling sendHideCreditCardOptionAction null Frame Window', () => {
const tempReturnObject = {...baseReturnObject};
tempReturnObject.success = false;
tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message);
sendPigiActionSpy.mockReturnValueOnce(tempReturnObject);

const res = sendHideCreditCardOptionAction();

expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce);
expect(res).not.toBeNull();
expect(res).toStrictEqual(tempReturnObject);
});

test('calling sendAddPaymentActionAsync success', async () => {
const tempReturnObject: IPigiResponseType = {
responseType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION,
payload: {success: true}
};
sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject);

const res = await sendHideCreditCardOptionActionAsync();

expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce);
expect(sendPigiActionAsyncSpy).toHaveBeenCalledWith(expectedAction);
expect(res).not.toBeNull();
expect(res).toStrictEqual(tempReturnObject);
});
});

Loading