Skip to content

Commit

Permalink
fix: allow stringification for subscription properties only
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Feb 7, 2024
1 parent ff39dac commit f9b4013
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 74 deletions.
10 changes: 8 additions & 2 deletions src/v0/destinations/clevertap/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@ const responseWrapper = (payload, destination) => {
}
*
}
* This function stringify the payload attributes if it's an array or objects.
* This function stringify the payload attributes if it's an array or objects. The keys that are not stringified are present in the `stringifyExcludeList` array.
* @param {*} payload
* @returns
* return the final payload after converting to the relevant data-types.
*/
const convertObjectAndArrayToString = (payload, event) => {
const finalPayload = {};
const stringifyExcludeList = ['category-unsubscribe', 'category-resubscribe'];
if (payload) {
Object.keys(payload).forEach((key) => {
if (payload[key] && (Array.isArray(payload[key]) || typeof payload[key] === 'object')) {
if (
payload[key] &&
(Array.isArray(payload[key]) || typeof payload[key] === 'object') &&
!stringifyExcludeList.includes(key)

Check warning on line 99 in src/v0/destinations/clevertap/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/clevertap/transform.js#L99

Added line #L99 was not covered by tests
) {
finalPayload[key] = JSON.stringify(payload[key]);
} else {
finalPayload[key] = payload[key];
Expand Down Expand Up @@ -225,6 +230,7 @@ const getClevertapProfile = (message, category) => {
['traits', 'context.traits'],
CLEVERTAP_DEFAULT_EXCLUSION,
);
profile = convertObjectAndArrayToString(profile);

// Add additional properties being passed inside overrideFields in traits or contextual traits
// to be added to the profile object, to be sent into Clevertap profileData
Expand Down
91 changes: 28 additions & 63 deletions test/integrations/destinations/clevertap/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
'category-unsubscribe': { email: ['Marketing', 'Transactional'] },
},
identity: 'anon_id',
Expand Down Expand Up @@ -249,15 +244,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
identity: 'anon_id',
},
Expand Down Expand Up @@ -980,15 +970,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
identity: 'anon_id',
},
Expand Down Expand Up @@ -1128,15 +1113,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
identity: 'anon_id',
},
Expand Down Expand Up @@ -1714,15 +1694,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
ts: 1615377562,
identity: 'anon_id',
Expand Down Expand Up @@ -2104,15 +2079,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
first_name: 'John',
last_name: 'Doe',
},
Expand Down Expand Up @@ -2262,15 +2232,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
first_name: 'John',
last_name: 'Doe',
},
Expand Down
13 changes: 4 additions & 9 deletions test/integrations/destinations/clevertap/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,10 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'],
custom_mappings: { Office: 'Trastkiv', Country: 'Russia' },
address: {
city: 'kolkata',
country: 'India',
postalCode: 789223,
state: 'WB',
street: '',
},
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
},
objectId: 'anon_id',
},
Expand Down

0 comments on commit f9b4013

Please sign in to comment.