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..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 @@ -15,3 +15,35 @@ Headers { }, } `; + +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 [ + "Bearer bar", + ], + "content-type": Array [ + "application/json", + ], + "user-agent": Array [ + "Segment (Actions)", + ], + }, +} +`; 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 943f518523..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 @@ -10,15 +10,13 @@ describe('Topsort.purchase', () => { nock(/.*/).persist().post(/.*/).reply(200) const event = createTestEvent({ - properties: { - products: [ - { - product_id: '123', - price: 100, - quantity: 1 - } - ] - } + products: [ + { + product_id: '123', + price: 100, + quantity: 1 + } + ] }) const responses = await testDestination.testAction('purchase', { @@ -50,6 +48,94 @@ describe('Topsort.purchase', () => { }) }) + it('should be successful with default mappings and products object, including brand as vendorId', async () => { + nock(/.*/).persist().post(/.*/).reply(200) + + const event = createTestEvent({ + products: [ + { + product_id: '123', + price: 100, + quantity: 1, + brand: '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 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) 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 602ee28508..1f3c9696e7 100644 --- a/packages/destination-actions/src/destinations/topsort/purchase/index.ts +++ b/packages/destination-actions/src/destinations/topsort/purchase/index.ts @@ -61,15 +61,28 @@ 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' }, - quantity: { '@path': '$.quantity' } + quantity: { '@path': '$.quantity' }, + vendorId: { + '@if': { + exists: { '@path': '$.vendorId' }, + then: { '@path': '$.vendorId' }, + else: { '@path': '$.brand' } + } + } } ] }