Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STRATCONN-5449] Update GEC - userList action to common hashed function #2710

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -418,18 +418,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 @@ -472,7 +460,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
Loading