Skip to content

Commit

Permalink
Additional unit tests to verify double-hashing prevention in Google A…
Browse files Browse the repository at this point in the history
…ds Enhanced Conversions. (#1389)
  • Loading branch information
seg-leonelsanches authored Jul 11, 2023
1 parent d246bb3 commit c82a96b
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ describe('GoogleEnhancedConversions', () => {
settings: {}
})
fail('the test should have thrown an error')
} catch (e) {
} catch (e: any) {
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.')
}
})

it('sends an event with default mappings', async () => {
const event = createTestEvent({
timestamp,
Expand Down Expand Up @@ -268,6 +269,7 @@ describe('GoogleEnhancedConversions', () => {
expect(responses.length).toBe(1)
expect(responses[0].status).toBe(201)
})

it('fails if customerId not set', async () => {
const event = createTestEvent({
timestamp,
Expand Down Expand Up @@ -301,7 +303,7 @@ describe('GoogleEnhancedConversions', () => {
settings: {}
})
fail('the test should have thrown an error')
} catch (e) {
} catch (e: any) {
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.')
}
})
Expand Down Expand Up @@ -349,5 +351,86 @@ describe('GoogleEnhancedConversions', () => {
expect(responses.length).toBe(1)
expect(responses[0].status).toBe(201)
})

it('hashed email', async () => {
const event = createTestEvent({
timestamp,
event: 'Test Event',
properties: {
gclid: '54321',
email: '87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674', //'[email protected]',
orderId: '1234',
total: '200',
currency: 'USD',
products: [
{
product_id: '1234',
quantity: 3,
price: 10.99
}
]
}
})

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}:uploadClickConversions`)
.post('')
.reply(201, { results: [{}] })

const responses = await testDestination.testAction('uploadClickConversion', {
event,
mapping: { conversion_action: '12345' },
useDefaultMappings: true,
settings: {
customerId
}
})

expect(responses[0].options.body).toMatchInlineSnapshot(
`"{\\"conversions\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"orderId\\":\\"1234\\",\\"conversionValue\\":200,\\"currencyCode\\":\\"USD\\",\\"cartData\\":{\\"items\\":[{\\"productId\\":\\"1234\\",\\"quantity\\":3,\\"unitPrice\\":10.99}]},\\"userIdentifiers\\":[{\\"hashedEmail\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"}]}],\\"partialFailure\\":true}"`
)

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(201)
})

it('fails if email is invalid', async () => {
const event = createTestEvent({
timestamp,
event: 'Test Event',
properties: {
gclid: '54321',
email: 'anything',
orderId: '1234',
total: '200',
currency: 'USD',
products: [
{
product_id: '1234',
quantity: 3,
price: 10.99
}
]
}
})

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}:uploadClickConversions`)
.post('')
.reply(201, {})

try {
await testDestination.testAction('uploadClickConversion', {
event,
features: { 'google-enhanced-v12': true },
mapping: { conversion_action: '12345' },
useDefaultMappings: true,
settings: {
customerId
}
})
fail('the test should have thrown an error')
} catch (e: any) {
expect(e.message).toBe("Email provided doesn't seem to be in a valid format.")
}
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('GoogleEnhancedConversions', () => {
settings: {}
})
fail('the test should have thrown an error')
} catch (e) {
} catch (e: any) {
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.')
}
})
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('GoogleEnhancedConversions', () => {
settings: {}
})
fail('the test should have thrown an error')
} catch (e) {
} catch (e: any) {
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.')
}
})
Expand Down Expand Up @@ -350,5 +350,94 @@ describe('GoogleEnhancedConversions', () => {
expect(responses.length).toBe(1)
expect(responses[0].status).toBe(201)
})

it('hashed email', async () => {
const event = createTestEvent({
timestamp,
event: 'Test Event',
properties: {
gclid: '54321',
email: '87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674',
orderId: '1234',
phone: '1234567890',
firstName: 'Jane',
lastName: 'Doe',
currency: 'USD',
value: '123',
address: {
street: '123 Street SW',
city: 'San Diego',
state: 'CA',
postalCode: '982004'
}
}
})

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}:uploadConversionAdjustments`)
.post('')
.reply(201, { results: [{}] })

const responses = await testDestination.testAction('uploadConversionAdjustment', {
event,
mapping: {
gclid: {
'@path': '$.properties.gclid'
},
conversion_action: '12345',
adjustment_type: 'ENHANCEMENT',
conversion_timestamp: {
'@path': '$.timestamp'
},
restatement_value: {
'@path': '$.properties.value'
},
restatement_currency_code: {
'@path': '$.properties.currency'
}
},
useDefaultMappings: true,
settings: {
customerId
}
})

expect(responses[0].options.body).toMatchInlineSnapshot(
`"{\\"conversionAdjustments\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"adjustmentType\\":\\"ENHANCEMENT\\",\\"adjustmentDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"orderId\\":\\"1234\\",\\"gclidDateTimePair\\":{\\"gclid\\":\\"54321\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\"},\\"userIdentifiers\\":[{\\"hashedEmail\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"},{\\"hashedPhoneNumber\\":\\"c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646\\"},{\\"addressInfo\\":{\\"hashedFirstName\\":\\"4f23798d92708359b734a18172c9c864f1d48044a754115a0d4b843bca3a5332\\",\\"hashedLastName\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\"}}],\\"userAgent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"restatementValue\\":{\\"adjustedValue\\":123,\\"currencyCode\\":\\"USD\\"}}],\\"partialFailure\\":true}"`
)

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(201)
})

it('fails if email is invalid', async () => {
const event = createTestEvent({
timestamp,
event: 'Test Event',
properties: {
gclid: '54321',
email: 'anything',
orderId: '1234'
}
})

nock(`https://googleads.googleapis.com/${API_VERSION}/customers/${customerId}:uploadConversionAdjustments`)
.post('')
.reply(201, { results: [{}] })

try {
await testDestination.testAction('uploadConversionAdjustment', {
event,
features: { 'google-enhanced-v12': true },
mapping: { gclid: '123a', conversion_action: '12345', adjustment_type: 'ENHANCEMENT' },
useDefaultMappings: true,
settings: {
customerId
}
})
fail('the test should have thrown an error')
} catch (e: any) {
expect(e.message).toBe("Email provided doesn't seem to be in a valid format.")
}
})
})
})

0 comments on commit c82a96b

Please sign in to comment.