Skip to content

Commit

Permalink
fix(SFI-1047): refactor eventType and add pluginType
Browse files Browse the repository at this point in the history
  • Loading branch information
shanikantsingh committed Jan 13, 2025
1 parent a5ef677 commit 32abaf0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('analyticsHook', () => {
};
onStartHandler(req);
expect(createAnalyticsEvent).toHaveBeenCalled();
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'START', 'EXPECTED', 'info');
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'expectedStart', 'EXPECTED', 'info');
})
it('should not create Start event when adyen analytics is disabled in BM', () => {
const req = {
Expand All @@ -51,7 +51,7 @@ describe('analyticsHook', () => {
};
onCompleteHandler(req, res);
expect(createAnalyticsEvent).toHaveBeenCalled();
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'END', 'EXPECTED', 'info');
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'expectedEnd', 'EXPECTED', 'info');
})
it('should create End event with unexpected status when onCompleteHandler is called for error in route', () => {
const req = {
Expand All @@ -62,7 +62,7 @@ describe('analyticsHook', () => {
};
onCompleteHandler(req, res);
expect(createAnalyticsEvent).toHaveBeenCalled();
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'END', 'UNEXPECTED', 'info');
expect(createAnalyticsEvent).toHaveBeenCalledWith('mocked_sessionID','Adyen-GetPaymentMethods', 'unexpectedEnd', 'UNEXPECTED', 'info');
})
it('should not create End event when adyen analytics is disabled in BM', () => {
const req = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function onStartHandler(req) {
analyticsEvent.createAnalyticsEvent(
session.sessionID,
path.join('-'),
analyticsConstants.eventType.START,
analyticsConstants.eventType.EXPECTED_START,
analyticsConstants.eventStatus.EXPECTED,
analyticsConstants.eventCode.INFO,
);
Expand All @@ -75,15 +75,15 @@ function onCompleteHandler(req, res) {
analyticsEvent.createAnalyticsEvent(
session.sessionID,
path.join('-'),
analyticsConstants.eventType.END,
analyticsConstants.eventType.UNEXPECTED_END,
analyticsConstants.eventStatus.UNEXPECTED,
analyticsConstants.eventCode.INFO,
);
} else {
analyticsEvent.createAnalyticsEvent(
session.sessionID,
path.join('-'),
analyticsConstants.eventType.END,
analyticsConstants.eventType.EXPECTED_END,
analyticsConstants.eventStatus.EXPECTED,
analyticsConstants.eventCode.INFO,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');
const AdyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
const constants = require('*/cartridge/adyen/config/constants');
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs');
const analyticsConstants = require('*/cartridge/adyen/analytics/constants');

function execute(serviceType, requestObject, checkoutAttemptID = '') {
const service = AdyenHelper.getService(serviceType);
Expand Down Expand Up @@ -42,6 +43,7 @@ function createCheckoutAttemptId() {
applicationInfo: AdyenHelper.getApplicationInfo(),
channel: 'Web',
platform: 'Web',
pluginType: analyticsConstants.pluginType,
};

const response = execute(constants.SERVICE.ADYEN_ANALYTICS, requestObject);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
analyticsEventObjectId: 'AdyenAnalyticsEvents',
pluginType: 'salesforceCommerceCloud',
eventType: {
START: 'START',
END: 'END',
EXPECTED_START: 'expectedStart',
UNEXPECTED_START: 'unexpectedStart',
EXPECTED_END: 'expectedEnd',
UNEXPECTED_END: 'unexpectedEnd',
},
eventStatus: {
EXPECTED: 'EXPECTED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function createRequestObjectForAllReferenceIds(groupedObjects) {
const requestObject = {
channel: 'Web',
platform: 'Web',
pluginType: constants.pluginType,
};

// Iterate over all referenceIds and group events into one requestObject
Expand All @@ -17,20 +18,20 @@ function createRequestObjectForAllReferenceIds(groupedObjects) {
events.forEach((event) => {
const eventObject = {
timestamp: new Date(event.creationDate).getTime().toString(),
type: 'focus', // this has to be changed once API accepts our event types
type: event.eventType,
target: event.eventStatus,
id: event.eventId,
component: event.eventSource,
};

const eventCode = event.eventCode.toLowerCase();
const eventTypes = [
const eventCodeList = [
constants.eventCode.INFO,
constants.eventCode.ERROR,
constants.eventCode.LOG,
];

if (eventTypes.includes(eventCode)) {
if (eventCodeList.includes(eventCode)) {
if (!requestObject[eventCode]) {
requestObject[eventCode] = [];
}
Expand Down

0 comments on commit 32abaf0

Please sign in to comment.