-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional unit tests to verify double-hashing prevention in Google A…
…ds Enhanced Conversions. (#1389)
- Loading branch information
1 parent
d246bb3
commit c82a96b
Showing
2 changed files
with
176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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.') | ||
} | ||
}) | ||
|
@@ -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.") | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters