Skip to content

Commit

Permalink
fix: fixing mismatch of schedule field value in clicksend destination…
Browse files Browse the repository at this point in the history
… due to different timezone
  • Loading branch information
manish339k committed Jan 10, 2025
1 parent 57fc4fe commit 7359fad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/cdk/v2/destinations/clicksend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ const deduceSchedule = (eventLevelSchedule, timestamp, destConfig) => {
if (isDefinedAndNotNull(eventLevelSchedule) && !Number.isNaN(eventLevelSchedule)) {
return eventLevelSchedule;
}
const { defaultCampaignScheduleUnit = 'minute', defaultCampaignSchedule = 0 } = destConfig;
const { defaultCampaignScheduleUnit = 'minute', defaultCampaignSchedule = '0' } = destConfig;
const date = new Date(timestamp);
let defaultCampaignScheduleInt = parseInt(defaultCampaignSchedule, 10);
if (Number.isNaN(defaultCampaignScheduleInt)) {
defaultCampaignScheduleInt = 0;
}

if (defaultCampaignScheduleUnit === 'day') {
date.setDate(date.getDate() + defaultCampaignSchedule);
date.setDate(date.getDate() + defaultCampaignScheduleInt);
} else if (defaultCampaignScheduleUnit === 'minute') {
date.setMinutes(date.getMinutes() + defaultCampaignSchedule);
date.setMinutes(date.getMinutes() + defaultCampaignScheduleInt);
} else {
throw new Error("Invalid delta unit. Use 'day' or 'minute'.");
}
Expand Down
21 changes: 16 additions & 5 deletions src/cdk/v2/destinations/clicksend/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('deduceSchedule', () => {
it('should return eventLevelSchedule when it is defined, not null, and not empty', () => {
const eventLevelSchedule = 1234567890;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = { defaultCampaignScheduleUnit: 'minute', defaultCampaignSchedule: 5 };
const destConfig = { defaultCampaignScheduleUnit: 'minute', defaultCampaignSchedule: '5' };

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);

Expand All @@ -57,7 +57,7 @@ describe('deduceSchedule', () => {
it('should throw error when defaultCampaignScheduleUnit is invalid', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = { defaultCampaignScheduleUnit: 'hour', defaultCampaignSchedule: 5 };
const destConfig = { defaultCampaignScheduleUnit: 'hour', defaultCampaignSchedule: '5' };

expect(() => {
deduceSchedule(eventLevelSchedule, timestamp, destConfig);
Expand All @@ -68,7 +68,7 @@ describe('deduceSchedule', () => {
it('should calculate future timestamp correctly when defaultCampaignScheduleUnit is minute', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = { defaultCampaignScheduleUnit: 'minute', defaultCampaignSchedule: 5 };
const destConfig = { defaultCampaignScheduleUnit: 'minute', defaultCampaignSchedule: '5' };

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);

Expand All @@ -81,7 +81,7 @@ describe('deduceSchedule', () => {
it('should calculate future timestamp correctly when defaultCampaignScheduleUnit is day', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = { defaultCampaignScheduleUnit: 'day', defaultCampaignSchedule: 1 };
const destConfig = { defaultCampaignScheduleUnit: 'day', defaultCampaignSchedule: '1' };

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);

Expand All @@ -90,11 +90,22 @@ describe('deduceSchedule', () => {
expect(result).toBe(expectedTimestamp);
});

it('should calculate timestamp when defaultCampaignSchedule in some invalid string', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = { defaultCampaignScheduleUnit: 'day', defaultCampaignSchedule: 'inValid' };

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);
const expectedTimestamp = new Date('2023-10-01T00:00:00Z').getTime() / 1000;

expect(result).toBe(expectedTimestamp);
});

// returns UNIX timestamp in seconds
it('should return UNIX timestamp in seconds', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = { defaultCampaignScheduleUnit: 'minute', defaultCampaignSchedule: 5 };
const destConfig = { defaultCampaignScheduleUnit: 'minute', defaultCampaignSchedule: '5' };

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);

Expand Down
4 changes: 2 additions & 2 deletions test/integrations/destinations/clicksend/processor/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const track = [
body: 'abcd',
from: 'abc@gmail.com',
name: 'new campaign',
schedule: 1631201576,
schedule: 1611761576,
},
userId: '',
}),
Expand Down Expand Up @@ -227,7 +227,7 @@ export const track = [
from: 'abc@gmail.com',
from_email: 'dummy@gmail.com',
custom_string: 'test string',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand Down
12 changes: 6 additions & 6 deletions test/integrations/destinations/clicksend/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const data = [
from: 'abc@gmail.com',
list_id: 123345,
name: 'new campaign',
schedule: 1631201576,
schedule: 1611761576,
},
JSON_ARRAY: {},
XML: {},
Expand Down Expand Up @@ -160,7 +160,7 @@ export const data = [
email: 'abc@gmail.com',
from: 'abc@gmail.com',
from_email: 'dummy@gmail.com',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand Down Expand Up @@ -373,7 +373,7 @@ export const data = [
from: 'abc@gmail.com',
list_id: 123345,
name: 'new campaign',
schedule: 1631201576,
schedule: 1611761576,
},
JSON_ARRAY: {},
XML: {},
Expand Down Expand Up @@ -412,7 +412,7 @@ export const data = [
email: 'abc@gmail.com',
from: 'abc@gmail.com',
from_email: 'dummy@gmail.com',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand All @@ -422,7 +422,7 @@ export const data = [
email: 'abc@gmail.com',
from: 'abc@gmail.com',
from_email: 'dummy@gmail.com',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand All @@ -432,7 +432,7 @@ export const data = [
email: 'abc@gmail.com',
from: 'abc@gmail.com',
from_email: 'dummy@gmail.com',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand Down

0 comments on commit 7359fad

Please sign in to comment.