Skip to content

Commit

Permalink
[TikTok Audiences] fix normalization of emails (#1387)
Browse files Browse the repository at this point in the history
* TikTok fix normalization to not remove all '.'

* fix test cases

* add test
  • Loading branch information
maryamsharif authored Jul 11, 2023
1 parent 53b2722 commit 49f4f53
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const updateUsersRequestBody = {
batch_data: [
[
{
id: '44d206f60172cd898051a9fb2174750aee1eca00f6f63f12801b90644321e342',
id: '584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777',
audience_ids: ['1234345']
},
{
Expand Down Expand Up @@ -68,6 +68,40 @@ describe('TiktokAudiences.addUser', () => {
).resolves.not.toThrowError()
})

it('should normalize and hash emails correctly', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`)
.post(/.*/, {
advertiser_ids: ['123'],
action: 'add',
id_schema: ['EMAIL_SHA256'],
batch_data: [
[
{
id: '584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777',
audience_ids: ['1234345']
}
]
]
})
.reply(200)
const responses = await testDestination.testAction('addUser', {
event,
settings: {
advertiser_ids: ['123']
},
useDefaultMappings: true,
auth,
mapping: {
selected_advertiser_id: '123',
audience_id: '1234345',
send_advertising_id: false
}
})
expect(responses[0].options.body).toMatchInlineSnapshot(
`"{\\"advertiser_ids\\":[\\"123\\"],\\"action\\":\\"add\\",\\"id_schema\\":[\\"EMAIL_SHA256\\"],\\"batch_data\\":[[{\\"id\\":\\"584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777\\",\\"audience_ids\\":[\\"1234345\\"]}]]}"`
)
})

it('should fail if an audience id is invalid', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export function extractUsers(payloads: GenericPayload[]): {}[][] {
if (payload.send_email === true) {
let email_id = {}
if (payload.email) {
payload.email = payload.email.replace(/\+.*@/, '@').replace(/\./g, '').toLowerCase()
payload.email = payload.email
.replace(/\+.*@/, '@')
.replace(/\.(?=.*@)/g, '')
.toLowerCase()
email_id = {
id: createHash('sha256').update(payload.email).digest('hex'),
audience_ids: [payload.audience_id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const updateUsersRequestBody = {
batch_data: [
[
{
id: '44d206f60172cd898051a9fb2174750aee1eca00f6f63f12801b90644321e342',
id: '584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777',
audience_ids: ['1234345']
},
{
Expand Down

0 comments on commit 49f4f53

Please sign in to comment.