From c82a96bcfe1609ac1083e6543deedc29f5aebf86 Mon Sep 17 00:00:00 2001 From: Leonel Sanches <113376080+seg-leonelsanches@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:43:04 -0700 Subject: [PATCH] Additional unit tests to verify double-hashing prevention in Google Ads Enhanced Conversions. (#1389) --- .../__tests__/uploadClickConversion.test.ts | 87 ++++++++++++++++- .../uploadConversionAdjustment.test.ts | 93 ++++++++++++++++++- 2 files changed, 176 insertions(+), 4 deletions(-) diff --git a/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadClickConversion.test.ts b/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadClickConversion.test.ts index ba0cb045e8..2376bdd374 100644 --- a/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadClickConversion.test.ts +++ b/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadClickConversion.test.ts @@ -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', //'test@gmail.com', + 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.") + } + }) }) }) diff --git a/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadConversionAdjustment.test.ts b/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadConversionAdjustment.test.ts index 3af9320137..a2b3d867e1 100644 --- a/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadConversionAdjustment.test.ts +++ b/packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadConversionAdjustment.test.ts @@ -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.') } }) @@ -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.') } }) @@ -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.") + } + }) }) })