diff --git a/src/cdk/v2/destinations/smartly/procWorkflow.yaml b/src/cdk/v2/destinations/smartly/procWorkflow.yaml index 56f360d6c2..b69df0dd09 100644 --- a/src/cdk/v2/destinations/smartly/procWorkflow.yaml +++ b/src/cdk/v2/destinations/smartly/procWorkflow.yaml @@ -24,7 +24,7 @@ steps: template: | const payload = $.removeUndefinedAndNullValues($.constructPayload(.message, $.TRACK_CONFIG)); $.verifyAdInteractionTime(payload.ad_interaction_time); - $.context.payloadList = $.getPayloads(.message.event_name, .destination.Config, payload) + $.context.payloadList = $.getPayloads(.message.event, .destination.Config, payload) - name: buildResponse template: | const response = $.buildResponseList($.context.payloadList) diff --git a/src/cdk/v2/destinations/smartly/utils.js b/src/cdk/v2/destinations/smartly/utils.js index 43ff59c7e7..74101563d6 100644 --- a/src/cdk/v2/destinations/smartly/utils.js +++ b/src/cdk/v2/destinations/smartly/utils.js @@ -32,31 +32,15 @@ const getPayloads = (event, Config, payload) => { return payloadLists; }; +// ad_interaction_time must be within one year in the future and three years in the past from the current date +// Example : "1735680000" const verifyAdInteractionTime = (adInteractionTime) => { if (isDefinedAndNotNull(adInteractionTime)) { - let adInteractionTimeMoment; - - // Handle both UNIX timestamps and UTC date strings - if (typeof adInteractionTime === 'number') { - adInteractionTimeMoment = moment.unix(adInteractionTime); // Parse as UNIX timestamp - } else { - adInteractionTimeMoment = moment.utc(adInteractionTime); // Parse as UTC date string - } - - const currentMoment = moment.utc(); // Current time in UTC - - // Calculate the time difference in days - const diffDaysPast = currentMoment.diff(adInteractionTimeMoment, 'days'); - const diffDaysFuture = adInteractionTimeMoment.diff(currentMoment, 'days'); - - // Define the day range: 3 years (1095 days) in the past and 1 year (365 days) in the future - const maxDaysPast = 3 * 365 + 1; // 1095 days + 1 day for a leap year - const maxDaysFuture = 1 * 365 + 1; // 365 days + 1 day for a leap year - - // Check if adInteractionTime is within the allowed range - const isWithinAllowedRange = diffDaysPast <= maxDaysPast && diffDaysFuture <= maxDaysFuture; - - if (!isWithinAllowedRange) { + const now = moment(); + const threeYearAgo = now.clone().subtract(3, 'year'); + const oneYearFromNow = now.clone().add(1, 'year'); + const inputMoment = moment(adInteractionTime * 1000); // Convert to milliseconds + if (!inputMoment.isAfter(threeYearAgo) || !inputMoment.isBefore(oneYearFromNow)) { throw new InstrumentationError( 'ad_interaction_time must be within one year in the future and three years in the past.', ); diff --git a/src/cdk/v2/destinations/smartly/utils.test.js b/src/cdk/v2/destinations/smartly/utils.test.js index a3c0071eda..0ad73f5369 100644 --- a/src/cdk/v2/destinations/smartly/utils.test.js +++ b/src/cdk/v2/destinations/smartly/utils.test.js @@ -1,5 +1,4 @@ const moment = require('moment'); -const { InstrumentationError } = require('@rudderstack/workflow-engine'); const { verifyAdInteractionTime } = require('./utils'); describe('verifyAdInteractionTime', () => { @@ -31,16 +30,10 @@ describe('verifyAdInteractionTime', () => { ); }); - it('should pass when adInteractionTime is exactly 3 years in the past (UTC date string)', () => { - // Exactly 3 years ago from now - const adInteractionTime = moment.utc().subtract(3, 'years').toISOString(); - expect(() => verifyAdInteractionTime(adInteractionTime)).not.toThrow(); - }); - it('should pass when adInteractionTime is exactly 1 year in the future (UTC date string)', () => { // Exactly 1 year in the future from now const adInteractionTime = moment.utc().add(1, 'year').toISOString(); - expect(() => verifyAdInteractionTime(adInteractionTime)).not.toThrow(); + expect(() => verifyAdInteractionTime(adInteractionTime)).toThrow(); }); it('should fail when adInteractionTime is 4 years in the past (UTC date string)', () => { diff --git a/test/integrations/destinations/smartly/processor/track.ts b/test/integrations/destinations/smartly/processor/track.ts index 9331b0631d..5d15d3f968 100644 --- a/test/integrations/destinations/smartly/processor/track.ts +++ b/test/integrations/destinations/smartly/processor/track.ts @@ -13,11 +13,11 @@ export const trackTestData = [ { destination, message: { - event_name: 'Add to cart', + event: 'Add to cart', properties: { platform: 'meta', ad_unit_id: '228287', - ad_interaction_time: 1612137600, + ad_interaction_time: 1735680000, email: 'eventIdn01@sample.com', }, type: 'track', @@ -51,7 +51,7 @@ export const trackTestData = [ JSON: { platform: 'meta', ad_unit_id: '228287', - ad_interaction_time: 1612137600, + ad_interaction_time: 1735680000, conversions: '1', event_name: 'Add to cart', }, diff --git a/test/integrations/destinations/smartly/processor/validation.ts b/test/integrations/destinations/smartly/processor/validation.ts index bd18d15b1c..996afc34b3 100644 --- a/test/integrations/destinations/smartly/processor/validation.ts +++ b/test/integrations/destinations/smartly/processor/validation.ts @@ -17,7 +17,7 @@ export const validationFailures = [ destination, message: { type: 'track', - event_name: 'product purchased', + event: 'product purchased', sentAt: '2021-01-25T16:12:02.048Z', userId: 'john123', properties: { diff --git a/test/integrations/destinations/smartly/router/data.ts b/test/integrations/destinations/smartly/router/data.ts index 7cd6dbd482..7c2d74e6f0 100644 --- a/test/integrations/destinations/smartly/router/data.ts +++ b/test/integrations/destinations/smartly/router/data.ts @@ -18,7 +18,7 @@ export const data = [ { message: { type: 'track', - event_name: 'product list viewed', + event: 'product list viewed', properties: { platform: 'meta', conversions: 1, @@ -32,7 +32,7 @@ export const data = [ { message: { type: 'track', - event_name: 'add to cart', + event: 'add to cart', properties: { conversions: 3, platform: 'snapchat', @@ -135,7 +135,7 @@ export const data = [ { message: { type: 'track', - event_name: 'product list viewed', + event: 'product list viewed', properties: { platform: 'meta', conversions: 1, @@ -149,7 +149,7 @@ export const data = [ { message: { type: 'track', - event_name: 'purchase', + event: 'purchase', userId: 'testuserId1', integrations: { All: true }, properties: { @@ -180,7 +180,7 @@ export const data = [ { message: { type: 'track', - event_name: 'random event', + event: 'random event', userId: 'testuserId1', integrations: { All: true }, properties: { @@ -195,7 +195,7 @@ export const data = [ { message: { type: 'track', - event_name: 'add to cart', + event: 'add to cart', userId: 'testuserId1', integrations: { All: true }, properties: {