Skip to content

Commit

Permalink
fix: clevertap remove stringification of array object properties (#3048)
Browse files Browse the repository at this point in the history
* fix: remove ztringification for nested objects and arrays in profileData

* fix: remove ztringification for nested objects and arrays in event data for custom events

* chore: update test on category-unsubscribe

* fix: revert "remove ztringification for nested objects and arrays in event data for custom events" commit

This reverts commit 9157b28.

* fix: allow stringification for subscription properties only

---------

Co-authored-by: Sudip Paul <[email protected]>
  • Loading branch information
yashasvibajpai and ItsSudip authored Feb 23, 2024
1 parent c844aaf commit 69e43b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 7 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)
) {
finalPayload[key] = JSON.stringify(payload[key]);
} else {
finalPayload[key] = payload[key];
Expand Down
16 changes: 9 additions & 7 deletions test/integrations/destinations/clevertap/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const data = [
state: 'WB',
street: '',
},
'category-unsubscribe': { email: ['Marketing', 'Transactional'] },
},
integrations: {
All: true,
Expand Down Expand Up @@ -98,10 +99,11 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
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 @@ -242,8 +244,8 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
Expand Down Expand Up @@ -968,8 +970,8 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
Expand Down Expand Up @@ -1111,8 +1113,8 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
Expand Down Expand Up @@ -1692,8 +1694,8 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
address:
'{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}',
},
Expand Down Expand Up @@ -2077,8 +2079,8 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
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',
Expand Down Expand Up @@ -2230,8 +2232,8 @@ export const data = [
msgSms: true,
msgemail: true,
msgwhatsapp: false,
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
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',
Expand Down
4 changes: 2 additions & 2 deletions test/integrations/destinations/clevertap/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +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":""}',
custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}',
custom_tags: '["Test_User","Interested_User","DIY_Hobby"]',
},
objectId: 'anon_id',
},
Expand Down

0 comments on commit 69e43b6

Please sign in to comment.