From 222608a1abcfad0cbd29bc3e0f1fbf68235141c9 Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Wed, 2 Oct 2024 16:44:03 +0100 Subject: [PATCH] adding tests --- .../__snapshots__/snapshot.test.ts.snap | 75 +++++++++++++++++++ .../optimizely-web/__tests__/index.test.ts | 18 ----- .../optimizely-web/__tests__/snapshot.test.ts | 22 +++++- .../__snapshots__/snapshot.test.ts.snap | 75 +++++++++++++++++++ .../trackEvent/__tests__/page.test.ts | 54 +------------ .../trackEvent/__tests__/snapshot.test.ts | 22 +++++- 6 files changed, 192 insertions(+), 74 deletions(-) create mode 100644 packages/destination-actions/src/destinations/optimizely-web/__tests__/__snapshots__/snapshot.test.ts.snap delete mode 100644 packages/destination-actions/src/destinations/optimizely-web/__tests__/index.test.ts create mode 100644 packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap diff --git a/packages/destination-actions/src/destinations/optimizely-web/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/optimizely-web/__tests__/__snapshots__/snapshot.test.ts.snap new file mode 100644 index 0000000000..f493429d76 --- /dev/null +++ b/packages/destination-actions/src/destinations/optimizely-web/__tests__/__snapshots__/snapshot.test.ts.snap @@ -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", + }, + ], +} +`; diff --git a/packages/destination-actions/src/destinations/optimizely-web/__tests__/index.test.ts b/packages/destination-actions/src/destinations/optimizely-web/__tests__/index.test.ts deleted file mode 100644 index 98152935a8..0000000000 --- a/packages/destination-actions/src/destinations/optimizely-web/__tests__/index.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import nock from 'nock' -import { createTestEvent, createTestIntegration } from '@segment/actions-core' -import Definition from '../index' - -const testDestination = createTestIntegration(Definition) - -describe('Optimizely Web', () => { - describe('testAuthentication', () => { - it('should validate authentication inputs', async () => { - nock('https://your.destination.endpoint').get('*').reply(200, {}) - - // This should match your authentication.fields - const authData = {} - - await expect(testDestination.testAuthentication(authData)).resolves.not.toThrowError() - }) - }) -}) diff --git a/packages/destination-actions/src/destinations/optimizely-web/__tests__/snapshot.test.ts b/packages/destination-actions/src/destinations/optimizely-web/__tests__/snapshot.test.ts index 2f81636801..f1e43135f4 100644 --- a/packages/destination-actions/src/destinations/optimizely-web/__tests__/snapshot.test.ts +++ b/packages/destination-actions/src/destinations/optimizely-web/__tests__/snapshot.test.ts @@ -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 }) @@ -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 }) diff --git a/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap new file mode 100644 index 0000000000..0ec924de1c --- /dev/null +++ b/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap @@ -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(", + }, + ], +} +`; diff --git a/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/page.test.ts b/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/page.test.ts index 4866d6cbc0..7b47232f5e 100644 --- a/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/page.test.ts +++ b/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/page.test.ts @@ -80,7 +80,7 @@ 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 @@ -88,7 +88,7 @@ const createPageJSON: CreatePageJSON = { const eventItem: EventItem = { id: 88888888888, - key: 'custom_page_1', + key: 'Custom_Page_1', name: 'Custom Page 1' } @@ -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 () => { diff --git a/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/snapshot.test.ts b/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/snapshot.test.ts index cb9f04994d..445ec58b6a 100644 --- a/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/snapshot.test.ts +++ b/packages/destination-actions/src/destinations/optimizely-web/trackEvent/__tests__/snapshot.test.ts @@ -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 }) @@ -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 })