Skip to content

Commit

Permalink
update userList action to common hashed function (#2710)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvadera12 authored Feb 4, 2025
1 parent 44dbd6c commit 25682fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTestIntegration, DynamicFieldResponse } from '@segment/actions-core'
import { Features } from '@segment/actions-core/mapping-kit'
import nock from 'nock'
import { CANARY_API_VERSION, formatToE164 } from '../functions'
import { CANARY_API_VERSION, formatToE164, commonHashedEmailValidation } from '../functions'
import destination from '../index'

const testDestination = createTestIntegration(destination)
Expand Down Expand Up @@ -142,7 +142,20 @@ describe('.getConversionActionId', () => {
})
})

describe.only('phone number formatting', () => {
describe('email formatting', () => {
it('should format a non-hashed value', async () => {
expect(commonHashedEmailValidation('[email protected]')).toEqual(
'87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674'
)
})
it('should return hashed value as is', async () => {
expect(commonHashedEmailValidation('87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674')).toEqual(
'87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674'
)
})
})

describe('phone number formatting', () => {
it('should format a US phone number', async () => {
expect(formatToE164('16195551000', '+1')).toEqual('+16195551000')
expect(formatToE164('6195551000', '+1')).toEqual('+16195551000')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,6 @@ export async function getGoogleAudience(
return response.data as UserListResponse
}

const formatEmail = (email: string): string => {
const googleDomain = new RegExp('^(gmail|googlemail).s*', 'g')
let normalizedEmail = email.toLowerCase().trim()
const emailParts = normalizedEmail.split('@')
if (emailParts.length > 1 && emailParts[1].match(googleDomain)) {
emailParts[0] = emailParts[0].replace('.', '')
normalizedEmail = `${emailParts[0]}@${emailParts[1]}`
}

return sha256SmartHash(normalizedEmail)
}

// Standardize phone number to E.164 format, This format represents a phone number as a number up to fifteen digits
// in length starting with a + sign, for example, +12125650000 or +442070313000.
// exported for unit testing
Expand Down Expand Up @@ -470,7 +458,7 @@ const extractUserIdentifiers = (payloads: UserListPayload[], idType: string, syn
const identifiers = []
if (payload.email) {
identifiers.push({
hashedEmail: formatEmail(payload.email)
hashedEmail: commonHashedEmailValidation(payload.email)
})
}
if (payload.phone) {
Expand Down

0 comments on commit 25682fd

Please sign in to comment.