From e281223164566d40bb39909c2273a5ce490c3670 Mon Sep 17 00:00:00 2001 From: agustinespildora Date: Mon, 10 Feb 2025 13:13:49 -0300 Subject: [PATCH 1/4] feat: vendorId in purchase --- .../purchase/__tests__/__snapshots__/index.test.ts.snap | 2 +- .../destinations/topsort/purchase/__tests__/index.test.ts | 8 +++++--- .../src/destinations/topsort/purchase/index.ts | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap index d1fdc7e404..089b507827 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Topsort.purchase should be successful with default mappings and products object 1`] = ` +exports[`Topsort.purchase should be successful with default mappings and products object, including vendorId 1`] = ` Headers { Symbol(map): Object { "authorization": Array [ diff --git a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts index 943f518523..849b685e52 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts @@ -6,7 +6,7 @@ import Destination from '../../index' const testDestination = createTestIntegration(Destination) describe('Topsort.purchase', () => { - it('should be successful with default mappings and products object', async () => { + it('should be successful with default mappings and products object, including vendorId', async () => { nock(/.*/).persist().post(/.*/).reply(200) const event = createTestEvent({ @@ -15,7 +15,8 @@ describe('Topsort.purchase', () => { { product_id: '123', price: 100, - quantity: 1 + quantity: 1, + vendor_id: 'v123' } ] } @@ -42,7 +43,8 @@ describe('Topsort.purchase', () => { { productId: '123', unitPrice: 100, - quantity: 1 + quantity: 1, + vendorId: 'v123' } ] }) diff --git a/packages/destination-actions/src/destinations/topsort/purchase/index.ts b/packages/destination-actions/src/destinations/topsort/purchase/index.ts index 602ee28508..69a0e8b78a 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/index.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/index.ts @@ -69,7 +69,8 @@ const action: ActionDefinition = { { productId: { '@path': '$.product_id' }, unitPrice: { '@path': '$.price' }, - quantity: { '@path': '$.quantity' } + quantity: { '@path': '$.quantity' }, + vendorId: { '@path': '$.brand' } } ] } From 8c46e7bac7dc25e3a84fac71efffcf1156490d50 Mon Sep 17 00:00:00 2001 From: agustinespildora Date: Thu, 13 Feb 2025 11:07:30 -0300 Subject: [PATCH 2/4] fix: purchase format --- .../__snapshots__/snapshot.test.ts.snap | 1 + .../topsort/purchase/__tests__/index.test.ts | 18 ++++++++---------- .../topsort/purchase/generated-types.ts | 4 ++++ .../src/destinations/topsort/purchase/index.ts | 8 +++++++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/snapshot.test.ts.snap index 956e66ff39..4b80522d03 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/snapshot.test.ts.snap @@ -10,6 +10,7 @@ Object { "productId": "4mevd8V", "quantity": -6621698275147776, "unitPrice": -66216982751477.76, + "vendorId": "4mevd8V", }, ], "occurredAt": "2021-02-01T00:00:00.000Z", diff --git a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts index 849b685e52..d97a5c2dc4 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts @@ -10,16 +10,14 @@ describe('Topsort.purchase', () => { nock(/.*/).persist().post(/.*/).reply(200) const event = createTestEvent({ - properties: { - products: [ - { - product_id: '123', - price: 100, - quantity: 1, - vendor_id: 'v123' - } - ] - } + products: [ + { + product_id: '123', + price: 100, + quantity: 1, + brand: 'v123' + } + ] }) const responses = await testDestination.testAction('purchase', { diff --git a/packages/destination-actions/src/destinations/topsort/purchase/generated-types.ts b/packages/destination-actions/src/destinations/topsort/purchase/generated-types.ts index 58fd24788e..935d338437 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/generated-types.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/generated-types.ts @@ -29,5 +29,9 @@ export interface Payload { * Count of products purchased. */ quantity?: number + /** + * The vendor ID of the product being purchased. + */ + vendorId?: string }[] } diff --git a/packages/destination-actions/src/destinations/topsort/purchase/index.ts b/packages/destination-actions/src/destinations/topsort/purchase/index.ts index 69a0e8b78a..699869783a 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/index.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/index.ts @@ -61,11 +61,17 @@ const action: ActionDefinition = { description: 'Count of products purchased.', type: 'integer', required: false + }, + vendorId: { + label: 'Vendor ID', + description: 'The vendor ID of the product being purchased.', + type: 'string', + required: false } }, default: { '@arrayPath': [ - '$.properties.products', + '$.products', { productId: { '@path': '$.product_id' }, unitPrice: { '@path': '$.price' }, From 31ab352ae5a0930b4864a7a2e6bcaf3e1632475f Mon Sep 17 00:00:00 2001 From: agustinespildora Date: Thu, 13 Feb 2025 11:30:58 -0300 Subject: [PATCH 3/4] feat: add conditional custom mapping for vendorId --- .../src/destinations/topsort/purchase/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/destination-actions/src/destinations/topsort/purchase/index.ts b/packages/destination-actions/src/destinations/topsort/purchase/index.ts index 699869783a..1f3c9696e7 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/index.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/index.ts @@ -76,7 +76,13 @@ const action: ActionDefinition = { productId: { '@path': '$.product_id' }, unitPrice: { '@path': '$.price' }, quantity: { '@path': '$.quantity' }, - vendorId: { '@path': '$.brand' } + vendorId: { + '@if': { + exists: { '@path': '$.vendorId' }, + then: { '@path': '$.vendorId' }, + else: { '@path': '$.brand' } + } + } } ] } From ca11bc1279d6c2bc7a91997496d2b439a783db11 Mon Sep 17 00:00:00 2001 From: agustinespildora Date: Thu, 13 Feb 2025 11:35:52 -0300 Subject: [PATCH 4/4] feat: add test for vendorId --- .../__snapshots__/index.test.ts.snap | 34 ++++++- .../topsort/purchase/__tests__/index.test.ts | 88 ++++++++++++++++++- 2 files changed, 120 insertions(+), 2 deletions(-) diff --git a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap index 089b507827..ca3158c655 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/__snapshots__/index.test.ts.snap @@ -1,6 +1,38 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Topsort.purchase should be successful with default mappings and products object, including vendorId 1`] = ` +exports[`Topsort.purchase should be successful with default mappings and products object 1`] = ` +Headers { + Symbol(map): Object { + "authorization": Array [ + "Bearer bar", + ], + "content-type": Array [ + "application/json", + ], + "user-agent": Array [ + "Segment (Actions)", + ], + }, +} +`; + +exports[`Topsort.purchase should be successful with default mappings and products object, including brand as vendorId 1`] = ` +Headers { + Symbol(map): Object { + "authorization": Array [ + "Bearer bar", + ], + "content-type": Array [ + "application/json", + ], + "user-agent": Array [ + "Segment (Actions)", + ], + }, +} +`; + +exports[`Topsort.purchase should be successful with default mappings and products object, including custom vendorId 1`] = ` Headers { Symbol(map): Object { "authorization": Array [ diff --git a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts index d97a5c2dc4..629db55a60 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/__tests__/index.test.ts @@ -6,7 +6,49 @@ import Destination from '../../index' const testDestination = createTestIntegration(Destination) describe('Topsort.purchase', () => { - it('should be successful with default mappings and products object, including vendorId', async () => { + it('should be successful with default mappings and products object', async () => { + nock(/.*/).persist().post(/.*/).reply(200) + + const event = createTestEvent({ + products: [ + { + product_id: '123', + price: 100, + quantity: 1 + } + ] + }) + + const responses = await testDestination.testAction('purchase', { + event, + settings: { + api_key: 'bar' + }, + useDefaultMappings: true + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.headers).toMatchSnapshot() + expect(responses[0].options.json).toMatchObject({ + purchases: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(String), + occurredAt: expect.any(String), + opaqueUserId: expect.any(String), + items: [ + { + productId: '123', + unitPrice: 100, + quantity: 1 + } + ] + }) + ]) + }) + }) + + it('should be successful with default mappings and products object, including brand as vendorId', async () => { nock(/.*/).persist().post(/.*/).reply(200) const event = createTestEvent({ @@ -50,6 +92,50 @@ describe('Topsort.purchase', () => { }) }) + it('should be successful with default mappings and products object, including custom vendorId', async () => { + nock(/.*/).persist().post(/.*/).reply(200) + + const event = createTestEvent({ + products: [ + { + product_id: '123', + price: 100, + quantity: 1, + vendorId: 'v123' + } + ] + }) + + const responses = await testDestination.testAction('purchase', { + event, + settings: { + api_key: 'bar' + }, + useDefaultMappings: true + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.headers).toMatchSnapshot() + expect(responses[0].options.json).toMatchObject({ + purchases: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(String), + occurredAt: expect.any(String), + opaqueUserId: expect.any(String), + items: [ + { + productId: '123', + unitPrice: 100, + quantity: 1, + vendorId: 'v123' + } + ] + }) + ]) + }) + }) + it('should fail because it misses a required field (products)', async () => { nock(/.*/).persist().post(/.*/).reply(200)