Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -48,23 +48,23 @@ describe('Amazon Conversions API Destination', () => {

// Check preset configurations
expect(addToCartPreset?.partnerAction).toBe('trackConversion')
expect(addToCartPreset?.mapping?.eventType).toBe('ADD_TO_SHOPPING_CART')
expect(addToCartPreset?.mapping?.conversionType).toBe('ADD_TO_SHOPPING_CART')
expect((addToCartPreset as any)?.subscribe).toBe('type = "track" AND event = "Product Added"')

expect(pageViewPreset?.partnerAction).toBe('trackConversion')
expect(pageViewPreset?.mapping?.eventType).toBe('PAGE_VIEW')
expect(pageViewPreset?.mapping?.conversionType).toBe('PAGE_VIEW')
expect((pageViewPreset as any)?.subscribe).toBe('type = "page"')

expect(signUpPreset?.partnerAction).toBe('trackConversion')
expect(signUpPreset?.mapping?.eventType).toBe('SIGN_UP')
expect(signUpPreset?.mapping?.conversionType).toBe('SIGN_UP')
expect((signUpPreset as any)?.subscribe).toBe('type = "track" AND event = "Signed Up"')
})

it('should have presets for all supported event types', () => {
const presets = (Destination as DestinationDefinition<any>).presets || []

// Get all event types from the presets
const presetEventTypes = presets.map(p => p.mapping?.eventType)
const presetEventTypes = presets.map(p => p.mapping?.conversionType)

// Check that all expected Amazon event types are covered
expect(presetEventTypes).toContain('ADD_TO_SHOPPING_CART')
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Amazon Conversions API Destination', () => {
}

expect(preset).toBeDefined()
expect(preset?.mapping?.eventType).toBe(amazonEvent)
expect(preset?.mapping?.conversionType).toBe(amazonEvent)
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const destination: DestinationDefinition<Settings> = {
return {
headers: {
authorization: `Bearer ${auth?.accessToken}`,
'Amazon-Advertising-API-ClientID': process.env.ACTIONS_AMAZON_CONVERSIONS_API_CLIENT_ID || ''
'Amazon-Ads-ClientId': process.env.ACTIONS_AMAZON_CONVERSIONS_API_CLIENT_ID || ''
}
}
},
Expand All @@ -68,7 +68,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'ADD_TO_SHOPPING_CART'
conversionType: 'ADD_TO_SHOPPING_CART'
},
type: 'automatic'
},
Expand All @@ -78,7 +78,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'APPLICATION'
conversionType: 'APPLICATION'
},
type: 'automatic'
},
Expand All @@ -88,7 +88,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'CHECKOUT'
conversionType: 'CHECKOUT'
},
type: 'automatic'
},
Expand All @@ -98,7 +98,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'CONTACT'
conversionType: 'CONTACT'
},
type: 'automatic'
},
Expand All @@ -108,7 +108,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'LEAD'
conversionType: 'LEAD'
},
type: 'automatic'
},
Expand All @@ -118,7 +118,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'OFF_AMAZON_PURCHASES'
conversionType: 'OFF_AMAZON_PURCHASES'
},
type: 'automatic'
},
Expand All @@ -128,7 +128,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'MOBILE_APP_FIRST_START'
conversionType: 'MOBILE_APP_FIRST_START'
},
type: 'automatic'
},
Expand All @@ -138,7 +138,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'PAGE_VIEW'
conversionType: 'PAGE_VIEW'
},
type: 'automatic'
},
Expand All @@ -148,7 +148,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'SEARCH'
conversionType: 'SEARCH'
},
type: 'automatic'
},
Expand All @@ -158,7 +158,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'SIGN_UP'
conversionType: 'SIGN_UP'
},
type: 'automatic'
},
Expand All @@ -168,7 +168,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'SUBSCRIBE'
conversionType: 'SUBSCRIBE'
},
type: 'automatic'
},
Expand All @@ -178,7 +178,7 @@ const destination: DestinationDefinition<Settings> = {
partnerAction: 'trackConversion',
mapping: {
...defaultValues(trackConversion.fields),
eventType: 'OTHER'
conversionType: 'OTHER'
},
type: 'automatic'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,59 @@ describe('trackConversion fields', () => {
it('should have all required fields defined', () => {
// Check that required fields are present
expect(fields.name).toBeDefined()
expect(fields.eventType).toBeDefined()
expect(fields.eventActionSource).toBeDefined()
expect(fields.conversionType).toBeDefined()
expect(fields.eventSource).toBeDefined()
expect(fields.countryCode).toBeDefined()
expect(fields.timestamp).toBeDefined()
expect(fields.eventTime).toBeDefined()
expect(fields.matchKeys).toBeDefined()
expect(fields.enable_batching).toBeDefined()
})

it('should mark required fields as required', () => {
expect(fields.name.required).toBe(true)
expect(fields.eventType.required).toBe(true)
expect(fields.eventActionSource.required).toBe(true)
expect(fields.conversionType.required).toBe(true)
expect(fields.eventSource.required).toBe(true)
expect(fields.countryCode.required).toBe(true)
expect(fields.timestamp.required).toBe(true)
expect(fields.eventTime.required).toBe(true)
expect(fields.matchKeys.required).toBe(true)
expect(fields.enable_batching.required).toBe(true)
})

it('should have correct default values', () => {
expect(fields.name.default).toEqual({ '@path': '$.event' })
expect(fields.timestamp.default).toEqual({ '@path': '$.timestamp' })
expect(fields.eventTime.default).toEqual({ '@path': '$.timestamp' })
expect(fields.enable_batching.default).toBe(true)
})

it('should have proper types for all fields', () => {
expect(fields.name.type).toBe('string')
expect(fields.eventType.type).toBe('string')
expect(fields.eventActionSource.type).toBe('string')
expect(fields.conversionType.type).toBe('string')
expect(fields.eventSource.type).toBe('string')
expect(fields.countryCode.type).toBe('string')
expect(fields.timestamp.type).toBe('string')
expect(fields.eventTime.type).toBe('string')
expect(fields.matchKeys.type).toBe('object')
expect(fields.value?.type).toBe('number')
expect(fields.currencyCode?.type).toBe('string')
expect(fields.unitsSold?.type).toBe('integer')
expect(fields.clientDedupeId?.type).toBe('string')
expect(fields.eventId?.type).toBe('string')
expect(fields.dataProcessingOptions?.type).toBe('string')
expect(fields.dataProcessingOptions?.multiple).toBe(true)
expect(fields.consent?.type).toBe('object')
expect(fields.customAttributes?.type).toBe('object')
expect(fields.customData?.type).toBe('object')
expect(fields.enable_batching.type).toBe('boolean')
expect(fields.batch_size?.type).toBe('number')
})

it('should have proper choices for enum fields', () => {
// Event type choices
expect(fields.eventType.choices).toHaveLength(12)
expect(fields.eventType.choices).toContainEqual({ label: 'Add to Shopping Cart', value: 'ADD_TO_SHOPPING_CART' })
expect(fields.eventType.choices).toContainEqual({ label: 'Page View', value: 'PAGE_VIEW' })
expect(fields.eventType.choices).toContainEqual({ label: 'Other', value: 'OTHER' })
expect(fields.conversionType.choices).toHaveLength(12)
expect(fields.conversionType.choices).toContainEqual({ label: 'Add to Shopping Cart', value: 'ADD_TO_SHOPPING_CART' })
expect(fields.conversionType.choices).toContainEqual({ label: 'Page View', value: 'PAGE_VIEW' })
expect(fields.conversionType.choices).toContainEqual({ label: 'Other', value: 'OTHER' })

// Event action source choices
expect(fields.eventActionSource.choices).toHaveLength(5)
expect(fields.eventActionSource.choices).toContainEqual({ label: 'Website', value: 'website' })
expect(fields.eventActionSource.choices).toContainEqual({ label: 'Android', value: 'android' })
expect(fields.eventSource.choices).toHaveLength(5)
expect(fields.eventSource.choices).toContainEqual({ label: 'Website', value: 'website' })
expect(fields.eventSource.choices).toContainEqual({ label: 'Android', value: 'android' })

// Currency code choices
expect(fields.currencyCode?.choices).toBeDefined()
Expand All @@ -74,13 +73,15 @@ describe('trackConversion fields', () => {
expect(fields.currencyCode?.depends_on).toBeDefined()
expect(fields.currencyCode?.depends_on?.conditions).toBeDefined()
expect(fields.currencyCode?.depends_on?.conditions?.[0]).toMatchObject({
fieldKey: 'conversionType',
operator: 'is',
value: 'OFF_AMAZON_PURCHASES'
})

expect(fields.unitsSold?.depends_on).toBeDefined()
expect(fields.unitsSold?.depends_on?.conditions).toBeDefined()
expect(fields.unitsSold?.depends_on?.conditions?.[0]).toMatchObject({
fieldKey: 'conversionType',
operator: 'is',
value: 'OFF_AMAZON_PURCHASES'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('trackConversion', () => {
type: 'track',
properties: {
email: 'test@example.com',
eventType: 'ADD_TO_SHOPPING_CART'
conversionType: 'ADD_TO_SHOPPING_CART'
}
})

Expand All @@ -39,18 +39,18 @@ describe('trackConversion', () => {
describe('perform', () => {
it('should send event data successfully', async () => {
nock(`${Region.NA}`)
.post('/events/v1')
.post('/adsApi/v1/create/events')
.reply(200, { success: true })

const responses = await testDestination.testAction('trackConversion', {
event,
settings,
mapping: {
name: 'test_conversion',
eventType: 'ADD_TO_SHOPPING_CART',
eventActionSource: 'website',
conversionType: 'ADD_TO_SHOPPING_CART',
eventSource: 'website',
countryCode: 'US',
timestamp: '2023-01-01T12:00:00Z',
eventTime: '2023-01-01T12:00:00Z',
matchKeys: {
email: 'test@example.com'
},
Expand All @@ -66,7 +66,7 @@ describe('trackConversion', () => {
it('should handle API errors', async () => {
// Mock an API error response
nock(`${Region.NA}`)
.post('/events/v1')
.post('/adsApi/v1/create/events')
.replyWithError('Invalid event data')

await expect(
Expand All @@ -75,10 +75,10 @@ describe('trackConversion', () => {
settings,
mapping: {
name: 'test_conversion',
eventType: 'ADD_TO_SHOPPING_CART',
eventActionSource: 'website',
conversionType: 'ADD_TO_SHOPPING_CART',
eventSource: 'website',
countryCode: 'US',
timestamp: '2023-01-01T12:00:00Z',
eventTime: '2023-01-01T12:00:00Z',
matchKeys: {
email: 'invalid_email'
},
Expand All @@ -95,10 +95,10 @@ describe('trackConversion', () => {
settings,
mapping: {
name: 'test_conversion',
// Missing eventType
eventActionSource: 'website',
// Missing conversionType
eventSource: 'website',
countryCode: 'US',
timestamp: '2023-01-01T12:00:00Z',
eventTime: '2023-01-01T12:00:00Z',
matchKeys: {
email: 'test@example.com'
},
Expand Down Expand Up @@ -130,25 +130,21 @@ describe('trackConversion', () => {
it('should process a batch of events successfully', async () => {
// Mock a 207 multi-status response
nock(`${Region.NA}`)
.post('/events/v1')
.post('/adsApi/v1/create/events')
.reply(207, {
success: [
{ index: 1, message: 'Success' }
],
error: [
{ index: 2, httpStatusCode: '400', subErrors: [{ errorMessage: 'Invalid event' }] }
]
success: [{ index: 0, event: null }],
error: [{ index: 1, errors: [{ code: "BAD_REQUEST", message: 'Invalid data' }] }]
})

const responses = await testDestination.testBatchAction('trackConversion', {
events,
settings,
mapping: {
name: 'test_batch_conversion',
eventType: 'ADD_TO_SHOPPING_CART',
eventActionSource: 'website',
conversionType: 'ADD_TO_SHOPPING_CART',
eventSource: 'website',
countryCode: 'US',
timestamp: '2023-01-01T12:00:00Z',
eventTime: '2023-01-01T12:00:00Z',
matchKeys: {
email: {
'@path': '$.properties.email'
Expand All @@ -169,9 +165,9 @@ describe('trackConversion', () => {
it('should handle validation errors for individual payloads', async () => {
// Mock the API request to send a partial success response
nock(`${Region.NA}`)
.post('/events/v1')
.post('/adsApi/v1/create/events')
.reply(207, {
success: [{ index: 1, message: 'Success' },{ index: 2, message: 'Success' }],
success: [{ index: 0, event: null }, { index: 1, event: null }],
error: []
})

Expand All @@ -196,10 +192,10 @@ describe('trackConversion', () => {
settings,
mapping: {
name: 'test_batch_conversion',
eventType: 'ADD_TO_SHOPPING_CART',
eventActionSource: 'website',
conversionType: 'ADD_TO_SHOPPING_CART',
eventSource: 'website',
countryCode: 'US',
timestamp: '2023-01-01T12:00:00Z',
eventTime: '2023-01-01T12:00:00Z',
matchKeys: {
email: {
'@path': '$.properties.email'
Expand All @@ -221,7 +217,7 @@ describe('trackConversion', () => {

it('should handle API errors in batch mode', async () => {
nock(`${Region.NA}`)
.post('/events/v1')
.post('/adsApi/v1/create/events')
.reply(500, { error: 'Internal server error' })

// Spy on console.error to prevent error output during the test
Expand All @@ -234,10 +230,10 @@ describe('trackConversion', () => {
settings,
mapping: {
name: 'test_batch_conversion',
eventType: 'ADD_TO_SHOPPING_CART',
eventActionSource: 'website',
conversionType: 'ADD_TO_SHOPPING_CART',
eventSource: 'website',
countryCode: 'US',
timestamp: '2023-01-01T12:00:00Z',
eventTime: '2023-01-01T12:00:00Z',
matchKeys: {
email: {
'@path': '$.properties.email'
Expand Down
Loading
Loading