Skip to content

Commit

Permalink
feat: adding component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jun 20, 2024
1 parent 178aeba commit 2ba43f4
Show file tree
Hide file tree
Showing 9 changed files with 1,183 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/cdk/v2/destinations/clicksend/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ steps:
from : $.getDestinationExternalID(^.message,'CLICKSEND_SENDER_EMAIL') || ^.destination.Config.defaultSenderEmail,
schedule : $.deduceSchedule(.properties.schedule,{{{{$.getGenericPaths("timestamp")}}}}, ^.destination.Config)
});
console.log(JSON.stringify(.destination.Config));
console.log(.destination.Config.defaultSenderEmail);
$.assert(!Number.isNaN(sendCampaignPayload.list_id), "list_id must be an integer");
$.validateTrackSMSCampaignPayload(sendCampaignPayload);
$.context.payload = $.removeUndefinedAndNullValues(sendCampaignPayload);
Expand All @@ -78,7 +76,7 @@ steps:
to: {{{{$.getGenericPaths("phone")}}}},
body: .properties.body,
source: .properties.source || ^.destination.Config.defaultSource,
schedule: $.deduceSchedule(.properties.schedule, ^.destination.Config),
schedule: $.deduceSchedule(.properties.schedule, {{{{$.getGenericPaths("timestamp")}}}}, ^.destination.Config),
custom_string: .properties.custom_string,
country: {{{{$.getGenericPaths("country")}}}},
from_email: .properties.from_email
Expand Down
13 changes: 3 additions & 10 deletions src/cdk/v2/destinations/clicksend/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const {
isDefinedAndNotNullAndNotEmpty,
InstrumentationError,
} = require('@rudderstack/integrations-lib');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const lodash = require('lodash');
const { BatchUtils } = require('@rudderstack/workflow-engine');
const { SMS_SEND_ENDPOINT, MAX_BATCH_SIZE, COMMON_CONTACT_DOMAIN } = require('./config');
const { isDefinedAndNotNullAndNotEmpty } = require('../../../../v0/util');

const getEndIdentifyPoint = (contactId, contactListId) => {
if (isDefinedAndNotNullAndNotEmpty(contactId) && isDefinedAndNotNullAndNotEmpty(contactListId)) {
Expand All @@ -28,12 +26,7 @@ const validateIdentifyPayload = (payload) => {
};

const validateTrackSMSCampaignPayload = (payload) => {
if (
!isDefinedAndNotNullAndNotEmpty(payload.body) &&
!isDefinedAndNotNullAndNotEmpty(payload.name) &&
!isDefinedAndNotNullAndNotEmpty(payload.list_id) &&
!isDefinedAndNotNullAndNotEmpty(payload.from)
) {
if (!(payload.body && payload.name && payload.list_id && payload.from)) {
throw new InstrumentationError(
'All of contact list Id, name, body and from are required to trigger an sms campaign',
);
Expand Down
38 changes: 38 additions & 0 deletions src/cdk/v2/destinations/clicksend/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { validateTrackSMSCampaignPayload } = require('./utils');

describe('validateTrackSMSCampaignPayload', () => {
// payload with all required fields defined and non-empty does not throw an error
it('should not throw an error when all required fields are defined and non-empty', () => {
const payload = {
body: 'Test message',
name: 'Test Campaign',
list_id: '12345',
from: 'TestSender',
};
expect(() => validateTrackSMSCampaignPayload(payload)).not.toThrow();
});

// payload with body field missing throws an error
it('should throw an error when body field is missing', () => {
const payload = {
name: 'Test Campaign',
list_id: '12345',
from: 'TestSender',
};
expect(() => validateTrackSMSCampaignPayload(payload)).toThrow(
'All of contact list Id, name, body and from are required to trigger an sms campaign',
);
});

it('should throw an error when from field is empty string', () => {
const payload = {
name: 'Test Campaign',
list_id: '12345',
from: '',
body: 'Test message',
};
expect(() => validateTrackSMSCampaignPayload(payload)).toThrow(
'All of contact list Id, name, body and from are required to trigger an sms campaign',
);
});
});
103 changes: 103 additions & 0 deletions test/integrations/destinations/clicksend/commonConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
export const destination = {
ID: 'random_id',
Name: 'clicksend',
DestinationDefinition: {
Config: {
cdkV2Enabled: true,
},
},
Config: {
clicksendUsername: 'dummy',
clicksendPassword: 'dummy',
defaultCampaignScheduleUnit: 'day',
defaultCampaignSchedule: '2',
defaultSource: 'php',
defaultSenderEmail: '[email protected]',
defaultSenderPhoneNumber: '+919XXXXXXXX8',
oneTrustCookieCategories: [
{
oneTrustCookieCategory: 'Marketing',
},
],
},
};

export const metadata = {
destinationId: 'dummyDestId',
};
export const commonProperties = {
name: 'new campaign',
body: 'abcd',
from: '[email protected]',
from_email: '[email protected]',
custom_string: 'test string',
};
export const traitsWithIdentifiers = {
firstName: 'John',
lastName: 'Doe',
phone: '+9182XXXX068',
email: '[email protected]',
address: { city: 'New York', country: 'USA', pinCode: '123456' },
};
export const traitsWithoutIdenfiers = {
firstName: 'John',
lastName: 'Doe',
address: { city: 'New York', country: 'USA', pinCode: '123456' },
};
export const contextWithoutScheduleAndWithContactId = {
externalId: [{ type: 'CLICKSEND_CONTACT_LIST_ID', id: '123345' }],
traitsWithoutIdenfiers,
};
export const commonInput = {
anonymousId: 'anon_123',
messageId: 'dummy_msg_id',
contextWithoutScheduleAndWithContactId,
channel: 'web',
integrations: {
All: true,
},
originalTimestamp: '2021-01-25T15:32:56.409Z',
};

export const commonOutput = {
anonymousId: 'anon_123',
messageId: 'dummy_msg_id',
contextWithoutScheduleAndWithContactId,
channel: 'web',
originalTimestamp: '2021-01-25T15:32:56.409Z',
};

export const SMS_SEND_ENDPOINT = 'https://rest.clicksend.com/v3/sms/send';
export const SMS_CAMPAIGN_ENDPOINT = 'https://rest.clicksend.com/v3/sms-campaigns/send';
export const COMMON_CONTACT_DOMAIN = 'https://rest.clicksend.com/v3/lists';
export const routerInstrumentationErrorStatTags = {
destType: 'CLICKSEND',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'router',
implementation: 'cdkV2',
module: 'destination',
};
export const commonIdentifyOutput = {
address_line_1: '{"city":"New York","country":"USA","pinCode":"123456"}',
address_line_2: '{"city":"New York","country":"USA","pinCode":"123456"}',
city: 'New York',
email: '[email protected]',
first_name: 'John',
last_name: 'Doe',
phone_number: '+9182XXXX068',
};
export const processInstrumentationErrorStatTags = {
destType: 'CLICKSEND',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'processor',
implementation: 'cdkV2',
module: 'destination',
destinationId: 'dummyDestId',
};

export const commonHeader = {
Authorization: 'Basic ZHVtbXk6ZHVtbXk=',
'Content-Type': 'application/json',
};
3 changes: 3 additions & 0 deletions test/integrations/destinations/clicksend/processor/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { track } from './track';
import { identify } from './identify';
export const data = [...identify, ...track];
Loading

0 comments on commit 2ba43f4

Please sign in to comment.