|
| 1 | +import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendHideCreditCardOptionAction, sendHideCreditCardOptionActionAsync} from 'src'; |
| 2 | +import {pigi} from 'src/variables'; |
| 3 | +import * as sendPigiAction from 'src/pigi/sendPigiAction'; |
| 4 | + |
| 5 | +describe('testing send PIGI Hide Credit Card Action', () => { |
| 6 | + pigi.iFrameId = 'PIGI'; |
| 7 | + const calledOnce = 1; |
| 8 | + let sendPigiActionSpy: jest.SpyInstance; |
| 9 | + let sendPigiActionAsyncSpy: jest.SpyInstance; |
| 10 | + const expectedAction = { actionType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION }; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + jest.restoreAllMocks(); |
| 14 | + sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); |
| 15 | + sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); |
| 16 | + }); |
| 17 | + |
| 18 | + test('calling sendAddPaymentAction success', () => { |
| 19 | + const tempReturnObject = {...baseReturnObject}; |
| 20 | + tempReturnObject.success = true; |
| 21 | + sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); |
| 22 | + |
| 23 | + const res = sendHideCreditCardOptionAction(); |
| 24 | + |
| 25 | + expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); |
| 26 | + expect(sendPigiActionSpy).toHaveBeenCalledWith(expectedAction); |
| 27 | + expect(res).not.toBeNull(); |
| 28 | + expect(res).toStrictEqual(tempReturnObject); |
| 29 | + }); |
| 30 | + |
| 31 | + test('calling sendHideCreditCardOptionAction null Frame Window', () => { |
| 32 | + const tempReturnObject = {...baseReturnObject}; |
| 33 | + tempReturnObject.success = false; |
| 34 | + tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); |
| 35 | + sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); |
| 36 | + |
| 37 | + const res = sendHideCreditCardOptionAction(); |
| 38 | + |
| 39 | + expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); |
| 40 | + expect(res).not.toBeNull(); |
| 41 | + expect(res).toStrictEqual(tempReturnObject); |
| 42 | + }); |
| 43 | + |
| 44 | + test('calling sendAddPaymentActionAsync success', async () => { |
| 45 | + const tempReturnObject: IPigiResponseType = { |
| 46 | + responseType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION, |
| 47 | + payload: {success: true} |
| 48 | + }; |
| 49 | + sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); |
| 50 | + |
| 51 | + const res = await sendHideCreditCardOptionActionAsync(); |
| 52 | + |
| 53 | + expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); |
| 54 | + expect(sendPigiActionAsyncSpy).toHaveBeenCalledWith(expectedAction); |
| 55 | + expect(res).not.toBeNull(); |
| 56 | + expect(res).toStrictEqual(tempReturnObject); |
| 57 | + }); |
| 58 | +}); |
| 59 | + |
0 commit comments