Skip to content

Commit 56021e5

Browse files
committed
Add validation for new setting
1 parent 0429cac commit 56021e5

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/google-enhanced-conversions.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,61 @@ const conversionTrackingId = '_conversion_id_'
88
const conversionLabel = '_conversion_'
99

1010
describe('GoogleEnhancedConversions', () => {
11+
describe('testAuthentication', () => {
12+
it('should validate loginCustomerId format - valid format', async () => {
13+
await expect(
14+
testDestination.testAuthentication({
15+
conversionTrackingId,
16+
loginCustomerId: '123-456-7890'
17+
})
18+
).resolves.not.toThrow()
19+
})
20+
21+
it('should validate loginCustomerId format - valid format without dashes', async () => {
22+
await expect(
23+
testDestination.testAuthentication({
24+
conversionTrackingId,
25+
loginCustomerId: '1234567890'
26+
})
27+
).resolves.not.toThrow()
28+
})
29+
30+
it('should reject loginCustomerId with invalid format - too few digits', async () => {
31+
await expect(
32+
testDestination.testAuthentication({
33+
conversionTrackingId,
34+
loginCustomerId: '123-456-789'
35+
})
36+
).rejects.toThrow('Login Customer ID must be 10 digits in XXX-XXX-XXXX format')
37+
})
38+
39+
it('should reject loginCustomerId with invalid format - too many digits', async () => {
40+
await expect(
41+
testDestination.testAuthentication({
42+
conversionTrackingId,
43+
loginCustomerId: '123-456-78901'
44+
})
45+
).rejects.toThrow('Login Customer ID must be 10 digits in XXX-XXX-XXXX format')
46+
})
47+
48+
it('should reject loginCustomerId with invalid format - contains letters', async () => {
49+
await expect(
50+
testDestination.testAuthentication({
51+
conversionTrackingId,
52+
loginCustomerId: '123-456-789A'
53+
})
54+
).rejects.toThrow('Login Customer ID must be 10 digits in XXX-XXX-XXXX format')
55+
})
56+
57+
it('should allow empty/undefined loginCustomerId since it is optional', async () => {
58+
await expect(
59+
testDestination.testAuthentication({
60+
conversionTrackingId
61+
})
62+
).resolves.not.toThrow()
63+
})
64+
})
65+
1166
describe('extendRequest - login-customer-id header', () => {
1267
it('should include login-customer-id header when loginCustomerId is provided', async () => {
1368
const event = createTestEvent({

packages/destination-actions/src/destinations/google-enhanced-conversions/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,27 @@ const destination: AudienceDestinationDefinition<Settings> = {
5252
type: 'string'
5353
}
5454
},
55-
testAuthentication: async (_request) => {
55+
testAuthentication: async (_request, { settings }) => {
5656
/* NOTE: Commenting this out until we surface the OAuth login flow in the Actions configuration wizard
5757
const res = await request<UserInfoResponse>('https://www.googleapis.com/oauth2/v3/userinfo', {
5858
method: 'GET'
5959
})
6060
6161
return { name: res.data.name || res.data.email }
6262
*/
63+
64+
// Validate loginCustomerId format if provided
65+
if (settings.loginCustomerId) {
66+
const cleanedId = settings.loginCustomerId.replace(/-/g, '')
67+
if (!/^\d{10}$/.test(cleanedId)) {
68+
throw new IntegrationError(
69+
'Login Customer ID must be 10 digits in XXX-XXX-XXXX format',
70+
'INVALID_LOGIN_CUSTOMER_ID',
71+
400
72+
)
73+
}
74+
}
75+
6376
return true
6477
},
6578
refreshAccessToken: async (request, { auth }) => {

0 commit comments

Comments
 (0)