Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixing mismatch of schedule field value in clicksend destination #3975

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
manish339k marked this conversation as resolved.
Show resolved Hide resolved

if (defaultCampaignScheduleUnit === 'day') {
date.setDate(date.getDate() + defaultCampaignSchedule);
date.setUTCDate(date.getUTCDate() + defaultCampaignScheduleInt);
} else if (defaultCampaignScheduleUnit === 'minute') {
date.setMinutes(date.getMinutes() + defaultCampaignSchedule);
date.setUTCMinutes(date.getUTCMinutes() + defaultCampaignScheduleInt);
} else {
throw new Error("Invalid delta unit. Use 'day' or 'minute'.");
}
Expand Down
35 changes: 30 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,36 @@ 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);
});

it('should calculate timestamp when defaultCampaignSchedule has trailing invalid text and/or leading space', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = {
defaultCampaignScheduleUnit: 'minute',
defaultCampaignSchedule: ' 5Invalid.String ',
};

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);
const expectedTimestamp = new Date('2023-10-01T00:05: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: '[email protected]',
name: 'new campaign',
schedule: 1631201576,
schedule: 1611761576,
},
userId: '',
}),
Expand Down Expand Up @@ -227,7 +227,7 @@ export const track = [
from: '[email protected]',
from_email: '[email protected]',
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: '[email protected]',
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: '[email protected]',
from: '[email protected]',
from_email: '[email protected]',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand Down Expand Up @@ -373,7 +373,7 @@ export const data = [
from: '[email protected]',
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: '[email protected]',
from: '[email protected]',
from_email: '[email protected]',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand All @@ -422,7 +422,7 @@ export const data = [
email: '[email protected]',
from: '[email protected]',
from_email: '[email protected]',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand All @@ -432,7 +432,7 @@ export const data = [
email: '[email protected]',
from: '[email protected]',
from_email: '[email protected]',
schedule: 1631201576,
schedule: 1611761576,
source: 'php',
to: '+9182XXXX068',
},
Expand Down
Loading