From f28407e2ed550c0c73ef0cf4019d0f699989488a Mon Sep 17 00:00:00 2001 From: Jonathan Dart Date: Thu, 27 Mar 2025 10:16:26 -0500 Subject: [PATCH] CHK-8248: Remove pigi from frontend library --- README.md | 270 ------------------ docs/interfaces/IApiErrors.md | 7 - docs/interfaces/IPigi.md | 13 - docs/interfaces/IPigiActionType.md | 20 -- docs/interfaces/IPigiActionTypes.md | 97 ------- docs/interfaces/IPigiResponseType.md | 20 -- docs/modules.md | 4 - src/index.ts | 3 - src/paymentIframe/cssStylingPaymentIframe.ts | 22 -- src/paymentIframe/getPaymentIframe.ts | 15 - src/paymentIframe/index.ts | 2 - src/pigi/getPigiFrameWindow.ts | 14 - src/pigi/index.ts | 12 - src/pigi/sendAddPaymentAction.ts | 30 -- src/pigi/sendClearErrorMessageAction.ts | 22 -- src/pigi/sendDisplayErrorMessageAction.ts | 36 --- src/pigi/sendHandleScaAction.ts | 33 --- src/pigi/sendHideCreditCardOptionAction.ts | 24 -- src/pigi/sendPigiAction.ts | 53 ---- src/pigi/sendRefreshOrderAction.ts | 25 -- src/pigi/sendSelectPaymentMethodAction.ts | 34 --- src/pigi/sendUpdateLanguageAction.ts | 22 -- src/pigi/sendUpdateMediaMatchAction.ts | 40 --- src/pigi/setPigiListener.ts | 41 --- src/types/apiInterfaces.ts | 27 -- src/types/errorInterfaces.ts | 1 - src/types/variables.ts | 5 - src/variables/constants.ts | 28 -- src/variables/variables.ts | 5 - .../cssStylingPaymentIframe.test.ts | 68 ----- tests/paymentIframe/getPaymentIframe.test.ts | 38 --- tests/pigi/getPigiFrameWindow.test.ts | 53 ---- tests/pigi/sendAddPaymentAction.test.ts | 56 ---- .../pigi/sendClearErrorMessageAction.test.ts | 62 ---- .../sendDisplayErrorMessageAction.test.ts | 56 ---- tests/pigi/sendHandleScaAction.test.ts | 56 ---- .../sendHideCreditCardOptionAction.test.ts | 59 ---- tests/pigi/sendPigiAction.test.ts | 173 ----------- tests/pigi/sendRefreshOrderAction.test.ts | 54 ---- .../sendSelectPaymentMethodAction.test.tsx | 65 ----- tests/pigi/sendUpdateLanguageAction.test.ts | 56 ---- .../pigi/sendUpdateMediaMatchAction.test.tsx | 71 ----- tests/pigi/setPigiListener.test.ts | 101 ------- 43 files changed, 1893 deletions(-) delete mode 100644 docs/interfaces/IPigi.md delete mode 100644 docs/interfaces/IPigiActionType.md delete mode 100644 docs/interfaces/IPigiActionTypes.md delete mode 100644 docs/interfaces/IPigiResponseType.md delete mode 100644 src/paymentIframe/cssStylingPaymentIframe.ts delete mode 100644 src/paymentIframe/getPaymentIframe.ts delete mode 100644 src/paymentIframe/index.ts delete mode 100644 src/pigi/getPigiFrameWindow.ts delete mode 100644 src/pigi/index.ts delete mode 100644 src/pigi/sendAddPaymentAction.ts delete mode 100644 src/pigi/sendClearErrorMessageAction.ts delete mode 100644 src/pigi/sendDisplayErrorMessageAction.ts delete mode 100644 src/pigi/sendHandleScaAction.ts delete mode 100644 src/pigi/sendHideCreditCardOptionAction.ts delete mode 100644 src/pigi/sendPigiAction.ts delete mode 100644 src/pigi/sendRefreshOrderAction.ts delete mode 100644 src/pigi/sendSelectPaymentMethodAction.ts delete mode 100644 src/pigi/sendUpdateLanguageAction.ts delete mode 100644 src/pigi/sendUpdateMediaMatchAction.ts delete mode 100644 src/pigi/setPigiListener.ts delete mode 100644 tests/paymentIframe/cssStylingPaymentIframe.test.ts delete mode 100644 tests/paymentIframe/getPaymentIframe.test.ts delete mode 100644 tests/pigi/getPigiFrameWindow.test.ts delete mode 100644 tests/pigi/sendAddPaymentAction.test.ts delete mode 100644 tests/pigi/sendClearErrorMessageAction.test.ts delete mode 100644 tests/pigi/sendDisplayErrorMessageAction.test.ts delete mode 100644 tests/pigi/sendHandleScaAction.test.ts delete mode 100644 tests/pigi/sendHideCreditCardOptionAction.test.ts delete mode 100644 tests/pigi/sendPigiAction.test.ts delete mode 100644 tests/pigi/sendRefreshOrderAction.test.ts delete mode 100644 tests/pigi/sendSelectPaymentMethodAction.test.tsx delete mode 100644 tests/pigi/sendUpdateLanguageAction.test.ts delete mode 100644 tests/pigi/sendUpdateMediaMatchAction.test.tsx delete mode 100644 tests/pigi/setPigiListener.test.ts diff --git a/README.md b/README.md index f626989..461090e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ The Checkout Frontend Library is a Bold Javascript library, which contains reusa * Call Bold's [Headless Checkout APIs](https://developer.boldcommerce.com/default/guides/checkout) * Control request retry -* Communicate to the [PIGI API](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api) * Get useful types and constants to avoid defining interfaces ## Installation @@ -712,275 +711,6 @@ Removes a gift card payment by `id`. A promise that resolves the API response. -### Payment Iframe - ---- - -#### Get Payment Iframe - -▸ **getPaymentIframeUrl**(): Promise <[IApiReturnObject](./docs/interfaces/IApiReturnObject.md)> - -Retrieve the Payment Isolation Gateway Interface ([PIGI](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi)) url. - -```typescript - const response: IApiReturnObject = await getPaymentIframeUrl(); -``` - -**Returns** - -`Promise`<[IApiReturnObject](./docs/interfaces/IApiReturnObject.md)> - -A promise that resolves the API response. - ---- - -#### CSS Styling for PIGI - -▸ **cssStylingPaymentIframe**(`body`,`numOfRetries?`): Promise <[IApiReturnObject](./docs/interfaces/IApiReturnObject.md)> - -Styles the Payment Isolation Gateway Interface (PIGI) using CSS and media queries. - -```typescript - const response: IApiReturnObject = await cssStylingPaymentIframe(body, API_RETRY); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `body`| [ICssStylingPaymentIframeRequest](./docs/interfaces/ICssStylingPaymentIframeRequest.md)| The css and media rules that need to be applied to PIGI Iframe. | -| `numOfRetries?`| `number`| The number of times to retry the API in case of a 408, 429, 503, 504, or 544 error. The default is 0. | - -**Returns** - -`Promise`<[IApiReturnObject](./docs/interfaces/IApiReturnObject.md)> - -A promise that resolves the API response. - - -### PIGI Actions - ---- - -#### Set PIGI Listener - -▸ **setPigiListener**(`iFrameId`, `callback`): void - -Sets the callback function that will receive all action responses from PIGI. The callback function is executed when the parent receives any response from PIGI. You can also implement [PIGI event driven responses](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#event-driven-responses) in the callback function. -```typescript - -const handlePigiMessage = (e) => { - const {responseType, payload} = e.data as IPigiResponseData; - // Implement all action responses by responseType -} - -setPigiListener(IframeId, handlePigiMessage); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `iFrameId`| `string`| The unique identifier for the PIGI Iframe. | -| `callback`| `EventListenerOrEventListenerObject`| The callback function to call when PIGI responses are received. | - - ---- - -#### Add Payment Action - -▸ **sendAddPaymentAction**(): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendAddPaymentActionAsync**(): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Add payment PIGI action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#add-payment) requests that PIGI adds the payment token to the order after customer enters the payment information. - -```typescript - const response: IApiReturnObject = sendAddPaymentAction(); - const responseAsync: IPigiResponseType = await sendAddPaymentActionAsync(); -``` - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - -#### Clear PIGI Error Action - -▸ **sendClearErrorMessageAction**(): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendClearErrorMessageActionAsync**(): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Clear PIGI error action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#clear-error-messages) removes all errors from the PIGI user interface. - -```typescript - const response: IApiReturnObject = sendClearErrorMessageAction(); - const responseAsync: IPigiResponseType = await sendClearErrorMessageActionAsync(); -``` - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - -#### Display Error Message - -▸ **sendDisplayErrorMessageAction**(`message`, `subType`): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendDisplayErrorMessageActionAsync**(`message`, `subType`): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Display error message action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#display-error-message) displays an error message in the PIGI user interface. - -```typescript - const response: IApiReturnObject = sendDisplayErrorMessageAction(message, subType); - const responseAsync: IPigiResponseType = await sendDisplayErrorMessageActionAsync(message, subType); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `message`| `string`| The error message to display in PIGI. | -| `subType`| `string`| The type of error, corresponds to payment gateway name.| - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - -#### Handle SCA Action - -▸ **sendHandleScaAction**(`clientSecretToken?`): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendHandleScaActionAsync**(`clientSecretToken?`): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The Handle SCA action requests that PIGI handles SCA/3DS. - -```typescript - const response: IApiReturnObject = sendHandleScaAction(clientSecretToken); - const responseAsync: IApiReturnObject = await sendHandleScaAction(clientSecretToken); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `clientSecretToken?`| `string`| The secret token from payment gateway. | - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - -#### Refresh Order Action - -▸ **sendRefreshOrderAction**(): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendRefreshOrderActionAsync**(): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Refresh Order action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#refresh-order) updates the order state in PIGI. - -```typescript - const response: IApiReturnObject = sendRefreshOrderAction(); - const responseAsync: IPigiResponseType = await sendRefreshOrderActionAsync(); -``` - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - -#### Select Payment Action - -▸ **sendSelectPaymentMethodAction**(`payload`): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendSelectPaymentMethodActionAsync**(`payload`): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Select Payment Method action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#select-payment-method) selects the customer's choice of payment. - -```typescript - const response: IApiReturnObject = sendSelectPaymentMethodAction(payload); - const responseAsync: IPigiResponseType = await sendSelectPaymentMethodActionAsync(payload); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `payload`| `{index?: number, gatewayName?: string}`| Provide an object with either the `index` or `gatewayName`. If both are used, PIGI uses index. | - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - - -#### Update Language Action - -▸ **sendUpdateLanguageAction**(`languageCode`): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendUpdateLanguageActionAsync**(`languageCode`): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Update Language action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#update-language) changes the display language of PIGI. - -```typescript - const response: IApiReturnObject = sendUpdateLanguageAction(languageCode); - const responseAsync: IPigiResponseType = await sendUpdateLanguageActionAsync(languageCode); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `languageCode`| `string`| The updated language code in [ISO 639-1](https://www.iso.org/standard/22109.html). | - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - - -#### Update Media Match Action - -▸ **sendUpdateMediaMatchAction**(`conditionText`, `matches`): [IApiReturnObject](./docs/interfaces/IApiReturnObject.md)
-▸ **sendUpdateMediaMatchActionAsync**(`conditionText`, `matches`): Promise <[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -The [Update Media Match action](https://developer.boldcommerce.com/default/guides/checkout/checkout-pigi-api#update-media-match) changes the CSS styling of PIGI. - -```typescript - const response: IApiReturnObject = sendUpdateMediaMatchAction(conditionText, matches); - const responseAsync: IPigiResponseType = await sendUpdateMediaMatchActionAsync(conditionText, matches); -``` - -**Parameters** - -| Parameter| type| Description| -| ---------| ----|-----------| -| `conditionText`| `string`| The media rule condition. | -| `matches`| `boolean`| Whether or not the condition was met. | - -**Returns** - -[IApiReturnObject](./docs/interfaces/IApiReturnObject.md) | `Promise`<[IPigiResponseType](./docs/interfaces/IPigiResponseType.md)> - -An API response or promise that resolve the PIGI response. - ---- - ### State The Bold Checkout Frontend Library keeps a local copy of the most up-to-date application state, which is updated after every API call. Use the methods in this section to retrieve certain information about your order. To see the latest order status, you can also call the [Get Application State](#get-application-state) endpoint. diff --git a/docs/interfaces/IApiErrors.md b/docs/interfaces/IApiErrors.md index 2c80385..a1c7589 100644 --- a/docs/interfaces/IApiErrors.md +++ b/docs/interfaces/IApiErrors.md @@ -13,7 +13,6 @@ - [noAppState](IApiErrors.md#noappstate) - [noCsrf](IApiErrors.md#nocsrf) - [noFieldInResponse](IApiErrors.md#nofieldinresponse) -- [noPigiIframe](IApiErrors.md#nopigiiframe) - [noResData](IApiErrors.md#noresdata) ## Properties @@ -72,12 +71,6 @@ ___ ___ -### noPigiIframe - -• **noPigiIframe**: [`IErrorFormat`](IErrorFormat.md) - -___ - ### noResData • **noResData**: [`IErrorFormat`](IErrorFormat.md) diff --git a/docs/interfaces/IPigi.md b/docs/interfaces/IPigi.md deleted file mode 100644 index 057f9cb..0000000 --- a/docs/interfaces/IPigi.md +++ /dev/null @@ -1,13 +0,0 @@ -# Interface: IPigi - -## Table of contents - -### Properties - -- [iFrameId](IPigi.md#iframeid) - -## Properties - -### iFrameId - -• **iFrameId**: `string` diff --git a/docs/interfaces/IPigiActionType.md b/docs/interfaces/IPigiActionType.md deleted file mode 100644 index 2cea118..0000000 --- a/docs/interfaces/IPigiActionType.md +++ /dev/null @@ -1,20 +0,0 @@ -# Interface: IPigiActionType - -## Table of contents - -### Properties - -- [actionType](IPigiActionType.md#actiontype) -- [payload](IPigiActionType.md#payload) - -## Properties - -### actionType - -• **actionType**: `string` - -___ - -### payload - -• `Optional` **payload**: `Record`<`string`, `unknown`\> diff --git a/docs/interfaces/IPigiActionTypes.md b/docs/interfaces/IPigiActionTypes.md deleted file mode 100644 index eb31630..0000000 --- a/docs/interfaces/IPigiActionTypes.md +++ /dev/null @@ -1,97 +0,0 @@ -# Interface: IPigiActionTypes - -## Table of contents - -### Properties - -- [PIGI\_ADD\_PAYMENT](IPigiActionTypes.md#pigi_add_payment) -- [PIGI\_CLEAR\_ERROR\_MESSAGES](IPigiActionTypes.md#pigi_clear_error_messages) -- [PIGI\_DISPLAY\_ERROR\_MESSAGE](IPigiActionTypes.md#pigi_display_error_message) -- [PIGI\_DISPLAY\_IN\_FULL\_PAGE](IPigiActionTypes.md#pigi_display_in_full_page) -- [PIGI\_DISPLAY\_IN\_FULL\_PAGE\_DONE](IPigiActionTypes.md#pigi_display_in_full_page_done) -- [PIGI\_HANDLE\_SCA](IPigiActionTypes.md#pigi_handle_sca) -- [PIGI\_INITIALIZED](IPigiActionTypes.md#pigi_initialized) -- [PIGI\_PAYMENT\_ADDED](IPigiActionTypes.md#pigi_payment_added) -- [PIGI\_REFRESH\_ORDER](IPigiActionTypes.md#pigi_refresh_order) -- [PIGI\_SELECT\_PAYMENT\_METHOD](IPigiActionTypes.md#pigi_select_payment_method) -- [PIGI\_UPDATE\_HEIGHT](IPigiActionTypes.md#pigi_update_height) -- [PIGI\_UPDATE\_LANGUAGE](IPigiActionTypes.md#pigi_update_language) -- [PIGI\_UPDATE\_MEDIA\_MATCH](IPigiActionTypes.md#pigi_update_media_match) - -## Properties - -### PIGI\_ADD\_PAYMENT - -• **PIGI\_ADD\_PAYMENT**: `string` - -___ - -### PIGI\_CLEAR\_ERROR\_MESSAGES - -• **PIGI\_CLEAR\_ERROR\_MESSAGES**: `string` - -___ - -### PIGI\_DISPLAY\_ERROR\_MESSAGE - -• **PIGI\_DISPLAY\_ERROR\_MESSAGE**: `string` - -___ - -### PIGI\_DISPLAY\_IN\_FULL\_PAGE - -• **PIGI\_DISPLAY\_IN\_FULL\_PAGE**: `string` - -___ - -### PIGI\_DISPLAY\_IN\_FULL\_PAGE\_DONE - -• **PIGI\_DISPLAY\_IN\_FULL\_PAGE\_DONE**: `string` - -___ - -### PIGI\_HANDLE\_SCA - -• **PIGI\_HANDLE\_SCA**: `string` - -___ - -### PIGI\_INITIALIZED - -• **PIGI\_INITIALIZED**: `string` - -___ - -### PIGI\_PAYMENT\_ADDED - -• **PIGI\_PAYMENT\_ADDED**: `string` - -___ - -### PIGI\_REFRESH\_ORDER - -• **PIGI\_REFRESH\_ORDER**: `string` - -___ - -### PIGI\_SELECT\_PAYMENT\_METHOD - -• **PIGI\_SELECT\_PAYMENT\_METHOD**: `string` - -___ - -### PIGI\_UPDATE\_HEIGHT - -• **PIGI\_UPDATE\_HEIGHT**: `string` - -___ - -### PIGI\_UPDATE\_LANGUAGE - -• **PIGI\_UPDATE\_LANGUAGE**: `string` - -___ - -### PIGI\_UPDATE\_MEDIA\_MATCH - -• **PIGI\_UPDATE\_MEDIA\_MATCH**: `string` diff --git a/docs/interfaces/IPigiResponseType.md b/docs/interfaces/IPigiResponseType.md deleted file mode 100644 index 9a37f27..0000000 --- a/docs/interfaces/IPigiResponseType.md +++ /dev/null @@ -1,20 +0,0 @@ -# Interface: IPigiResponseType - -## Table of contents - -### Properties - -- [payload](IPigiResponseType.md#payload) -- [responseType](IPigiResponseType.md#responsetype) - -## Properties - -### payload - -• **payload**: `Record`<`string`, `unknown`\> - -___ - -### responseType - -• **responseType**: `string` diff --git a/docs/modules.md b/docs/modules.md index 06afa93..f1aa997 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -76,10 +76,6 @@ - [IPatchOrderMetaDataResponse](interfaces/IPatchOrderMetaDataResponse.md) - [IPayment](interfaces/IPayment.md) - [IPaymentFrame](interfaces/IPaymentFrame.md) -- [IPigi](interfaces/IPigi.md) -- [IPigiActionType](interfaces/IPigiActionType.md) -- [IPigiActionTypes](interfaces/IPigiActionTypes.md) -- [IPigiResponseType](interfaces/IPigiResponseType.md) - [IProductData](interfaces/IProductData.md) - [IProvince](interfaces/IProvince.md) - [ISessionStartApiResponse](interfaces/ISessionStartApiResponse.md) diff --git a/src/index.ts b/src/index.ts index aa2d7db..661f098 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ export { environmentPath, generalApiResponseParsingErrorType, methods, - pigiActionTypes, externalPaymentGatewayToParentActionTypes, externalPaymentGatewayToIframeActionTypes, apiTypes, @@ -31,7 +30,6 @@ export * from './taxes'; export * from './discounts'; export * from './payment'; export * from './orderMetaData'; -export * from './paymentIframe'; export * from './order'; export * from './externalPaymentGateway'; export * from './walletPay'; @@ -51,5 +49,4 @@ export { getOrderInitialData, getCurrency } from './state'; -export * from './pigi'; export * from './log'; diff --git a/src/paymentIframe/cssStylingPaymentIframe.ts b/src/paymentIframe/cssStylingPaymentIframe.ts deleted file mode 100644 index a052dca..0000000 --- a/src/paymentIframe/cssStylingPaymentIframe.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { - apiTypeKeys, - apiTypes, - checkApiResponse, - fetchAPI, - getApiOptions, - getApiUrl, - IApiReturnObject, ICssStylingPaymentIframeRequest -} from 'src'; - -/** - * cssStylingPaymentIframe - * - * Use this endpoint to style the Payment Isolation Gateway Interface (PIGI) using CSS and media queries. - */ -export async function cssStylingPaymentIframe(body: ICssStylingPaymentIframeRequest, numOfRetries = 0): Promise { - const {cssStylingPaymentIframe} = apiTypeKeys; - const options = getApiOptions(cssStylingPaymentIframe, body); - const url = getApiUrl(cssStylingPaymentIframe); - const fetchRes = await fetchAPI(url, options, numOfRetries); - return checkApiResponse(fetchRes, apiTypes[cssStylingPaymentIframe].keysToTest); -} diff --git a/src/paymentIframe/getPaymentIframe.ts b/src/paymentIframe/getPaymentIframe.ts deleted file mode 100644 index 4f0a2e3..0000000 --- a/src/paymentIframe/getPaymentIframe.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {apiTypeKeys, baseReturnObject, getApiUrlWithParams, getJwtToken, IApiReturnObject} from 'src'; - -/** - * - * Use this endpoint to retrieve the Payment Isolation Gateway Interface (PIGI) and load into an iframe. - * - */ -export async function getPaymentIframeUrl(): Promise { - const returnObject = {...baseReturnObject}; - const {getPaymentIframe} = apiTypeKeys; - const url = getApiUrlWithParams(getPaymentIframe, { token: getJwtToken()}); - returnObject.success = true; - returnObject.response = {data: {url}}; - return returnObject; -} diff --git a/src/paymentIframe/index.ts b/src/paymentIframe/index.ts deleted file mode 100644 index c4164cf..0000000 --- a/src/paymentIframe/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './getPaymentIframe'; -export * from './cssStylingPaymentIframe'; diff --git a/src/pigi/getPigiFrameWindow.ts b/src/pigi/getPigiFrameWindow.ts deleted file mode 100644 index 14b8575..0000000 --- a/src/pigi/getPigiFrameWindow.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {pigi} from 'src/variables'; - -/** - * ## getPigiFrameWindow - * Get the contentWindow of the PIGI iFrame - */ -export function getPigiFrameWindow(): WindowProxy | null { - const selector = `iframe#${pigi.iFrameId}`; - const iframeElement: HTMLIFrameElement | null = document.querySelector(selector); - if (iframeElement) { - return iframeElement.contentWindow || null; - } - return null; -} diff --git a/src/pigi/index.ts b/src/pigi/index.ts deleted file mode 100644 index 7a2919b..0000000 --- a/src/pigi/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -export * from './getPigiFrameWindow'; -export * from './sendPigiAction'; -export * from './sendAddPaymentAction'; -export * from './sendClearErrorMessageAction'; -export * from './sendDisplayErrorMessageAction'; -export * from './sendHandleScaAction'; -export * from './sendHideCreditCardOptionAction'; -export * from './sendRefreshOrderAction'; -export * from './sendSelectPaymentMethodAction'; -export * from './sendUpdateLanguageAction'; -export * from './sendUpdateMediaMatchAction'; -export * from './setPigiListener'; diff --git a/src/pigi/sendAddPaymentAction.ts b/src/pigi/sendAddPaymentAction.ts deleted file mode 100644 index d4ba674..0000000 --- a/src/pigi/sendAddPaymentAction.ts +++ /dev/null @@ -1,30 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction, sendPigiActionAsync} from 'src'; - -const action: IPigiActionType = { actionType: pigiActionTypes.PIGI_ADD_PAYMENT }; -/** - * ## sendAddPaymentAction - * - * This action is to be sent after the customer has entered payment information - * and the payment is to be added to the order so the order can be processed. - * - * This only tokenizes the payment information then puts it onto the order - * and does not authorize or capture the payment. - */ -export function sendAddPaymentAction(): IApiReturnObject { - return sendPigiAction(action); -} - -/** - * ## sendAddPaymentActionAsync - * - * This action is to be sent after the customer has entered payment information - * and the payment is to be added to the order so the order can be processed. - * - * This only tokenizes the payment information then puts it onto the order - * and does not authorize or capture the payment. - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendAddPaymentActionAsync(): Promise { - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendClearErrorMessageAction.ts b/src/pigi/sendClearErrorMessageAction.ts deleted file mode 100644 index fe68c04..0000000 --- a/src/pigi/sendClearErrorMessageAction.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction, sendPigiActionAsync} from 'src'; - -const action: IPigiActionType = { actionType: pigiActionTypes.PIGI_CLEAR_ERROR_MESSAGES }; -/** - * ## sendClearErrorMessageAction - * - * This action is to be sent when we need to clear the error message(s) displayed in PIGI - */ -export function sendClearErrorMessageAction(): IApiReturnObject { - return sendPigiAction(action); -} - -/** - * ## sendClearErrorMessageActionAsync - * - * This action is to be sent when we need to clear the error message(s) displayed in PIGI - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendClearErrorMessageActionAsync(): Promise { - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendDisplayErrorMessageAction.ts b/src/pigi/sendDisplayErrorMessageAction.ts deleted file mode 100644 index 04e53a5..0000000 --- a/src/pigi/sendDisplayErrorMessageAction.ts +++ /dev/null @@ -1,36 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction, sendPigiActionAsync} from 'src'; - -/** - * ## sendDisplayErrorMessageAction - * - * This action is to be sent if PIGI was displayed and we need to disdplay an error message. - */ -export function sendDisplayErrorMessageAction(message: string, subType: string): IApiReturnObject { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_DISPLAY_ERROR_MESSAGE, - payload: { - message: message, - sub_type: subType - } - }; - return sendPigiAction(action); -} - - -/** - * ## sendDisplayErrorMessageActionAsync - * - * This action is to be sent if PIGI was displayed and we need to display an error message. - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendDisplayErrorMessageActionAsync(message: string, subType: string): Promise { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_DISPLAY_ERROR_MESSAGE, - payload: { - message: message, - sub_type: subType - } - }; - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendHandleScaAction.ts b/src/pigi/sendHandleScaAction.ts deleted file mode 100644 index ff08625..0000000 --- a/src/pigi/sendHandleScaAction.ts +++ /dev/null @@ -1,33 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction, sendPigiActionAsync} from 'src'; - -/** - * ## sendHandleScaAction - * - * This action is to be sent to request Pigi to handle any SCA/3DS actions. - */ -export function sendHandleScaAction(clientSecretToken?: string): IApiReturnObject { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_HANDLE_SCA, - payload: { - clientSecretToken - } - }; - return sendPigiAction(action); -} - -/** - * ## sendHandleScaActionAsync - * - * This action is to be sent to request Pigi to handle any SCA/3DS actions. - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendHandleScaActionAsync(clientSecretToken?: string): Promise { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_HANDLE_SCA, - payload: { - clientSecretToken - } - }; - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendHideCreditCardOptionAction.ts b/src/pigi/sendHideCreditCardOptionAction.ts deleted file mode 100644 index 13a94f5..0000000 --- a/src/pigi/sendHideCreditCardOptionAction.ts +++ /dev/null @@ -1,24 +0,0 @@ -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 { - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendPigiAction.ts b/src/pigi/sendPigiAction.ts deleted file mode 100644 index 75095de..0000000 --- a/src/pigi/sendPigiAction.ts +++ /dev/null @@ -1,53 +0,0 @@ -import {apiErrors, baseReturnObject, getPigiFrameWindow, FetchError, IApiReturnObject, IPigiActionType, IPigiResponseType} from 'src'; - -/** - * ## sendAction - * - * This function sends a Action to the iFrame using postMessage - */ -export function sendPigiAction(action: IPigiActionType): IApiReturnObject { - const response = {...baseReturnObject}; - const iframeWindow = getPigiFrameWindow(); - if (iframeWindow){ - iframeWindow.postMessage(action, '*'); - response.success = true; - } else { - response.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - } - return response; -} - -/** - * ## sendActionAsync - * - * This function sends a Action to the iFrame using postMessage and waits for a response - */ -export function sendPigiActionAsync(action: IPigiActionType): Promise { - return new Promise((resolve, reject) => { - const iframeListener = (event: MessageEvent) => { - const pigiResponse = event.data; - if (pigiResponse && pigiResponse.responseType === action.actionType) { - if (pigiResponse.payload.success) { - window.removeEventListener('message', iframeListener); - resolve(pigiResponse); - } else { - window.removeEventListener('message', iframeListener); - reject(pigiResponse); - } - } - }; - - window.addEventListener('message', iframeListener); - const response = sendPigiAction(action); - if(!response.success){ - window.removeEventListener('message', iframeListener); - reject(response.error); - } - - //Timeout if haven't heard answer in 3 seconds - setTimeout(() => { - window.removeEventListener('message', iframeListener); - reject('Pigi response timeout'); - }, 10_000); - }); -} diff --git a/src/pigi/sendRefreshOrderAction.ts b/src/pigi/sendRefreshOrderAction.ts deleted file mode 100644 index 29f662c..0000000 --- a/src/pigi/sendRefreshOrderAction.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction} from 'src'; -import {sendPigiActionAsync} from '.'; - -const action: IPigiActionType = { actionType: pigiActionTypes.PIGI_REFRESH_ORDER }; -/** - * ## sendRefreshOrderAction - * - * This action is to be sent if PIGI was displayed and the order was updated. - * Payment gateways will require updated information about the customer or order to add the payment to the order. - */ -export function sendRefreshOrderAction(): IApiReturnObject { - return sendPigiAction(action); -} - -/** - * ## sendRefreshOrderActionAsync - * - * This action is to be sent if PIGI was displayed and the order was updated. - * Payment gateways will require updated information about the customer or order to add the payment to the order. - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendRefreshOrderActionAsync(): Promise { - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendSelectPaymentMethodAction.ts b/src/pigi/sendSelectPaymentMethodAction.ts deleted file mode 100644 index e1c7b65..0000000 --- a/src/pigi/sendSelectPaymentMethodAction.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - pigiActionTypes, - IApiReturnObject, - IPigiActionType, - IPigiResponseType, - sendPigiAction, - sendPigiActionAsync -} from 'src'; - -/** - * ## sendSelectPaymentMethodAction - * - * This action is to be sent to select a payment method - * @param payload Provide a object with either the index or gatewayName, if both are used, PIGI will use index. - */ -export function sendSelectPaymentMethodAction(payload: {index?: number, gatewayName?: string}): IApiReturnObject { - const action: IPigiActionType = {actionType: pigiActionTypes.PIGI_SELECT_PAYMENT_METHOD, payload}; - - return sendPigiAction(action); -} - -/** - * ## sendSelectPaymentMethodActionAsync - * - * This action is to be sent to select a payment method - * @param payload Provide a object with either the index or gatewayName, if both are used, PIGI will use index. - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendSelectPaymentMethodActionAsync(payload: {index?: number, gatewayName?: string}): Promise { - const action: IPigiActionType = {actionType: pigiActionTypes.PIGI_SELECT_PAYMENT_METHOD, payload}; - - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendUpdateLanguageAction.ts b/src/pigi/sendUpdateLanguageAction.ts deleted file mode 100644 index c88894e..0000000 --- a/src/pigi/sendUpdateLanguageAction.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction} from 'src'; -import {sendPigiActionAsync} from '.'; - -export function sendUpdateLanguageAction(languageCode: string): IApiReturnObject { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_UPDATE_LANGUAGE, - payload: { - language: languageCode - } - }; - return sendPigiAction(action); -} - -export async function sendUpdateLanguageActionAsync(languageCode: string): Promise { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_UPDATE_LANGUAGE, - payload: { - language: languageCode - } - }; - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/sendUpdateMediaMatchAction.ts b/src/pigi/sendUpdateMediaMatchAction.ts deleted file mode 100644 index 734f35b..0000000 --- a/src/pigi/sendUpdateMediaMatchAction.ts +++ /dev/null @@ -1,40 +0,0 @@ -import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction} from 'src'; -import {sendPigiActionAsync} from '.'; - -/** - * ## sendUpdateMediaMatchAction - * - * To update media rules in PIGI this action can be sent along with a payload containing - * the media condition and if it is a match. - * - * @param conditionText media rule condition. - * @param matches true or false if condition is met. - */ -export function sendUpdateMediaMatchAction(conditionText: string, matches: boolean): IApiReturnObject { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_UPDATE_MEDIA_MATCH, - payload: {conditionText, matches} - }; - - return sendPigiAction(action); -} - -/** - * ## sendUpdateMediaMatchActionAsync - * - * To update media rules in PIGI this action can be sent along with a payload containing - * the media condition and if it is a match. - * - * @param conditionText media rule condition. - * @param matches true or false if condition is met. - * - * This method waits for a response back from PIGI before returning. - */ -export async function sendUpdateMediaMatchActionAsync(conditionText: string, matches: boolean): Promise { - const action: IPigiActionType = { - actionType: pigiActionTypes.PIGI_UPDATE_MEDIA_MATCH, - payload: {conditionText, matches} - }; - - return await sendPigiActionAsync(action); -} diff --git a/src/pigi/setPigiListener.ts b/src/pigi/setPigiListener.ts deleted file mode 100644 index d75e633..0000000 --- a/src/pigi/setPigiListener.ts +++ /dev/null @@ -1,41 +0,0 @@ -import {pigiActionTypes} from 'src'; -import {pigi} from 'src/variables'; - -let pigiMessageListener: (this: Window, ev: MessageEvent) => void; - -/** - * ## setPigiListener - * Set the PIGI iFrame id to be used for the actions - * and the callback that will receive the responses from PIGI iFrame. - * - * @param iFrameId Provide the Pigi iFrame Id. - * @param callback Provide the callback function to call when PIGI responses are received. - * - * @returns The function used to subscribe to pigi messages, needed to unsubscribe from listener - */ -export function setPigiListener(iFrameId: string, callback: EventListenerOrEventListenerObject): void { - //unsubscribe from any orphan listeners before subscribing/resubscribing - window.removeEventListener('message', pigiMessageListener); - - pigi.iFrameId = iFrameId.replace('#', ''); - pigiMessageListener = (event: MessageEvent) => { - const {responseType} = event.data || {}; - if (responseType && responseType in pigiActionTypes) { - if(typeof callback === 'function') { - callback(event); - } else { - callback.handleEvent(event); - } - } - }; - window.addEventListener('message', pigiMessageListener); -} - -/** - * ## removePigiListener - * Remove the callback that receives the responses from PIGI iFrame. - * - */ -export function removePigiListener(): void{ - window.removeEventListener('message', pigiMessageListener); -} diff --git a/src/types/apiInterfaces.ts b/src/types/apiInterfaces.ts index 2188ccf..f3d2590 100644 --- a/src/types/apiInterfaces.ts +++ b/src/types/apiInterfaces.ts @@ -66,23 +66,6 @@ export interface IMethods { DELETE: string; } -export interface IPigiActionTypes { - PIGI_ADD_PAYMENT: string; - PIGI_REFRESH_ORDER: string; - PIGI_UPDATE_LANGUAGE: string; - PIGI_UPDATE_MEDIA_MATCH: string; - PIGI_DISPLAY_ERROR_MESSAGE: string; - PIGI_CLEAR_ERROR_MESSAGES: string; - PIGI_SELECT_PAYMENT_METHOD: string; - PIGI_INITIALIZED: string; - PIGI_UPDATE_HEIGHT: string; - PIGI_HANDLE_SCA: string; - 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 { EXTERNAL_PAYMENT_GATEWAY_ADD_PAYMENT: string; EXTERNAL_PAYMENT_GATEWAY_REFRESH_ORDER: string; @@ -916,21 +899,11 @@ export interface IShippingLine { code: string; } -export interface IPigiActionType { - actionType: string; - payload?: Record; -} - export interface IExternalPaymentGatewayActionType { type: string; payload?: IInitializeOrderResponse | IExternalPaymentGateway | IExternalPaymentGatewayLanguage | IAddress; } -export interface IPigiResponseType { - responseType: string; - payload: Record; -} - export interface IInventoryCheck { result: 'pass' | 'fail' | 'not_enabled'; reason?: string; diff --git a/src/types/errorInterfaces.ts b/src/types/errorInterfaces.ts index 0d381f5..e590542 100644 --- a/src/types/errorInterfaces.ts +++ b/src/types/errorInterfaces.ts @@ -30,7 +30,6 @@ export interface IApiErrors { emptyFieldInResponse: IErrorFormat; errorsInResponse: IErrorFormat; emptyKeysToCheck: IErrorFormat; - noPigiIframe: IErrorFormat; } export interface IGeneralApiResponseParsingErrorType { diff --git a/src/types/variables.ts b/src/types/variables.ts index 6d557a1..17b886c 100644 --- a/src/types/variables.ts +++ b/src/types/variables.ts @@ -10,8 +10,3 @@ export interface IAuth { csrfToken: string; jwtToken: string; } - -export interface IPigi { - iFrameId: string; -} - diff --git a/src/variables/constants.ts b/src/variables/constants.ts index 3228ac4..2cb0d8f 100644 --- a/src/variables/constants.ts +++ b/src/variables/constants.ts @@ -9,8 +9,6 @@ import { IHttpStatusCode, ICheckInventoryStage, IMethods, - IPigiActionTypes, - IPigiResponseType, IAlternatePaymentMethodType, IExternalPaymentGatewayToParentActionTypes, IExternalPaymentGatewayToIframeActionTypes @@ -53,23 +51,6 @@ export const methods: IMethods = { DELETE: 'DELETE' }; -export const pigiActionTypes: IPigiActionTypes = { - PIGI_ADD_PAYMENT: 'PIGI_ADD_PAYMENT', - PIGI_REFRESH_ORDER: 'PIGI_REFRESH_ORDER', - PIGI_UPDATE_LANGUAGE: 'PIGI_UPDATE_LANGUAGE', - PIGI_UPDATE_MEDIA_MATCH: 'PIGI_UPDATE_MEDIA_MATCH', - PIGI_DISPLAY_ERROR_MESSAGE: 'PIGI_DISPLAY_ERROR_MESSAGE', - PIGI_CLEAR_ERROR_MESSAGES: 'PIGI_CLEAR_ERROR_MESSAGES', - PIGI_SELECT_PAYMENT_METHOD: 'PIGI_SELECT_PAYMENT_METHOD', - PIGI_INITIALIZED: 'PIGI_INITIALIZED', - PIGI_UPDATE_HEIGHT: 'PIGI_UPDATE_HEIGHT', - PIGI_HANDLE_SCA: 'PIGI_HANDLE_SCA', - 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 = { EXTERNAL_PAYMENT_GATEWAY_ADD_PAYMENT: 'EXTERNAL_PAYMENT_GATEWAY_ADD_PAYMENT', EXTERNAL_PAYMENT_GATEWAY_REFRESH_ORDER: 'EXTERNAL_PAYMENT_GATEWAY_REFRESH_ORDER', @@ -383,7 +364,6 @@ export const baseReturnObject: IApiReturnObject = { export const apiErrors: IApiErrors = { general: {status: 1000, message: 'General error thrown'}, noCsrf: {status: 1001, message: 'CSRF Token not found'}, - noPigiIframe: {status: 1002, message: 'PIGI iframe not found or empty'}, /* * API RESPONSE - checkApiResponse function ERRORS * @@ -401,14 +381,6 @@ export const apiErrors: IApiErrors = { emptyResData: {status: 1201, message: 'Data is empty in response'}, }; -export const basePigiResponseType: IPigiResponseType = { - responseType: '', - payload: { - success: false, - height: 0 - } -}; - export const httpStatusCode: IHttpStatusCode = { OK: 200, ACCEPTED: 202, diff --git a/src/variables/variables.ts b/src/variables/variables.ts index 2870ac1..23bc608 100644 --- a/src/variables/variables.ts +++ b/src/variables/variables.ts @@ -12,7 +12,6 @@ import { ITax, IDiscount, IPayment, - IPigi, IOrderMetaData, IShipping, ICurrency, @@ -37,10 +36,6 @@ export const auth: IAuth = { jwtToken: '' }; -export const pigi: IPigi = { - iFrameId: '' -}; - export const customer: ICustomer = { platform_id: '', public_id: '', diff --git a/tests/paymentIframe/cssStylingPaymentIframe.test.ts b/tests/paymentIframe/cssStylingPaymentIframe.test.ts deleted file mode 100644 index 3860589..0000000 --- a/tests/paymentIframe/cssStylingPaymentIframe.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -import {apiTypeKeys, baseReturnObject, methods, cssStylingPaymentIframe} from 'src'; -import * as fetchAPI from 'src/utils/fetchAPI'; -import * as getApiOptions from 'src/utils/getApiOptions'; -import * as apiUrl from 'src/utils/apiUrl'; -import {cssStylingPaymentIframeRequestMock} from 'src/variables/mocks'; -import * as apiResponse from 'src/utils/apiResponse'; - -describe('testing CSS Styling Payment Iframe api', () => { - const returnObject = {...baseReturnObject}; - const timesWhenCalled = 1; - const apiUrlMock = 'https://api.com/checkout/storefront/123/123/payments/styles'; - let optionsMock: RequestInit; - let getApiOptionsSpy: jest.SpyInstance; - let getApiUrlSpy: jest.SpyInstance; - let fetchApiSpy: jest.SpyInstance; - let checkApiResponseSpy: jest.SpyInstance; - - beforeEach(() => { - global.Headers = jest.fn().mockReturnValue({append: jest.fn()}); - optionsMock = {method: methods.POST, headers: new Headers(), body: JSON.stringify({})}; - getApiOptionsSpy = jest.spyOn(getApiOptions, 'getApiOptions').mockReturnValue(optionsMock); - getApiUrlSpy = jest.spyOn(apiUrl, 'getApiUrl').mockReturnValue(apiUrlMock); - fetchApiSpy = jest.spyOn(fetchAPI, 'fetchAPI').mockReturnValue(Promise.resolve(returnObject)); - checkApiResponseSpy = jest.spyOn(apiResponse, 'checkApiResponse').mockReturnValue(returnObject); - returnObject.response = { - data: { - style_sheet: { - cssRules: cssStylingPaymentIframeRequestMock.css_rules, - mediaRules: cssStylingPaymentIframeRequestMock.media_rules - } - } - }; - returnObject.success = true; - }); - - afterEach(() => { - jest.restoreAllMocks(); - }); - - test('calling cssStylingPaymentIframe', async () => { - const res = await cssStylingPaymentIframe(cssStylingPaymentIframeRequestMock); - - expect(getApiOptionsSpy).toHaveBeenCalledTimes(timesWhenCalled); - expect(getApiUrlSpy).toHaveBeenCalledTimes(timesWhenCalled); - expect(fetchApiSpy).toHaveBeenCalledTimes(timesWhenCalled); - expect(getApiOptionsSpy).toHaveBeenCalledWith(apiTypeKeys.cssStylingPaymentIframe, cssStylingPaymentIframeRequestMock); - expect(getApiUrlSpy).toHaveBeenCalledWith(apiTypeKeys.cssStylingPaymentIframe); - expect(fetchApiSpy).toHaveBeenCalledWith(apiUrlMock, optionsMock, 0); - expect(res).toStrictEqual(returnObject); - }); - - test('calling cssStylingPaymentIframe w/ success = false', async () => { - const tempReturnObject = {...baseReturnObject}; - checkApiResponseSpy.mockReturnValueOnce(tempReturnObject); - fetchApiSpy.mockReturnValueOnce(Promise.resolve(tempReturnObject)); - - const res = await cssStylingPaymentIframe(cssStylingPaymentIframeRequestMock, 1); - - expect(getApiOptionsSpy).toHaveBeenCalledTimes(timesWhenCalled); - expect(getApiUrlSpy).toHaveBeenCalledTimes(timesWhenCalled); - expect(fetchApiSpy).toHaveBeenCalledTimes(timesWhenCalled); - expect(getApiOptionsSpy).toHaveBeenCalledWith(apiTypeKeys.cssStylingPaymentIframe, cssStylingPaymentIframeRequestMock); - expect(getApiUrlSpy).toHaveBeenCalledWith(apiTypeKeys.cssStylingPaymentIframe); - expect(fetchApiSpy).toHaveBeenCalledWith(apiUrlMock, optionsMock, 1); - expect(res).toStrictEqual(tempReturnObject); - }); -}); - diff --git a/tests/paymentIframe/getPaymentIframe.test.ts b/tests/paymentIframe/getPaymentIframe.test.ts deleted file mode 100644 index b52a86e..0000000 --- a/tests/paymentIframe/getPaymentIframe.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import {baseReturnObject, getPaymentIframeUrl} from 'src'; -import * as getShopIdentifier from 'src/auth/getShopIdentifier'; -import * as getPublicOrderId from 'src/auth/getPublicOrderId'; -import * as getEnvironment from 'src/environment/getEnvironment'; -import * as getJwtToken from 'src/auth/getJwtToken'; - -describe('testing getPaymentIframe - expected Url', () => { - const shopId = 'shopId'; - const jwtToken = 'jwtToken'; - const publicOrderId = 'publicOrderId'; - const env = { type: 'mockedEnvType', url: 'https://mockerenvurl.com', path: 'mockedEnvPath'}; - - beforeEach(() => { - const shopIdSpy = jest.spyOn(getShopIdentifier, 'getShopIdentifier'); - const publicOrderIdSpy = jest.spyOn(getPublicOrderId, 'getPublicOrderId'); - const jwtTokenSpy = jest.spyOn(getJwtToken, 'getJwtToken'); - const envSpy = jest.spyOn(getEnvironment, 'getEnvironment'); - - shopIdSpy.mockReturnValue(shopId); - jwtTokenSpy.mockReturnValue(jwtToken); - publicOrderIdSpy.mockReturnValue(publicOrderId); - envSpy.mockReturnValue(env); - }); - - test('successful call (200)', async () => { - const res = await getPaymentIframeUrl(); - expect(res.success).toBe(true); - }); - test('testing getPaymentIframe - validating URL', async () => { - const url = `${env.url}/${env.path}/storefront/${shopId}/${publicOrderId}/payments/iframe?token=${jwtToken}`; - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.response = {data: {url}}; - const res = await getPaymentIframeUrl(); - - expect(res.success).toBe(true); - expect(res.response).toStrictEqual(tempReturnObject.response); - }); -}); diff --git a/tests/pigi/getPigiFrameWindow.test.ts b/tests/pigi/getPigiFrameWindow.test.ts deleted file mode 100644 index 8a225a3..0000000 --- a/tests/pigi/getPigiFrameWindow.test.ts +++ /dev/null @@ -1,53 +0,0 @@ -import {getPigiFrameWindow} from 'src'; -import {pigi} from 'src/variables'; - -describe('testing get pigi frame window', () => { - pigi.iFrameId = 'PIGI'; - const selector = 'iframe#PIGI'; - const html_string = 'test'; - const src = 'data:text/html;charset=utf-8,' + escape(html_string); - const calledOnce = 1; - - beforeEach(() => { - jest.restoreAllMocks(); - }); - - test('calling getPigiFrameWindow success', () => { - const iFrame = document.createElement('iframe'); - iFrame.setAttribute('id', pigi.iFrameId); - iFrame.src = src; - document.body.appendChild(iFrame); - const querySelectorSpy = jest.spyOn(document, 'querySelector'); - - const res = getPigiFrameWindow(); - - expect(querySelectorSpy).toHaveBeenCalledTimes(calledOnce); - expect(querySelectorSpy).toHaveBeenCalledWith(selector); - expect(res).not.toBeNull(); - expect(res).toBe(iFrame.contentWindow); - }); - - test('calling getPigiFrameWindow No contentWindow', () => { - const iFrame = document.createElement('iframe'); - iFrame.setAttribute('id', pigi.iFrameId); - const querySelectorSpy = jest.spyOn(document, 'querySelector').mockReturnValueOnce(iFrame); - - const res = getPigiFrameWindow(); - - expect(querySelectorSpy).toHaveBeenCalledTimes(calledOnce); - expect(querySelectorSpy).toHaveBeenCalledWith(selector); - expect(res).toBeNull(); - expect(res).toBe(iFrame.contentWindow); - }); - - test('calling getPigiFrameWindow No iFrame', () => { - const querySelectorSpy = jest.spyOn(document, 'querySelector').mockReturnValueOnce(null); - - const res = getPigiFrameWindow(); - - expect(querySelectorSpy).toHaveBeenCalledTimes(calledOnce); - expect(querySelectorSpy).toHaveBeenCalledWith(selector); - expect(res).toBeNull(); - }); -}); - diff --git a/tests/pigi/sendAddPaymentAction.test.ts b/tests/pigi/sendAddPaymentAction.test.ts deleted file mode 100644 index 5877cab..0000000 --- a/tests/pigi/sendAddPaymentAction.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendAddPaymentAction, sendAddPaymentActionAsync} from 'src'; -import {pigi} from 'src/variables'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('testing send PIGI Add Payment Action', () => { - pigi.iFrameId = 'PIGI'; - const calledOnce = 1; - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - - 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 = sendAddPaymentAction(); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendAddPaymentAction null Frame Window', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = false; - tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendAddPaymentAction(); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendAddPaymentActionAsync success', async () => { - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_ADD_PAYMENT, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendAddPaymentActionAsync(); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); - diff --git a/tests/pigi/sendClearErrorMessageAction.test.ts b/tests/pigi/sendClearErrorMessageAction.test.ts deleted file mode 100644 index 14d44d5..0000000 --- a/tests/pigi/sendClearErrorMessageAction.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - apiErrors, - baseReturnObject, - pigiActionTypes, - FetchError, - IPigiResponseType, - sendClearErrorMessageAction, - sendClearErrorMessageActionAsync -} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('testing send PIGI Clear Error Message Action', () => { - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - const calledOnce = 1; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('calling sendClearErrorMessageAction success', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = true; - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendClearErrorMessageAction(); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendClearErrorMessageAction null Frame Window', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = false; - tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendClearErrorMessageAction(); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendClearErrorMessageActionAsync success', async () => { - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_CLEAR_ERROR_MESSAGES, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendClearErrorMessageActionAsync(); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); - diff --git a/tests/pigi/sendDisplayErrorMessageAction.test.ts b/tests/pigi/sendDisplayErrorMessageAction.test.ts deleted file mode 100644 index f3d1520..0000000 --- a/tests/pigi/sendDisplayErrorMessageAction.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendDisplayErrorMessageAction, sendDisplayErrorMessageActionAsync} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('testing send pigi Display Error Message Action', () => { - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - const message = 'message'; - const subType = 'sub_type'; - const calledOnce = 1; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('calling sendDisplayErrorMessageAction success', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = true; - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendDisplayErrorMessageAction(message, subType); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendDisplayErrorMessageAction null Frame Window', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = false; - tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendDisplayErrorMessageAction(message, subType); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendDisplayErrorMessageActionAsync success', async () => { - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_DISPLAY_ERROR_MESSAGE, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendDisplayErrorMessageActionAsync(message, subType); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); - diff --git a/tests/pigi/sendHandleScaAction.test.ts b/tests/pigi/sendHandleScaAction.test.ts deleted file mode 100644 index ef00a3e..0000000 --- a/tests/pigi/sendHandleScaAction.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendHandleScaAction, sendHandleScaActionAsync} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('testing send pigi Handle Sca Action', () => { - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - const clientSecretToken = 'string-for-secret-token'; - const calledOnce = 1; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('calling sendHandleScaAction success', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = true; - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendHandleScaAction(clientSecretToken); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendHandleScaAction null Frame Window', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = false; - tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendHandleScaAction(clientSecretToken); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - - test('calling sendHandleScaActionAsync success', async () => { - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_HANDLE_SCA, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendHandleScaActionAsync(); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); - diff --git a/tests/pigi/sendHideCreditCardOptionAction.test.ts b/tests/pigi/sendHideCreditCardOptionAction.test.ts deleted file mode 100644 index 9c3597d..0000000 --- a/tests/pigi/sendHideCreditCardOptionAction.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -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); - }); -}); - diff --git a/tests/pigi/sendPigiAction.test.ts b/tests/pigi/sendPigiAction.test.ts deleted file mode 100644 index 5eecf42..0000000 --- a/tests/pigi/sendPigiAction.test.ts +++ /dev/null @@ -1,173 +0,0 @@ -import {apiErrors, baseReturnObject, FetchError, IPigiActionType, sendPigiAction, sendPigiActionAsync} from 'src'; -import {pigi} from 'src/variables'; -import * as getPigiFrameWindow from 'src/pigi/getPigiFrameWindow'; - -const flushPromises = () => new Promise(jest.requireActual('timers').setImmediate); - -describe('testing send pigi Action', () => { - pigi.iFrameId = 'PIGI'; - const action: IPigiActionType = { actionType: 'TEST_ACTION' }; - const html_string = 'test'; - const src = 'data:text/html;charset=utf-8,' + escape(html_string); - const calledOnce = 1; - let getPigiFrameWindowSpy: jest.SpyInstance; - - beforeEach(() => { - jest.restoreAllMocks(); - getPigiFrameWindowSpy = jest.spyOn(getPigiFrameWindow, 'getPigiFrameWindow'); - }); - - test('calling sendPigiAction success', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = true; - const iFrame = document.createElement('iframe'); - iFrame.setAttribute('id', pigi.iFrameId); - iFrame.src = src; - document.body.appendChild(iFrame); - const postMessageSpy = jest.spyOn(iFrame.contentWindow as Window, 'postMessage'); - getPigiFrameWindowSpy.mockReturnValueOnce(iFrame.contentWindow); - - const res = sendPigiAction(action); - - expect(getPigiFrameWindowSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledWith(action, '*'); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendPigiAction null Frame Window', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - getPigiFrameWindowSpy.mockReturnValueOnce(null); - - const res = sendPigiAction(action); - - expect(getPigiFrameWindowSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendPigiActionAsync success', async () => { - const iFrame = document.createElement('iframe'); - iFrame.setAttribute('id', pigi.iFrameId); - iFrame.src = src; - document.body.appendChild(iFrame); - const postMessageSpy = jest.spyOn(iFrame.contentWindow as Window, 'postMessage'); - getPigiFrameWindowSpy.mockReturnValueOnce(iFrame.contentWindow); - - const pigiResponse = { - data: { - responseType: 'TEST_ACTION', - payload: {success: true} - } - }; - - const addEventListenerMock = jest.fn((event, callback) => { - callback(pigiResponse); - }); - const removeEventListenerMock = jest.fn(); - - window = Object.assign(window, { - addEventListener: addEventListenerMock, - removeEventListener: removeEventListenerMock - }); - - const res = await sendPigiActionAsync(action); - - expect(getPigiFrameWindowSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledWith(action, '*'); - expect(addEventListenerMock).toHaveBeenCalled(); - expect(removeEventListenerMock).toHaveBeenCalled(); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(pigiResponse.data); - }); - - test('calling sendPigiActionAsync failed response from pigi', async () => { - const iFrame = document.createElement('iframe'); - iFrame.setAttribute('id', pigi.iFrameId); - iFrame.src = src; - document.body.appendChild(iFrame); - const postMessageSpy = jest.spyOn(iFrame.contentWindow as Window, 'postMessage'); - getPigiFrameWindowSpy.mockReturnValueOnce(iFrame.contentWindow); - - const pigiResponse = { - data: { - responseType: 'TEST_ACTION', - payload: {success: false} - } - }; - - const addEventListenerMock = jest.fn((event, callback) => { - callback(pigiResponse); - }); - const removeEventListenerMock = jest.fn(); - - window = Object.assign(window, { - addEventListener: addEventListenerMock, - removeEventListener: removeEventListenerMock - }); - - await sendPigiActionAsync(action).catch(error => {expect(error).toBe(pigiResponse.data);}); - - expect(getPigiFrameWindowSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledWith(action, '*'); - expect(addEventListenerMock).toHaveBeenCalled(); - expect(removeEventListenerMock).toHaveBeenCalled(); - }); - - test('calling sendPigiActionAsync invalid data', async () => { - jest.useFakeTimers(); - const iFrame = document.createElement('iframe'); - iFrame.setAttribute('id', pigi.iFrameId); - iFrame.src = src; - document.body.appendChild(iFrame); - const postMessageSpy = jest.spyOn(iFrame.contentWindow as Window, 'postMessage'); - getPigiFrameWindowSpy.mockReturnValueOnce(iFrame.contentWindow); - - const pigiResponse = {}; - - const addEventListenerMock = jest.fn((event, callback) => { - callback(pigiResponse); - }); - const removeEventListenerMock = jest.fn(); - - window = Object.assign(window, { - addEventListener: addEventListenerMock, - removeEventListener: removeEventListenerMock - }); - - sendPigiActionAsync(action).catch(error => {expect(error).toBe('Pigi response timeout');}); - - jest.advanceTimersByTime(10_001); - - await flushPromises(); - - expect(getPigiFrameWindowSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledTimes(calledOnce); - expect(postMessageSpy).toHaveBeenCalledWith(action, '*'); - expect(addEventListenerMock).toHaveBeenCalled(); - expect(removeEventListenerMock).toHaveBeenCalled(); - }); - - test('calling sendPigiActionAsync null Frame Window', async () => { - const errorObject = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - getPigiFrameWindowSpy.mockReturnValueOnce(null); - - const addEventListenerMock = jest.fn(); - const removeEventListenerMock = jest.fn(); - - window = Object.assign(window, { - addEventListener: addEventListenerMock, - removeEventListener: removeEventListenerMock - }); - - await sendPigiActionAsync(action).catch(error => {expect(error).toStrictEqual(errorObject);}); - - expect(getPigiFrameWindowSpy).toHaveBeenCalledTimes(calledOnce); - expect(addEventListenerMock).toHaveBeenCalled(); - expect(removeEventListenerMock).toHaveBeenCalled(); - }); -}); diff --git a/tests/pigi/sendRefreshOrderAction.test.ts b/tests/pigi/sendRefreshOrderAction.test.ts deleted file mode 100644 index bccad1d..0000000 --- a/tests/pigi/sendRefreshOrderAction.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendRefreshOrderAction, sendRefreshOrderActionAsync} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('testing send pigi Refresh Order Action', () => { - const calledOnce = 1; - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('calling sendRefreshOrderAction success', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = true; - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendRefreshOrderAction(); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendRefreshOrderAction null Frame Window', () => { - const tempReturnObject = {...baseReturnObject}; - tempReturnObject.success = false; - tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(tempReturnObject); - - const res = sendRefreshOrderAction(); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); - - test('calling sendRefreshOrderActionAsync success', async () => { - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_REFRESH_ORDER, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendRefreshOrderActionAsync(); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); - diff --git a/tests/pigi/sendSelectPaymentMethodAction.test.tsx b/tests/pigi/sendSelectPaymentMethodAction.test.tsx deleted file mode 100644 index 7d68a60..0000000 --- a/tests/pigi/sendSelectPaymentMethodAction.test.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { - apiErrors, - baseReturnObject, - pigiActionTypes, - FetchError, - IPigiResponseType, - sendSelectPaymentMethodAction, - sendSelectPaymentMethodActionAsync -} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('Testing Pigi Select Payment Method action', () => { - const calledOnce = 1; - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('sendSelectPaymentMethodAction Error return', () => { - const payload = {index: 1, gatewayName: 'test'}; - const action = {actionType: pigiActionTypes.PIGI_SELECT_PAYMENT_METHOD, payload}; - const falseReturnObject = {...baseReturnObject}; - falseReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(falseReturnObject); - - const res = sendSelectPaymentMethodAction(payload); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(sendPigiActionSpy).toHaveBeenCalledWith(action); - expect(res).toStrictEqual(falseReturnObject); - }); - - test('sendSelectPaymentMethodAction Success return', () => { - const payload = {index: 1, gatewayName: 'test'}; - const action = {actionType: pigiActionTypes.PIGI_SELECT_PAYMENT_METHOD, payload}; - const trueReturnObject = {...baseReturnObject}; - trueReturnObject.success = true; - sendPigiActionSpy.mockReturnValueOnce(trueReturnObject); - - const res = sendSelectPaymentMethodAction(payload); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(sendPigiActionSpy).toHaveBeenCalledWith(action); - expect(res).toStrictEqual(trueReturnObject); - }); - - test('calling sendSelectPaymentMethodActionAsync success', async () => { - const payload = {index: 1, gatewayName: 'test'}; - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_SELECT_PAYMENT_METHOD, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendSelectPaymentMethodActionAsync(payload); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); diff --git a/tests/pigi/sendUpdateLanguageAction.test.ts b/tests/pigi/sendUpdateLanguageAction.test.ts deleted file mode 100644 index 61cdbfd..0000000 --- a/tests/pigi/sendUpdateLanguageAction.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { - apiErrors, - baseReturnObject, - pigiActionTypes, - FetchError, - IPigiResponseType, - sendUpdateLanguageAction, - sendUpdateLanguageActionAsync -} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('Testing UPDATE_LANGUAGE action sent to PIGI iFrame', () => { - const calledOnce = 1; - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('iframe content is null', () => { - const falseReturnObject = {...baseReturnObject}; - falseReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction').mockReturnValue(falseReturnObject); - - const res = sendUpdateLanguageAction('en'); - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).toStrictEqual(falseReturnObject); - }); - - test('iframe content is populated', () => { - const correctReturnObject = {...baseReturnObject}; - correctReturnObject.success = true; - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction').mockReturnValue(correctReturnObject); - - const res = sendUpdateLanguageAction('en'); - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).toStrictEqual(correctReturnObject); - }); - - - test('calling sendUpdateLanguageActionAsync success', async () => { - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_UPDATE_LANGUAGE, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendUpdateLanguageActionAsync('en'); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); diff --git a/tests/pigi/sendUpdateMediaMatchAction.test.tsx b/tests/pigi/sendUpdateMediaMatchAction.test.tsx deleted file mode 100644 index d5ce6d2..0000000 --- a/tests/pigi/sendUpdateMediaMatchAction.test.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { - apiErrors, - baseReturnObject, - pigiActionTypes, - FetchError, - IPigiActionType, - IPigiResponseType, - sendUpdateMediaMatchAction, - sendUpdateMediaMatchActionAsync -} from 'src'; -import * as sendPigiAction from 'src/pigi/sendPigiAction'; - -describe('Testing Pigi Update Media Match action', () => { - const calledOnce = 1; - let sendPigiActionSpy: jest.SpyInstance; - let sendPigiActionAsyncSpy: jest.SpyInstance; - - beforeEach(() => { - jest.restoreAllMocks(); - sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction'); - sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync'); - }); - - test('sendUpdateMediaMatchAction Error return', () => { - const conditionText = 'screen and (min-width: 768px)'; - const matches = false; - const payload = {conditionText, matches}; - const action: IPigiActionType = {actionType: pigiActionTypes.PIGI_UPDATE_MEDIA_MATCH, payload}; - const falseReturnObject = {...baseReturnObject}; - falseReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message); - sendPigiActionSpy.mockReturnValueOnce(falseReturnObject); - - const res = sendUpdateMediaMatchAction(conditionText, matches); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(sendPigiActionSpy).toHaveBeenCalledWith(action); - expect(res).toStrictEqual(falseReturnObject); - }); - - test('sendUpdateMediaMatchAction Success return', () => { - const conditionText = 'screen and (min-width: 768px)'; - const matches = false; - const payload = {conditionText, matches}; - const action: IPigiActionType = {actionType: pigiActionTypes.PIGI_UPDATE_MEDIA_MATCH, payload}; - const trueReturnObject = {...baseReturnObject}; - trueReturnObject.success = true; - sendPigiActionSpy.mockReturnValueOnce(trueReturnObject); - - const res = sendUpdateMediaMatchAction(conditionText, matches); - - expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce); - expect(sendPigiActionSpy).toHaveBeenCalledWith(action); - expect(res).toStrictEqual(trueReturnObject); - }); - - test('calling sendUpdateMediaMatchActionAsync success', async () => { - const conditionText = 'screen and (min-width: 768px)'; - const matches = false; - const tempReturnObject: IPigiResponseType = { - responseType: pigiActionTypes.PIGI_ADD_PAYMENT, - payload: {success: true} - }; - sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject); - - const res = await sendUpdateMediaMatchActionAsync(conditionText, matches); - - expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce); - expect(res).not.toBeNull(); - expect(res).toStrictEqual(tempReturnObject); - }); -}); diff --git a/tests/pigi/setPigiListener.test.ts b/tests/pigi/setPigiListener.test.ts deleted file mode 100644 index 4bb867f..0000000 --- a/tests/pigi/setPigiListener.test.ts +++ /dev/null @@ -1,101 +0,0 @@ -import {pigiActionTypes, IPigiActionTypes, setPigiListener, removePigiListener} from 'src'; -import {pigi} from 'src/variables'; - -describe('testing set pigi listener', () => { - const iFrameId = '#PIGI'; - const noHashTagIFrameId = 'PIGI'; - const calledOnce = 1; - const notCalled = 0; - const pigiActionTypesKeys = Object.keys(pigiActionTypes); - const getAddEventListenerImplementation = (event: MessageEvent) => { - return (type: string, listener: EventListenerOrEventListenerObject) => { - if(typeof listener === 'function') { - listener(event); - } else { - listener.handleEvent(event); - } - }; - }; - - beforeEach(() => { - jest.restoreAllMocks(); - }); - - test.each(pigiActionTypesKeys)('calling setPigiListener with function listener and action %s', key => { - jest.restoreAllMocks(); - const eventInit = { data: { responseType: pigiActionTypes[key as keyof IPigiActionTypes], payload: {something: 'test'} } }; - const event = new MessageEvent('test', eventInit); - const eventHandlerFunction: EventListener = jest.fn(); - const addEventListenerSpy = jest.spyOn(window, 'addEventListener') - .mockImplementationOnce(getAddEventListenerImplementation(event)); - const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener'); - - setPigiListener(iFrameId, eventHandlerFunction); - - expect(removeEventListenerSpy).toHaveBeenCalledTimes(1); - expect(addEventListenerSpy).toHaveBeenCalledTimes(calledOnce); - expect(eventHandlerFunction).toHaveBeenCalledTimes(calledOnce); - expect(eventHandlerFunction).toHaveBeenCalledWith(event); - expect(pigi.iFrameId).toBe(noHashTagIFrameId); - }); - - test.each(pigiActionTypesKeys)('calling setPigiListener with object listener and action %s', key => { - jest.restoreAllMocks(); - const eventInit = { data: { responseType: pigiActionTypes[key as keyof IPigiActionTypes], payload: {something: 'test'} } }; - const event = new MessageEvent('test', eventInit); - const eventHandlerObject: EventListenerObject = {handleEvent: jest.fn()}; - const addEventListenerSpy = jest.spyOn(window, 'addEventListener') - .mockImplementationOnce(getAddEventListenerImplementation(event)); - const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener'); - - setPigiListener(iFrameId, eventHandlerObject); - - expect(removeEventListenerSpy).toHaveBeenCalledTimes(1); - expect(addEventListenerSpy).toHaveBeenCalledTimes(calledOnce); - expect(eventHandlerObject.handleEvent).toHaveBeenCalledTimes(calledOnce); - expect(eventHandlerObject.handleEvent).toHaveBeenCalledWith(event); - expect(pigi.iFrameId).toBe(noHashTagIFrameId); - }); - - test('calling setPigiListener invalid action type', () => { - const eventInit = { data: { responseType: 'invalid_action_type', payload: {something: 'test'} } }; - const event = new MessageEvent('test', eventInit); - const eventHandlerFunction: EventListener = jest.fn(); - const addEventListenerSpy = jest.spyOn(window, 'addEventListener') - .mockImplementationOnce(getAddEventListenerImplementation(event)); - const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener'); - - setPigiListener(iFrameId, eventHandlerFunction); - - expect(removeEventListenerSpy).toHaveBeenCalledTimes(1); - expect(addEventListenerSpy).toHaveBeenCalledTimes(calledOnce); - expect(eventHandlerFunction).toHaveBeenCalledTimes(notCalled); - expect(pigi.iFrameId).toBe(noHashTagIFrameId); - }); - - test('calling setPigiListener invalid data', () => { - const eventInit = {}; - const event = new MessageEvent('test', eventInit); - const eventHandlerFunction: EventListener = jest.fn(); - const addEventListenerSpy = jest.spyOn(window, 'addEventListener') - .mockImplementationOnce(getAddEventListenerImplementation(event)); - const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener'); - - setPigiListener(iFrameId, eventHandlerFunction); - - expect(removeEventListenerSpy).toHaveBeenCalledTimes(1); - expect(addEventListenerSpy).toHaveBeenCalledTimes(calledOnce); - expect(eventHandlerFunction).toHaveBeenCalledTimes(notCalled); - expect(pigi.iFrameId).toBe(noHashTagIFrameId); - }); - - test('calling removePigiListener with function listener ', () => { - jest.restoreAllMocks(); - const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener'); - - removePigiListener(); - - expect(removeEventListenerSpy).toHaveBeenCalledTimes(1); - }); -}); -