-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Recombee (Actions)" destination (#2429)
- Loading branch information
1 parent
468a6e8
commit e65ec10
Showing
57 changed files
with
4,133 additions
and
0 deletions.
There are no files selected for viewing
228 changes: 228 additions & 0 deletions
228
...stination-actions/src/destinations/recombee/__tests__/__snapshots__/snapshot.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addBookmark action - all fields 1`] = ` | ||
Object { | ||
"additionalData": Object { | ||
"testType": "7(iq3vwM", | ||
}, | ||
"cascadeCreate": true, | ||
"itemId": "7(iq3vwM", | ||
"recommId": "7(iq3vwM", | ||
"timestamp": "7(iq3vwM", | ||
"userId": "7(iq3vwM", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addBookmark action - required fields 1`] = ` | ||
Object { | ||
"cascadeCreate": true, | ||
"itemId": "7(iq3vwM", | ||
"userId": "7(iq3vwM", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addCartAddition action - all fields 1`] = ` | ||
Object { | ||
"requests": Array [ | ||
Object { | ||
"method": "POST", | ||
"params": Object { | ||
"additionalData": Object { | ||
"testType": "fSK%!$(3gz2peZ!&@L@D", | ||
}, | ||
"amount": 85450379273175.05, | ||
"cascadeCreate": true, | ||
"itemId": "fSK%!$(3gz2peZ!&@L@D", | ||
"price": 85450379273175.05, | ||
"recommId": "fSK%!$(3gz2peZ!&@L@D", | ||
"timestamp": "fSK%!$(3gz2peZ!&@L@D", | ||
"userId": "fSK%!$(3gz2peZ!&@L@D", | ||
}, | ||
"path": "/cartadditions/", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addCartAddition action - required fields 1`] = ` | ||
Object { | ||
"requests": Array [ | ||
Object { | ||
"method": "POST", | ||
"params": Object { | ||
"cascadeCreate": true, | ||
"itemId": "fSK%!$(3gz2peZ!&@L@D", | ||
"userId": "fSK%!$(3gz2peZ!&@L@D", | ||
}, | ||
"path": "/cartadditions/", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addDetailView action - all fields 1`] = ` | ||
Object { | ||
"additionalData": Object { | ||
"testType": "VhiOfa#s6#B[CQDV", | ||
}, | ||
"cascadeCreate": true, | ||
"duration": 4043918945550336, | ||
"itemId": "VhiOfa#s6#B[CQDV", | ||
"recommId": "VhiOfa#s6#B[CQDV", | ||
"timestamp": "VhiOfa#s6#B[CQDV", | ||
"userId": "VhiOfa#s6#B[CQDV", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addDetailView action - required fields 1`] = ` | ||
Object { | ||
"cascadeCreate": true, | ||
"itemId": "VhiOfa#s6#B[CQDV", | ||
"userId": "VhiOfa#s6#B[CQDV", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addPurchase action - all fields 1`] = ` | ||
Object { | ||
"requests": Array [ | ||
Object { | ||
"method": "POST", | ||
"params": Object { | ||
"additionalData": Object { | ||
"testType": "!D2A1H%v%jv&r", | ||
}, | ||
"amount": 3316018504007.68, | ||
"cascadeCreate": true, | ||
"itemId": "!D2A1H%v%jv&r", | ||
"price": 3316018504007.68, | ||
"profit": 3316018504007.68, | ||
"recommId": "!D2A1H%v%jv&r", | ||
"timestamp": "!D2A1H%v%jv&r", | ||
"userId": "!D2A1H%v%jv&r", | ||
}, | ||
"path": "/purchases/", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addPurchase action - required fields 1`] = ` | ||
Object { | ||
"requests": Array [ | ||
Object { | ||
"method": "POST", | ||
"params": Object { | ||
"cascadeCreate": true, | ||
"itemId": "!D2A1H%v%jv&r", | ||
"userId": "!D2A1H%v%jv&r", | ||
}, | ||
"path": "/purchases/", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addRating action - all fields 1`] = ` | ||
Object { | ||
"additionalData": Object { | ||
"testType": "X9m9Urlsqof(&*PN!s", | ||
}, | ||
"cascadeCreate": true, | ||
"itemId": "X9m9Urlsqof(&*PN!s", | ||
"rating": 63040185947914.24, | ||
"recommId": "X9m9Urlsqof(&*PN!s", | ||
"timestamp": "X9m9Urlsqof(&*PN!s", | ||
"userId": "X9m9Urlsqof(&*PN!s", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: addRating action - required fields 1`] = ` | ||
Object { | ||
"cascadeCreate": true, | ||
"itemId": "X9m9Urlsqof(&*PN!s", | ||
"rating": 63040185947914.24, | ||
"userId": "X9m9Urlsqof(&*PN!s", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: deleteBookmark action - all fields 1`] = ` | ||
Object { | ||
"itemId": "Sy@zJ0^", | ||
"timestamp": "Sy@zJ0^", | ||
"userId": "Sy@zJ0^", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: deleteBookmark action - required fields 1`] = ` | ||
Object { | ||
"itemId": "Sy@zJ0^", | ||
"userId": "Sy@zJ0^", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: deleteCartAddition action - all fields 1`] = ` | ||
Object { | ||
"itemId": "BGNilpbMGk^JyT", | ||
"timestamp": "BGNilpbMGk^JyT", | ||
"userId": "BGNilpbMGk^JyT", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: deleteCartAddition action - required fields 1`] = ` | ||
Object { | ||
"itemId": "BGNilpbMGk^JyT", | ||
"userId": "BGNilpbMGk^JyT", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: mergeUsers action - all fields 1`] = `Object {}`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: mergeUsers action - required fields 1`] = `Object {}`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: setViewPortion action - all fields 1`] = ` | ||
Object { | ||
"additionalData": Object { | ||
"testType": "D9^z[P*Zv", | ||
}, | ||
"cascadeCreate": true, | ||
"itemId": "D9^z[P*Zv", | ||
"portion": -42971588743659.52, | ||
"recommId": "D9^z[P*Zv", | ||
"sessionId": "D9^z[P*Zv", | ||
"timestamp": "D9^z[P*Zv", | ||
"userId": "D9^z[P*Zv", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: setViewPortion action - required fields 1`] = ` | ||
Object { | ||
"cascadeCreate": true, | ||
"itemId": "D9^z[P*Zv", | ||
"portion": -42971588743659.52, | ||
"userId": "D9^z[P*Zv", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: setViewPortionFromWatchTime action - all fields 1`] = ` | ||
Object { | ||
"additionalData": Object { | ||
"testType": "gpLV6!FLD#$6^LR77nTN", | ||
}, | ||
"cascadeCreate": true, | ||
"itemId": "gpLV6!FLD#$6^LR77nTN", | ||
"portion": 1, | ||
"recommId": "gpLV6!FLD#$6^LR77nTN", | ||
"sessionId": "gpLV6!FLD#$6^LR77nTN", | ||
"timestamp": "gpLV6!FLD#$6^LR77nTN", | ||
"userId": "gpLV6!FLD#$6^LR77nTN", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for actions-recombee destination: setViewPortionFromWatchTime action - required fields 1`] = ` | ||
Object { | ||
"cascadeCreate": true, | ||
"itemId": "gpLV6!FLD#$6^LR77nTN", | ||
"portion": 1, | ||
"userId": "gpLV6!FLD#$6^LR77nTN", | ||
} | ||
`; |
65 changes: 65 additions & 0 deletions
65
packages/destination-actions/src/destinations/recombee/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import nock from 'nock' | ||
import { createTestIntegration } from '@segment/actions-core' | ||
import Definition from '../index' | ||
import { Settings } from '../generated-types' | ||
|
||
const testDestination = createTestIntegration(Definition) | ||
const DATABASE_ID = 'test-database' | ||
|
||
describe('Recombee', () => { | ||
describe('testAuthentication', () => { | ||
it('should validate authentication inputs', async () => { | ||
nock('https://rapi-eu-west.recombee.com/') | ||
.post(`/${DATABASE_ID}/batch/`) | ||
.query({ | ||
hmac_timestamp: /.*/, | ||
hmac_sign: /.*/ | ||
}) | ||
.reply(200, []) | ||
|
||
const authData: Settings = { | ||
privateToken: 'VALID_TOKEN', | ||
databaseId: DATABASE_ID, | ||
databaseRegion: 'eu-west' | ||
} | ||
|
||
await expect(testDestination.testAuthentication(authData)).resolves.not.toThrowError() | ||
}) | ||
|
||
it('should throw error when no API Key', async () => { | ||
nock('https://rapi-eu-west.recombee.com/') | ||
.post(`/${DATABASE_ID}/batch/`) | ||
.query({ | ||
hmac_timestamp: /.*/, | ||
hmac_sign: /.*/ | ||
}) | ||
.reply(401, []) | ||
|
||
const authData: Settings = { | ||
privateToken: '', | ||
databaseId: DATABASE_ID, | ||
databaseRegion: 'eu-west' | ||
} | ||
|
||
await expect(testDestination.testAuthentication(authData)).rejects.toThrowError(/401/) | ||
}) | ||
|
||
it('should throw error when API Key invalid', async () => { | ||
nock('https://rapi-eu-west.recombee.com/') | ||
.post(`/${DATABASE_ID}/batch/`) | ||
.query({ | ||
hmac_timestamp: /.*/, | ||
hmac_sign: /.*/ | ||
}) | ||
.reply(401, []) | ||
|
||
const authData: Settings = { | ||
privateToken: 'INVALID_TOKEN', | ||
databaseId: DATABASE_ID, | ||
databaseRegion: 'eu-west' | ||
} | ||
|
||
await expect(testDestination.testAuthentication(authData)).rejects.toThrowError(/401/) | ||
}) | ||
}) | ||
}) |
77 changes: 77 additions & 0 deletions
77
packages/destination-actions/src/destinations/recombee/__tests__/snapshot.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { createTestEvent, createTestIntegration } from '@segment/actions-core' | ||
import { generateTestData } from '../../../lib/test-data' | ||
import destination from '../index' | ||
import nock from 'nock' | ||
|
||
const testDestination = createTestIntegration(destination) | ||
const destinationSlug = 'actions-recombee' | ||
|
||
describe(`Testing snapshot for ${destinationSlug} destination:`, () => { | ||
for (const actionSlug in destination.actions) { | ||
it(`${actionSlug} action - required fields`, async () => { | ||
const seedName = `${destinationSlug}#${actionSlug}` | ||
const action = destination.actions[actionSlug] | ||
const [eventData, settingsData] = generateTestData(seedName, destination, action, true) | ||
|
||
nock(/.*/).persist().post(/.*/).reply(200) | ||
nock(/.*/).persist().put(/.*/).reply(200) | ||
nock(/.*/).persist().delete(/.*/).reply(200) | ||
|
||
const event = createTestEvent({ | ||
properties: eventData | ||
}) | ||
|
||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: settingsData, | ||
auth: undefined | ||
}) | ||
|
||
const request = responses[0].request | ||
const rawBody = await request.text() | ||
|
||
try { | ||
const json = JSON.parse(rawBody) | ||
expect(json).toMatchSnapshot() | ||
return | ||
} catch (err) { | ||
expect(rawBody).toMatchSnapshot() | ||
} | ||
|
||
expect(request.headers).toMatchSnapshot() | ||
}) | ||
|
||
it(`${actionSlug} action - all fields`, async () => { | ||
const seedName = `${destinationSlug}#${actionSlug}` | ||
const action = destination.actions[actionSlug] | ||
const [eventData, settingsData] = generateTestData(seedName, destination, action, false) | ||
|
||
nock(/.*/).persist().post(/.*/).reply(200) | ||
nock(/.*/).persist().put(/.*/).reply(200) | ||
nock(/.*/).persist().delete(/.*/).reply(200) | ||
|
||
const event = createTestEvent({ | ||
properties: eventData | ||
}) | ||
|
||
const responses = await testDestination.testAction(actionSlug, { | ||
event: event, | ||
mapping: event.properties, | ||
settings: settingsData, | ||
auth: undefined | ||
}) | ||
|
||
const request = responses[0].request | ||
const rawBody = await request.text() | ||
|
||
try { | ||
const json = JSON.parse(rawBody) | ||
expect(json).toMatchSnapshot() | ||
return | ||
} catch (err) { | ||
expect(rawBody).toMatchSnapshot() | ||
} | ||
}) | ||
} | ||
}) |
22 changes: 22 additions & 0 deletions
22
...tions/src/destinations/recombee/addBookmark/__tests__/__snapshots__/snapshot.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing snapshot for Recombee's addBookmark destination action: all fields 1`] = ` | ||
Object { | ||
"additionalData": Object { | ||
"testType": "GxFzk&V2a4R8iF62G9]q", | ||
}, | ||
"cascadeCreate": true, | ||
"itemId": "GxFzk&V2a4R8iF62G9]q", | ||
"recommId": "GxFzk&V2a4R8iF62G9]q", | ||
"timestamp": "GxFzk&V2a4R8iF62G9]q", | ||
"userId": "GxFzk&V2a4R8iF62G9]q", | ||
} | ||
`; | ||
|
||
exports[`Testing snapshot for Recombee's addBookmark destination action: required fields 1`] = ` | ||
Object { | ||
"cascadeCreate": true, | ||
"itemId": "GxFzk&V2a4R8iF62G9]q", | ||
"userId": "GxFzk&V2a4R8iF62G9]q", | ||
} | ||
`; |
Oops, something went wrong.