Skip to content

Commit

Permalink
refactor(analytics): group some constants together
Browse files Browse the repository at this point in the history
  • Loading branch information
longyulongyu committed Nov 15, 2024
1 parent 30b750d commit ca44cd9
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 81 deletions.
19 changes: 9 additions & 10 deletions packages/lib/src/components/Card/Card.Analytics.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ let analyticsEventObject;

import {
ANALYTICS_CONFIGURED_STR,
ANALYTICS_EVENT_INFO,
ANALYTICS_EVENT_LOG,
ANALYTICS_EVENT,
ANALYTICS_FOCUS_STR,
ANALYTICS_RENDERED_STR,
ANALYTICS_SUBMIT_STR,
Expand Down Expand Up @@ -47,7 +46,7 @@ describe('Card: calls that generate "info" analytics should produce objects with

// With configData removed inspect what's left
expect(analyticsEventObject).toEqual({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: { component: card.constructor['type'], type: ANALYTICS_RENDERED_STR }
});
});
Expand All @@ -65,7 +64,7 @@ describe('Card: calls that generate "info" analytics should produce objects with

// With configData removed inspect what's left
expect(analyticsEventObject).toEqual({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: { component: card.constructor['type'], type: ANALYTICS_RENDERED_STR, isStoredPaymentMethod: true, brand: 'mc' }
});
});
Expand All @@ -76,7 +75,7 @@ describe('Card: calls that generate "info" analytics should produce objects with
});

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: { component: card.constructor['type'], type: ANALYTICS_CONFIGURED_STR }
});
});
Expand All @@ -89,7 +88,7 @@ describe('Card: calls that generate "info" analytics should produce objects with
});

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: { component: card.constructor['type'], type: ANALYTICS_CONFIGURED_STR, isStoredPaymentMethod: true, brand: 'mc' }
});
});
Expand All @@ -109,7 +108,7 @@ describe('Card: calls that generate "info" analytics should produce objects with
});

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: { component: card.constructor['type'], type: ANALYTICS_FOCUS_STR, target: 'card_number' }
});
});
Expand All @@ -129,7 +128,7 @@ describe('Card: calls that generate "info" analytics should produce objects with
});

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: { component: card.constructor['type'], type: ANALYTICS_UNFOCUS_STR, target: 'card_number' }
});
});
Expand All @@ -141,7 +140,7 @@ describe('Card: calls that generate "info" analytics should produce objects with
});

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: {
component: card.constructor['type'],
type: ANALYTICS_VALIDATION_ERROR_STR,
Expand Down Expand Up @@ -170,7 +169,7 @@ describe('Card: calls that generate "log" analytics should produce objects with
card.submitAnalytics({ type: ANALYTICS_SUBMIT_STR });

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_LOG,
event: ANALYTICS_EVENT.log,
data: {
component: card.constructor['type'],
type: ANALYTICS_SUBMIT_STR,
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/src/components/GooglePay/GooglePay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GooglePay from './GooglePay';
import GooglePayService from './GooglePayService';

import Analytics from '../../core/Analytics';
import { ANALYTICS_EVENT_INFO, ANALYTICS_SELECTED_STR, NO_CHECKOUT_ATTEMPT_ID } from '../../core/Analytics/constants';
import { ANALYTICS_EVENT, ANALYTICS_SELECTED_STR, NO_CHECKOUT_ATTEMPT_ID } from '../../core/Analytics/constants';

const analyticsModule = Analytics({ analytics: {}, loadingContext: '', locale: '', clientKey: '', bundleType: 'umd' });

Expand Down Expand Up @@ -458,7 +458,7 @@ describe('GooglePay', () => {
gpay.submit();

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_INFO,
event: ANALYTICS_EVENT.info,
data: {
component: gpay.props.type,
type: ANALYTICS_SELECTED_STR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ interface RedirectShopperProps {
redirectFromTopWhenInIframe?: boolean;
paymentMethodType?: string;
onActionHandled?: (rtnObj: ActionHandledReturnObject) => void;
onRedirectError?: () => void;
}

class RedirectShopper extends Component<RedirectShopperProps> {
private postForm;
public static defaultProps = {
beforeRedirect: resolve => resolve(),
onRedirectError: () => {},
method: 'GET'
};

Expand Down Expand Up @@ -49,7 +51,9 @@ class RedirectShopper extends Component<RedirectShopperProps> {
})
);

dispatchEvent.then(doRedirect).catch(() => {});
dispatchEvent.then(doRedirect).catch(() => {
this.props.onRedirectError();
});
}

render({ url, method, data = {} }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ThreeDS2Challenge } from './index';
import Analytics from '../../core/Analytics';
import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_EVENT_ERROR, ANALYTICS_RENDERED_STR } from '../../core/Analytics/constants';
import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, ANALYTICS_EVENT } from '../../core/Analytics/constants';
import { THREEDS2_CHALLENGE_ERROR, THREEDS2_ERROR } from './constants';

const analyticsModule = Analytics({ analytics: {}, loadingContext: '', locale: '', clientKey: '', bundleType: 'umd' });
Expand Down Expand Up @@ -31,11 +31,11 @@ describe('ThreeDS2Challenge: calls that generate analytics should produce object
const view = challenge.render();

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_ERROR,
event: ANALYTICS_EVENT.error,
data: {
component: challenge.constructor['type'],
type: THREEDS2_ERROR,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_CHALLENGE_ERROR}: Missing 'paymentData' property from threeDS2 action`,
code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA
}
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/src/components/ThreeDS2/ThreeDS2Challenge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hasOwnProperty } from '../../utils/hasOwnProperty';
import { TxVariants } from '../tx-variants';
import { ThreeDS2ChallengeConfiguration } from './types';
import AdyenCheckoutError, { API_ERROR } from '../../core/Errors/AdyenCheckoutError';
import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants';
import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants';
import { SendAnalyticsObject } from '../../core/Analytics/types';
import { CoreProvider } from '../../core/Context/CoreProvider';
import { ActionHandledReturnObject } from '../../types/global-types';
Expand Down Expand Up @@ -61,7 +61,7 @@ class ThreeDS2Challenge extends UIElement<ThreeDS2ChallengeConfiguration> {
this.submitAnalytics({
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_CHALLENGE_ERROR}: Missing 'paymentData' property from threeDS2 action`
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ThreeDS2DeviceFingerprint } from './index';
import Analytics from '../../core/Analytics';
import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_EVENT_ERROR, ANALYTICS_RENDERED_STR } from '../../core/Analytics/constants';
import { Analytics3DS2Errors, ANALYTICS_RENDERED_STR, ANALYTICS_EVENT, ANALYTICS_ERROR_TYPE } from '../../core/Analytics/constants';
import { THREEDS2_ERROR, THREEDS2_FINGERPRINT_ERROR } from './constants';

const analyticsModule = Analytics({ analytics: {}, loadingContext: '', locale: '', clientKey: '', bundleType: 'umd' });
Expand Down Expand Up @@ -32,11 +32,11 @@ describe('ThreeDS2DeviceFingerprint: calls that generate analytics should produc
const view = fingerprint.render();

expect(analyticsModule.createAnalyticsEvent).toHaveBeenCalledWith({
event: ANALYTICS_EVENT_ERROR,
event: ANALYTICS_EVENT.error,
data: {
component: fingerprint.constructor['type'],
type: THREEDS2_ERROR,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_FINGERPRINT_ERROR}: Missing 'paymentData' property from threeDS2 action`,
code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { existy } from '../../utils/commonUtils';
import { TxVariants } from '../tx-variants';
import { ThreeDS2DeviceFingerprintConfiguration } from './types';
import AdyenCheckoutError, { API_ERROR } from '../../core/Errors/AdyenCheckoutError';
import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants';
import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, ANALYTICS_RENDERED_STR, Analytics3DS2Events } from '../../core/Analytics/constants';
import { SendAnalyticsObject } from '../../core/Analytics/types';
import { THREEDS2_ERROR, THREEDS2_FINGERPRINT, THREEDS2_FINGERPRINT_ERROR, THREEDS2_FULL } from './constants';
import { ActionHandledReturnObject } from '../../types/global-types';
Expand Down Expand Up @@ -53,7 +53,7 @@ class ThreeDS2DeviceFingerprint extends UIElement<ThreeDS2DeviceFingerprintConfi
this.submitAnalytics({
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.ACTION_IS_MISSING_PAYMENT_DATA,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_FINGERPRINT_ERROR}: Missing 'paymentData' property from threeDS2 action`
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pick } from '../../utils/commonUtils';
import { ThreeDS2FingerprintResponse } from './types';
import AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';
import { THREEDS2_ERROR, THREEDS2_FINGERPRINT_SUBMIT } from './constants';
import { ANALYTICS_API_ERROR, Analytics3DS2Errors, ANALYTICS_SDK_ERROR } from '../../core/Analytics/constants';
import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors } from '../../core/Analytics/constants';
import { SendAnalyticsObject } from '../../core/Analytics/types';

/**
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function callSubmit3DS2Fingerprint({ data }): void {
analyticsErrorObject = {
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.NO_DETAILS_FOR_FRICTIONLESS_OR_REFUSED,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_FINGERPRINT_SUBMIT}: no details object in a response indicating either a "frictionless" flow, or a "refused" response`
};

Expand All @@ -62,7 +62,7 @@ export default function callSubmit3DS2Fingerprint({ data }): void {
analyticsErrorObject = {
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.NO_ACTION_FOR_CHALLENGE,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_FINGERPRINT_SUBMIT}: no action object in a response indicating a "challenge" flow`
};
this.submitAnalytics(analyticsErrorObject);
Expand All @@ -82,7 +82,7 @@ export default function callSubmit3DS2Fingerprint({ data }): void {
analyticsErrorObject = {
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.NO_COMPONENT_FOR_ACTION,
errorType: ANALYTICS_SDK_ERROR,
errorType: ANALYTICS_ERROR_TYPE.sdkError,
message: `${THREEDS2_FINGERPRINT_SUBMIT}: no component defined to handle the action response`
};
this.submitAnalytics(analyticsErrorObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { h } from 'preact';
import PrepareChallenge3DS2 from './PrepareChallenge3DS2';
import { CoreProvider } from '../../../../core/Context/CoreProvider';
import { THREEDS2_ERROR, THREEDS2_FULL, TIMEOUT } from '../../constants';
import { Analytics3DS2Errors, Analytics3DS2Events, ANALYTICS_API_ERROR, ANALYTICS_NETWORK_ERROR } from '../../../../core/Analytics/constants';
import { Analytics3DS2Errors, Analytics3DS2Events, ANALYTICS_ERROR_TYPE } from '../../../../core/Analytics/constants';

const challengeToken = {
acsReferenceNumber: 'ADYEN-ACS-SIMULATOR',
Expand Down Expand Up @@ -33,7 +33,7 @@ let errorMessage: string;

const baseAnalyticsError = {
type: THREEDS2_ERROR,
errorType: ANALYTICS_API_ERROR
errorType: ANALYTICS_ERROR_TYPE.apiError
};

let onSubmitAnalytics: any;
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('PrepareChallenge3DS2 - flow completes with errors that are considered
type: THREEDS2_ERROR,
message: 'threeDS2Challenge: timeout',
code: Analytics3DS2Errors.THREEDS2_TIMEOUT,
errorType: ANALYTICS_NETWORK_ERROR
errorType: ANALYTICS_ERROR_TYPE.network
});

// analytics to say process is complete
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('PrepareChallenge3DS2 - flow completes with errors that are considered
type: THREEDS2_ERROR,
message: 'threeDS2Challenge: no transStatus could be retrieved',
code: Analytics3DS2Errors.NO_TRANSSTATUS,
errorType: ANALYTICS_API_ERROR
errorType: ANALYTICS_ERROR_TYPE.apiError
});

// analytics to say process is complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
THREEDS2_ERROR
} from '../../constants';
import { isValidHttpUrl } from '../../../../utils/isValidURL';
import { ANALYTICS_API_ERROR, ANALYTICS_NETWORK_ERROR, Analytics3DS2Errors, Analytics3DS2Events } from '../../../../core/Analytics/constants';
import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, Analytics3DS2Events } from '../../../../core/Analytics/constants';
import { ErrorObject } from '../../../../core/Errors/types';

class PrepareChallenge3DS2 extends Component<PrepareChallenge3DS2Props, PrepareChallenge3DS2State> {
Expand Down Expand Up @@ -91,7 +91,7 @@ class PrepareChallenge3DS2 extends Component<PrepareChallenge3DS2Props, PrepareC
const errorCodeObject: SendAnalyticsObject = {
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.TOKEN_IS_MISSING_ACSURL,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_CHALLENGE_ERROR}: Decoded token is missing a valid acsURL property`
// metadata: { acsURL } // NEW TODO - check acsURL isn't secret
};
Expand All @@ -118,7 +118,7 @@ class PrepareChallenge3DS2 extends Component<PrepareChallenge3DS2Props, PrepareC
this.props.onSubmitAnalytics({
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.TOKEN_IS_MISSING_OTHER_PROPS,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_CHALLENGE_ERROR}: Decoded token is missing one or more of the following properties (acsTransID | messageVersion | threeDSServerTransID)`
} as SendAnalyticsObject);

Expand Down Expand Up @@ -155,7 +155,7 @@ class PrepareChallenge3DS2 extends Component<PrepareChallenge3DS2Props, PrepareC
this.props.onSubmitAnalytics({
type: THREEDS2_ERROR,
code: errorCode,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_CHALLENGE_ERROR}: ${errorMsg}` // can be: 'Missing "token" property from threeDS2 action', 'not base64', 'malformed URI sequence' or 'Could not JSON parse token'
});

Expand Down Expand Up @@ -183,7 +183,7 @@ class PrepareChallenge3DS2 extends Component<PrepareChallenge3DS2Props, PrepareC
if (finalResObject.errorCode) {
const errorTypeAndCode = {
code: finalResObject.errorCode === 'timeout' ? Analytics3DS2Errors.THREEDS2_TIMEOUT : Analytics3DS2Errors.NO_TRANSSTATUS,
errorType: finalResObject.errorCode === 'timeout' ? ANALYTICS_NETWORK_ERROR : ANALYTICS_API_ERROR
errorType: finalResObject.errorCode === 'timeout' ? ANALYTICS_ERROR_TYPE.network : ANALYTICS_ERROR_TYPE.apiError
};

// Challenge process has timed out,
Expand Down Expand Up @@ -308,7 +308,7 @@ class PrepareChallenge3DS2 extends Component<PrepareChallenge3DS2Props, PrepareC
this.props.onSubmitAnalytics({
type: THREEDS2_ERROR,
code: Analytics3DS2Errors.CHALLENGE_RESOLVED_WITHOUT_RESULT_PROP,
errorType: ANALYTICS_API_ERROR,
errorType: ANALYTICS_ERROR_TYPE.apiError,
message: `${THREEDS2_CHALLENGE_ERROR}: challenge resolved without a "result" object`
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mount } from 'enzyme';
import { h } from 'preact';
import PrepareFingerprint3DS2 from './PrepareFingerprint3DS2';
import { THREEDS2_ERROR, THREEDS2_FINGERPRINT_ERROR, THREEDS2_FULL, TIMEOUT } from '../../constants';
import { Analytics3DS2Errors, Analytics3DS2Events, ANALYTICS_API_ERROR, ANALYTICS_NETWORK_ERROR } from '../../../../core/Analytics/constants';
import { Analytics3DS2Errors, Analytics3DS2Events, ANALYTICS_ERROR_TYPE } from '../../../../core/Analytics/constants';

const fingerPrintToken = {
threeDSMessageVersion: '2.1.0',
Expand Down Expand Up @@ -32,7 +32,7 @@ const onError: any = () => {};

const baseAnalyticsError = {
type: THREEDS2_ERROR,
errorType: ANALYTICS_API_ERROR
errorType: ANALYTICS_ERROR_TYPE.apiError
};

let completeFunction: any;
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('ThreeDS2DeviceFingerprint - flow completes with errors that are consid
type: THREEDS2_ERROR,
message: 'threeDS2Fingerprint: timeout',
code: Analytics3DS2Errors.THREEDS2_TIMEOUT,
errorType: ANALYTICS_NETWORK_ERROR
errorType: ANALYTICS_ERROR_TYPE.network
});

// analytics to say process is complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
THREEDS2_ERROR,
TIMEOUT
} from '../../constants';
import { ANALYTICS_API_ERROR, ANALYTICS_NETWORK_ERROR, Analytics3DS2Errors, Analytics3DS2Events } from '../../../../core/Analytics/constants';
import { ANALYTICS_ERROR_TYPE, Analytics3DS2Errors, Analytics3DS2Events } from '../../../../core/Analytics/constants';

class PrepareFingerprint3DS2 extends Component<PrepareFingerprint3DS2Props, PrepareFingerprint3DS2State> {
public static type = 'scheme';
Expand Down Expand Up @@ -163,7 +163,7 @@ class PrepareFingerprint3DS2 extends Component<PrepareFingerprint3DS2Props, Prep
if (finalResObject.errorCode) {
const errorTypeAndCode = {
code: finalResObject.errorCode === TIMEOUT ? Analytics3DS2Errors.THREEDS2_TIMEOUT : finalResObject.errorCode,
errorType: finalResObject.errorCode === TIMEOUT ? ANALYTICS_NETWORK_ERROR : ANALYTICS_API_ERROR
errorType: finalResObject.errorCode === TIMEOUT ? ANALYTICS_ERROR_TYPE.network : ANALYTICS_ERROR_TYPE.apiError
};

/**
Expand Down
Loading

0 comments on commit ca44cd9

Please sign in to comment.