Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-ayoub-segment committed Oct 2, 2024
1 parent 191d7ea commit 222608a
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for actions-optimizely-web destination: trackEvent action - all fields 1`] = `
Object {
"account_id": "0dx]zHxQ6Zbx",
"anonymize_ip": true,
"client_name": "Segment Optimizely Web Destination",
"client_version": "1.0.0",
"enrich_decisions": true,
"project_id": -566109321297.92,
"visitors": Array [
Object {
"attributes": Array [],
"session_id": "0dx]zHxQ6Zbx",
"snapshots": Array [
Object {
"decisions": Array [],
"events": Array [
Object {
"entity_id": "custom_event_id_1",
"key": "custom_event_1",
"revenue": -56610932129792.01,
"tags": Object {
"$opt_event_properties": Object {},
"currency": "HRK",
"quantity": -56610932129792,
"testType": "0dx]zHxQ6Zbx",
},
"timestamp": 1612137600000,
"type": "other",
"uuid": "0dx]zHxQ6Zbx",
"value": -566109321297.92,
},
],
},
],
"visitor_id": "0dx]zHxQ6Zbx",
},
],
}
`;

exports[`Testing snapshot for actions-optimizely-web destination: trackEvent action - required fields 1`] = `
Object {
"account_id": "0dx]zHxQ6Zbx",
"anonymize_ip": true,
"client_name": "Segment Optimizely Web Destination",
"client_version": "1.0.0",
"enrich_decisions": true,
"project_id": -566109321297.92,
"visitors": Array [
Object {
"attributes": Array [],
"snapshots": Array [
Object {
"decisions": Array [],
"events": Array [
Object {
"entity_id": "custom_event_id_1",
"key": "custom_event_1",
"tags": Object {
"$opt_event_properties": Object {},
},
"timestamp": 1612137600000,
"type": "other",
"uuid": "0dx]zHxQ6Zbx",
},
],
},
],
"visitor_id": "0dx]zHxQ6Zbx",
},
],
}
`;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ describe(`Testing snapshot for ${destinationSlug} destination:`, () => {

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
mapping: {
...event.properties,
eventMatching: {
eventId: 'custom_event_id_1',
eventKey: 'Custom_Event_1',
createEventIfNotFound: 'CREATE',
shouldSnakeCaseEventKey: true
},
eventType: 'track'
},
settings: settingsData,
auth: undefined
})
Expand Down Expand Up @@ -57,7 +66,16 @@ describe(`Testing snapshot for ${destinationSlug} destination:`, () => {

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
mapping: {
...event.properties,
eventMatching: {
eventId: 'custom_event_id_1',
eventKey: 'Custom_Event_1',
createEventIfNotFound: 'CREATE',
shouldSnakeCaseEventKey: true
},
eventType: 'track'
},
settings: settingsData,
auth: undefined
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for OptimizelyWeb's trackEvent destination action: all fields 1`] = `
Object {
"account_id": "PXs*Kr1gqV9(",
"anonymize_ip": true,
"client_name": "Segment Optimizely Web Destination",
"client_version": "1.0.0",
"enrich_decisions": true,
"project_id": -9262421990440.96,
"visitors": Array [
Object {
"attributes": Array [],
"session_id": "PXs*Kr1gqV9(",
"snapshots": Array [
Object {
"decisions": Array [],
"events": Array [
Object {
"entity_id": "custom_event_id_1",
"key": "custom_event_1",
"revenue": -926242199044096.1,
"tags": Object {
"$opt_event_properties": Object {},
"currency": "SBD",
"quantity": -926242199044096,
"testType": "PXs*Kr1gqV9(",
},
"timestamp": 1612137600000,
"type": "other",
"uuid": "PXs*Kr1gqV9(",
"value": -9262421990440.96,
},
],
},
],
"visitor_id": "PXs*Kr1gqV9(",
},
],
}
`;

exports[`Testing snapshot for OptimizelyWeb's trackEvent destination action: required fields 1`] = `
Object {
"account_id": "PXs*Kr1gqV9(",
"anonymize_ip": true,
"client_name": "Segment Optimizely Web Destination",
"client_version": "1.0.0",
"enrich_decisions": true,
"project_id": -9262421990440.96,
"visitors": Array [
Object {
"attributes": Array [],
"snapshots": Array [
Object {
"decisions": Array [],
"events": Array [
Object {
"entity_id": "custom_event_id_1",
"key": "custom_event_1",
"tags": Object {
"$opt_event_properties": Object {},
},
"timestamp": 1612137600000,
"type": "other",
"uuid": "PXs*Kr1gqV9(",
},
],
},
],
"visitor_id": "PXs*Kr1gqV9(",
},
],
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ const mapping = {
const createPageJSON: CreatePageJSON = {
category: 'other',
event_type: 'custom',
key: 'custom_page_1',
key: 'Custom_Page_1',
name: 'Custom Page 1',
edit_url: 'https://example.com',
project_id: 123456
}

const eventItem: EventItem = {
id: 88888888888,
key: 'custom_page_1',
key: 'Custom_Page_1',
name: 'Custom Page 1'
}

Expand Down Expand Up @@ -166,56 +166,6 @@ describe('OptimizelyWeb.trackEvent', () => {
expect(responses.length).toBe(2)
expect(responses[1].status).toBe(204)
})

it('Should fetch event_id from Optimizely then send a custom track() event to Optimizely - event name should be snake cased and cleaned', async () => {
const event = createTestEvent(payload)

const mappingSnakeCase = {
...mapping,
eventMatching: { ...mapping.eventMatching, shouldSnakeCaseEventKey: true }
}

const sendEventJSONSnakeCase = {
...sendEventJSON,
visitors: [
{
...sendEventJSON.visitors[0],
snapshots: [
{
...sendEventJSON.visitors[0].snapshots[0],
events: [
{
...sendEventJSON.visitors[0].snapshots[0].events[0],
key: 'custom_page_1'
}
]
}
]
}
]
}

nock('https://api.optimizely.com')
.get('/v2/pages?per_page=100&project_id=123456')
.reply(200, [
{ id: 99999999999, key: 'not_the_correct_key', name: 'not_the_correct_name' },
{ id: 88888888888, key: 'custom_event_1', name: 'Custom Event 1' }
])

nock('https://logx.optimizely.com')
.post('/v1/events', sendEventJSONSnakeCase as unknown as any)
.reply(204)

const responses = await testDestination.testAction('trackEvent', {
event,
settings,
useDefaultMappings: true,
mapping: mappingSnakeCase
})

expect(responses.length).toBe(2)
expect(responses[1].status).toBe(204)
})
})
describe('Event Schema does not exist in Optimizely', () => {
it('Should fail to fetch event_id from Optimizely, then create new Custom Event schema in Optimizely, then send a custom track() event to Optimizely', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination ac

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
mapping: {
...event.properties,
eventMatching: {
eventId: 'custom_event_id_1',
eventKey: 'Custom_Event_1',
createEventIfNotFound: 'CREATE',
shouldSnakeCaseEventKey: true
},
eventType: 'track'
},
settings: settingsData,
auth: undefined
})
Expand Down Expand Up @@ -56,7 +65,16 @@ describe(`Testing snapshot for ${destinationSlug}'s ${actionSlug} destination ac

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
mapping: {
...event.properties,
eventMatching: {
eventId: 'custom_event_id_1',
eventKey: 'Custom_Event_1',
createEventIfNotFound: 'CREATE',
shouldSnakeCaseEventKey: true
},
eventType: 'track'
},
settings: settingsData,
auth: undefined
})
Expand Down

0 comments on commit 222608a

Please sign in to comment.