Skip to content

Commit

Permalink
Fixes after v5 merge (v5.60.0) to allow yarn build to run
Browse files Browse the repository at this point in the history
  • Loading branch information
sponglord committed Mar 12, 2024
1 parent 957da7c commit 211b610
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
3 changes: 1 addition & 2 deletions packages/lib/src/components/ApplePay/ApplePay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { APPLEPAY_SESSION_ENDPOINT } from './config';
import { preparePaymentRequest } from './payment-request';
import { resolveSupportedVersion, mapBrands, formatApplePayContactToAdyenAddressFormat } from './utils';
import AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';
import { ANALYTICS_INSTANT_PAYMENT_BUTTON, ANALYTICS_SELECTED_STR } from '../../core/Analytics/constants';
import { DecodeObject } from '../types';
import { DecodeObject } from '../../types/global-types';
import { TxVariants } from '../tx-variants';
import { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';
import { ANALYTICS_INSTANT_PAYMENT_BUTTON, ANALYTICS_SELECTED_STR } from '../../core/Analytics/constants';
Expand Down
28 changes: 19 additions & 9 deletions packages/lib/src/components/Card/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,33 @@ describe('Card', () => {

test('should only return storePaymentMethod:true for regular card, zero auth payments, *if* the conditions are right', () => {
// Manual flow
expect(new CardElement(global.core, { amount: { value: 0 }, enableStoreDetails: true }).data.storePaymentMethod).toBe(true);
expect(new CardElement(global.core, { amount: { value: 0 }, enableStoreDetails: false }).data.storePaymentMethod).toBe(undefined);
expect(new CardElement(global.core, { amount: { value: 0, currency: 'USD' }, enableStoreDetails: true }).data.storePaymentMethod).toBe(
true
);
expect(new CardElement(global.core, { amount: { value: 0, currency: 'USD' }, enableStoreDetails: false }).data.storePaymentMethod).toBe(
undefined
);

// Session flow - session configuration should override merchant configuration
let cardElement = new CardElement(global.core, {
amount: { value: 0 },
amount: { value: 0, currency: 'USD' },
enableStoreDetails: false,
// @ts-ignore it's just a test
session: { configuration: { enableStoreDetails: true } }
});
expect(cardElement.data.storePaymentMethod).toBe(true);

cardElement = new CardElement(global.core, {
amount: { value: 0 },
amount: { value: 0, currency: 'USD' },
enableStoreDetails: true,
// @ts-ignore it's just a test
session: { configuration: { enableStoreDetails: false } }
});
expect(cardElement.data.storePaymentMethod).toBe(undefined);
});

test('should return storePaymentMethod based on the checkbox value, for regular card, non-zero auth payments', () => {
const card = new CardElement(global.core, { amount: { value: 10 }, enableStoreDetails: true });
const card = new CardElement(global.core, { amount: { value: 10, currency: 'USD' }, enableStoreDetails: true });
card.setState({ storePaymentMethod: true });
expect(card.data.storePaymentMethod).toBe(true);
card.setState({ storePaymentMethod: false });
Expand All @@ -116,19 +122,23 @@ describe('Card', () => {

test('should not return storePaymentMethod for stored card, non-zero auth payments', () => {
expect(
new CardElement(global.core, { amount: { value: 10 }, storedPaymentMethodId: 'xxx', enableStoreDetails: true }).data.storePaymentMethod
new CardElement(global.core, { amount: { value: 10, currency: 'USD' }, storedPaymentMethodId: 'xxx', enableStoreDetails: true }).data
.storePaymentMethod
).not.toBeDefined();
expect(
new CardElement(global.core, { amount: { value: 10 }, storedPaymentMethodId: 'xxx', enableStoreDetails: false }).data.storePaymentMethod
new CardElement(global.core, { amount: { value: 10, currency: 'USD' }, storedPaymentMethodId: 'xxx', enableStoreDetails: false }).data
.storePaymentMethod
).not.toBeDefined();
});

test('should not return storePaymentMethod for stored card, zero auth payments', () => {
expect(
new CardElement(global.core, { amount: { value: 0 }, storedPaymentMethodId: 'xxx', enableStoreDetails: true }).data.storePaymentMethod
new CardElement(global.core, { amount: { value: 0, currency: 'USD' }, storedPaymentMethodId: 'xxx', enableStoreDetails: true }).data
.storePaymentMethod
).not.toBeDefined();
expect(
new CardElement(global.core, { amount: { value: 0 }, storedPaymentMethodId: 'xxx', enableStoreDetails: false }).data.storePaymentMethod
new CardElement(global.core, { amount: { value: 0, currency: 'USD' }, storedPaymentMethodId: 'xxx', enableStoreDetails: false }).data
.storePaymentMethod
).not.toBeDefined();
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/components/Donation/Donation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DonationElement extends UIElement<DonationConfiguration> {
render() {
return (
<CoreProvider i18n={this.props.i18n} loadingContext={this.props.loadingContext} resources={this.resources}>
{/*@ts-ignore ref*/}
<DonationComponent {...this.props} ref={this.handleRef} onChange={this.setState} onDonate={this.donate} />
</CoreProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/ThreeDS2/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getOrigin } from '../../../utils/getOrigin';
import base64 from '../../../utils/base64';
import { ChallengeData, ThreeDS2Token, FingerPrintData, ResultObject } from '../types';
import { pick } from '../../internal/SecuredFields/utils';
import { DecodeObject } from '../../types';
import { DecodeObject } from '../../../types/global-types';
import { ErrorObject } from '../../../core/Errors/types';

export interface FingerprintResolveData {
Expand Down
11 changes: 0 additions & 11 deletions packages/lib/src/core/Errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ const fieldTypeToErrorCodeIdentifier = (fieldType: string): string => {
return errorCodeIdentifier;
};

export const getErrorMessageFromCode = (errorCode: string, codeMap: Record<string, string>): string => {
let errMsg = errorCode;
for (const [key, value] of Object.entries(codeMap)) {
if (value === errorCode) {
errMsg = key;
break;
}
}
return errMsg?.toLowerCase().replace(/[_.]/g, '-');
};

/**
* sortErrorsByLayout - takes a list of errors and a layout, and returns a sorted array of error objects with translated error messages
*
Expand Down
8 changes: 7 additions & 1 deletion packages/lib/src/types/global-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export type RawPaymentResponse = PaymentResponseData &
[key: string]: any;
};

export type ActionDescriptionType = 'qr-code-loaded' | 'polling-started' | 'fingerprint-iframe-loaded' | 'challenge-iframe-loaded';
export type ActionDescriptionType = 'qr-code-loaded' | 'polling-started' | 'fingerprint-iframe-loaded' | string;

export interface ActionHandledReturnObject {
componentType: string;
Expand Down Expand Up @@ -391,3 +391,9 @@ export type ComponentFocusObject = {
fieldType: string;
event: Event | CbObjOnFocus;
};

export type DecodeObject = {
success: boolean;
error?: string;
data?: string;
};
2 changes: 1 addition & 1 deletion packages/lib/src/utils/base64.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DecodeObject } from '../components/types';
import { DecodeObject } from '../types/global-types';

export const NOT_BASE64_ERROR = 'not base64';
export const BASE64_MALFORMED_URI_ERROR = 'malformed URI sequence';
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
"./src/**/*",
"./src/types/custom.d.ts",
],
"exclude": ["node_modules", "./dist/**", "**/*.scss", "**/*_*/**"],
"exclude": ["node_modules", "./dist/**", "**/*.scss", "**/*_*/**", "**/*.test.*"],
}

0 comments on commit 211b610

Please sign in to comment.