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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krishna2020 Should we throw error here? We should throw error ideally. I tested the API locally, We are getting successful response for any value for schedule. As per the destination doc . It should be in Unix format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manish339k Can this be a random value? What is the UI here? Does the frontend limit the user to add only a number or any string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwing error may cause problem for the existing destinations, if they have added some random value there.

Copy link
Contributor Author

@manish339k manish339k Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinayteki95 in frontend, ui does not restrict from entering any random value. it can be string.

Copy link
Contributor

@vinayteki95 vinayteki95 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manish339k In that case, let's not throw an error but before defaulting to 0 let try to clean up the string.
Cases like "2 " or " 10" (spaces around the value) can still be legitimate but a mistake from the user's side. Do cater for any other scenarios like this.


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
Loading