diff --git a/.github/workflows/component-test-report.yml b/.github/workflows/component-test-report.yml new file mode 100644 index 0000000000..9904004417 --- /dev/null +++ b/.github/workflows/component-test-report.yml @@ -0,0 +1,68 @@ +name: Component Test Reporter + +on: + pull_request: + types: + - opened + - reopened + - synchronize + +permissions: + id-token: write # allows the JWT to be requested from GitHub's OIDC provider + contents: read # This is required for actions/checkout + +jobs: + test_and_upload: + runs-on: ubuntu-latest + + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_DEV_ACCOUNT_ID }}:role/${{ secrets.AWS_DEV_S3_SYNC_ROLE }} + aws-region: us-east-1 + + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 1 + + - name: Setup Node + uses: actions/setup-node@v4.0.1 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Install Dependencies + run: npm ci + + - name: Run Tests and Generate Report + run: | + npm run test:ts -- component + + + - name: Uplaod Report to S3 + run: | + aws s3 cp ./test_reports/ s3://test-integrations-dev/integrations-test-reports/rudder-transformer/${{ github.event.number }}/ --recursive + + + - name: Comment on PR with S3 Object URL + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.PAT }} + script: | + const { owner, repo } = context.repo; + // Get the pull request number + const prNumber = context.payload.pull_request.number; + const commentBody = `Test report for this run is available at: https://test-integrations-dev.s3.amazonaws.com/integrations-test-reports/rudder-transformer/${prNumber}/test-report.html`; + + + // Comment on the pull request + github.rest.issues.createComment({ + owner, + repo, + issue_number: prNumber, + body: commentBody + }); + + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 24d37f6354..f96c3ac807 100644 --- a/.gitignore +++ b/.gitignore @@ -134,4 +134,7 @@ dist **/.DS_Store -.idea \ No newline at end of file +.idea + +# component test report +test_reports/ \ No newline at end of file diff --git a/src/v0/destinations/tiktok_ads/util.test.js b/src/v0/destinations/tiktok_ads/util.test.js index 67473ad9dd..1649b94eeb 100644 --- a/src/v0/destinations/tiktok_ads/util.test.js +++ b/src/v0/destinations/tiktok_ads/util.test.js @@ -107,7 +107,7 @@ describe('hashUserField utility test', () => { const hashedUser = hashUserField(user); expect(hashedUser).toEqual({ - external_id: "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3", + external_id: 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3', email: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b', phone: '422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8', }); diff --git a/test/integrations/component.test.ts b/test/integrations/component.test.ts index 847dd4c91f..d8d7732e12 100644 --- a/test/integrations/component.test.ts +++ b/test/integrations/component.test.ts @@ -21,6 +21,8 @@ import tags from '../../src/v0/util/tags'; import { Server } from 'http'; import { appendFileSync } from 'fs'; import { responses } from '../testHelper'; +import { generateTestReport, initaliseReport } from '../test_reporter/reporter'; +import _ from 'lodash'; // To run single destination test cases // npm run test:ts -- component --destination=adobe_analytics @@ -37,6 +39,7 @@ command .option('-f, --feature ', 'Enter Feature Name(processor, router)') .option('-i, --index ', 'Enter Test index') .option('-g, --generate ', 'Enter "true" If you want to generate network file') + .option('-id, --id ', 'Enter unique "Id" of the test case you want to run') .parse(); const opts = command.opts(); @@ -50,7 +53,10 @@ if (opts.generate === 'true') { let server: Server; +const REPORT_COMPATIBLE_INTEGRATION = ['klaviyo']; + beforeAll(async () => { + initaliseReport(); const app = new Koa(); app.use( bodyParser({ @@ -124,6 +130,16 @@ const testRoute = async (route, tcData: TestCaseData) => { const outputResp = tcData.output.response || ({} as any); expect(response.status).toEqual(outputResp.status); + if (REPORT_COMPATIBLE_INTEGRATION.includes(tcData.name?.toLocaleLowerCase())) { + const bodyMatched = _.isEqual(response.body, outputResp.body); + const statusMatched = response.status === outputResp.status; + if (bodyMatched && statusMatched) { + generateTestReport(tcData, response.body, 'passed'); + } else { + generateTestReport(tcData, response.body, 'failed'); + } + } + if (outputResp?.body) { expect(response.body).toEqual(outputResp.body); } @@ -181,6 +197,14 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => { if (opts.index !== undefined) { testData = [testData[parseInt(opts.index)]]; } + if (opts.id) { + testData = testData.filter((data) => { + if (data['id'] === opts.id) { + return true; + } + return false; + }); + } describe(`${testData[0].name} ${testData[0].module}`, () => { test.each(testData)('$feature -> $description', async (tcData) => { tcData?.mockFns?.(mockAdapter); diff --git a/test/integrations/destinations/klaviyo/processor/data.ts b/test/integrations/destinations/klaviyo/processor/data.ts index 58a1064251..06c4a3e530 100644 --- a/test/integrations/destinations/klaviyo/processor/data.ts +++ b/test/integrations/destinations/klaviyo/processor/data.ts @@ -1,2500 +1,15 @@ +import { ecomTestData } from './ecomTestData'; +import { groupTestData } from './groupTestData'; +import { identifyData } from './identifyTestData'; +import { screenTestData } from './screenTestData'; +import { trackTestData } from './trackTestData'; +import { validationTestData } from './validationTestData'; + export const data = [ - { - name: 'klaviyo', - description: 'Profile updating call and subscribe user (old transformer)', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - email: 'test@rudderstack.com', - phone: '+12 345 578 900', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - Flagged: false, - Residence: 'Shibuya', - properties: { - listId: 'XUepkK', - subscribe: true, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'PATCH', - endpoint: 'https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile', - attributes: { - external_id: 'user@1', - email: 'test@rudderstack.com', - first_name: 'Test', - last_name: 'Rudderlabs', - phone_number: '+12 345 578 900', - title: 'Developer', - organization: 'Rudder', - location: { - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - }, - properties: { - Flagged: false, - Residence: 'Shibuya', - }, - }, - id: '01GW3PHVY0MTCDGS0A1612HARX', - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - { - output: { - version: '1', - type: 'REST', - method: 'POST', - userId: '', - endpoint: 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile-subscription-bulk-create-job', - attributes: { - list_id: 'XUepkK', - subscriptions: [ - { - email: 'test@rudderstack.com', - phone_number: '+12 345 578 900', - channels: { - email: ['MARKETING'], - sms: ['MARKETING'], - }, - }, - ], - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Identify call for with flattenProperties enabled (old transformer)', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - flattenProperties: true, - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - email: 'test@rudderstack.com', - phone: '+12 345 578 900', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - Flagged: false, - Residence: 'Shibuya', - friend: { - names: { - first: 'Alice', - last: 'Smith', - }, - age: 25, - }, - properties: { - listId: 'XUepkK', - subscribe: true, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'PATCH', - endpoint: 'https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile', - attributes: { - external_id: 'user@1', - email: 'test@rudderstack.com', - first_name: 'Test', - last_name: 'Rudderlabs', - phone_number: '+12 345 578 900', - title: 'Developer', - organization: 'Rudder', - location: { - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - }, - properties: { - 'friend.age': 25, - 'friend.names.first': 'Alice', - 'friend.names.last': 'Smith', - Flagged: false, - Residence: 'Shibuya', - }, - }, - id: '01GW3PHVY0MTCDGS0A1612HARX', - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile-subscription-bulk-create-job', - attributes: { - list_id: 'XUepkK', - subscriptions: [ - { - email: 'test@rudderstack.com', - phone_number: '+12 345 578 900', - channels: { - email: ['MARKETING'], - sms: ['MARKETING'], - }, - }, - ], - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Profile updation call and subcribe user', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKeyforfailure', - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - email: 'test3@rudderstack.com', - phone: '+12 345 578 900', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - Flagged: false, - Residence: 'Shibuya', - properties: { - listId: 'XUepkK', - subscribe: true, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - error: - '{"message":"Failed to create user due to \\"\\"","destinationResponse":"\\"\\""}', - statTags: { - destType: 'KLAVIYO', - errorCategory: 'network', - errorType: 'retryable', - feature: 'processor', - implementation: 'native', - module: 'destination', - }, - statusCode: 500, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Profile updation call listId is not provided for subscribing the user', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - email: 'test@rudderstack.com', - phone: '+12 345 578 900', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - Flagged: false, - Residence: 'Shibuya', - properties: { - subscribe: false, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'PATCH', - endpoint: 'https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile', - attributes: { - external_id: 'user@1', - email: 'test@rudderstack.com', - first_name: 'Test', - last_name: 'Rudderlabs', - phone_number: '+12 345 578 900', - title: 'Developer', - organization: 'Rudder', - location: { - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - }, - properties: { - Flagged: false, - Residence: 'Shibuya', - }, - }, - id: '01GW3PHVY0MTCDGS0A1612HARX', - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Identify call with enforceEmailAsPrimary enabled from UI', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - enforceEmailAsPrimary: true, - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - email: 'test@rudderstack.com', - phone: '+12 345 578 900', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - Flagged: false, - Residence: 'Shibuya', - properties: { - listId: 'XUepkK', - subscribe: true, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'PATCH', - endpoint: 'https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile', - attributes: { - email: 'test@rudderstack.com', - first_name: 'Test', - last_name: 'Rudderlabs', - phone_number: '+12 345 578 900', - title: 'Developer', - organization: 'Rudder', - location: { - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - }, - properties: { - Flagged: false, - Residence: 'Shibuya', - _id: 'user@1', - }, - }, - id: '01GW3PHVY0MTCDGS0A1612HARX', - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile-subscription-bulk-create-job', - attributes: { - list_id: 'XUepkK', - subscriptions: [ - { - email: 'test@rudderstack.com', - phone_number: '+12 345 578 900', - channels: { - email: ['MARKETING'], - sms: ['MARKETING'], - }, - }, - ], - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Identify call without user custom Properties', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - enforceEmailAsPrimary: false, - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - email: 'test@rudderstack.com', - phone: '+12 345 578 900', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - properties: { - listId: 'XUepkK', - subscribe: true, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'PATCH', - endpoint: 'https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile', - attributes: { - email: 'test@rudderstack.com', - first_name: 'Test', - last_name: 'Rudderlabs', - phone_number: '+12 345 578 900', - external_id: 'user@1', - title: 'Developer', - organization: 'Rudder', - location: { - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - }, - }, - id: '01GW3PHVY0MTCDGS0A1612HARX', - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - { - output: { - version: '1', - type: 'REST', - userId: '', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'profile-subscription-bulk-create-job', - attributes: { - list_id: 'XUepkK', - subscriptions: [ - { - email: 'test@rudderstack.com', - phone_number: '+12 345 578 900', - channels: { - email: ['MARKETING'], - sms: ['MARKETING'], - }, - }, - ], - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Identify call without email and phone & enforceEmailAsPrimary enabled from UI', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - enforceEmailAsPrimary: true, - }, - }, - message: { - type: 'identify', - sentAt: '2021-01-03T17:02:53.195Z', - userId: 'user@1', - channel: 'web', - context: { - os: { - name: '', - version: '', - }, - app: { - name: 'RudderLabs JavaScript SDK', - build: '1.0.0', - version: '1.1.11', - namespace: 'com.rudderlabs.javascript', - }, - traits: { - firstName: 'Test', - lastName: 'Rudderlabs', - userId: 'user@1', - title: 'Developer', - organization: 'Rudder', - city: 'Tokyo', - region: 'Kanto', - country: 'JP', - zip: '100-0001', - Flagged: false, - Residence: 'Shibuya', - properties: { - listId: 'XUepkK', - subscribe: true, - consent: ['email', 'sms'], - }, - }, - locale: 'en-US', - screen: { - density: 2, - }, - library: { - name: 'RudderLabs JavaScript SDK', - version: '1.1.11', - }, - campaign: {}, - userAgent: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', - }, - rudderId: '8f8fa6b5-8e24-489c-8e22-61f23f2e364f', - messageId: '2116ef8c-efc3-4ca4-851b-02ee60dad6ff', - anonymousId: '97c46c81-3140-456d-b2a9-690d70aaca35', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-03T17:02:53.193Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - error: 'None of email and phone are present in the payload', - statTags: { - destType: 'KLAVIYO', - errorCategory: 'dataValidation', - errorType: 'instrumentation', - feature: 'processor', - implementation: 'native', - module: 'destination', - }, - statusCode: 400, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Screen event call', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'screen', - event: 'TestEven001', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'TestEven001', - }, - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - $id: 'sajal12', - age: '22', - }, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track event call with flatten properties enabled', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - flattenProperties: true, - }, - }, - message: { - type: 'track', - event: 'TestEven001', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - plan_details: { - plan_type: 'gold', - duration: '3 months', - }, - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - vicePresdentInfo: { - PreviouslVicePresident: true, - YearElected: 1801, - VicePresidents: ['AaronBurr', 'GeorgeClinton'], - }, - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'TestEven001', - }, - properties: { - 'vicePresdentInfo.PreviouslVicePresident': true, - 'vicePresdentInfo.VicePresidents': ['AaronBurr', 'GeorgeClinton'], - 'vicePresdentInfo.YearElected': 1801, - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - $id: 'sajal12', - age: '22', - 'plan_details.plan_type': 'gold', - 'plan_details.duration': '3 months', - }, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track event call', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'track', - event: 'TestEven002', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - name: 'Test', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - description: 'Sample description', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - revenue: 3000, - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'TestEven002', - }, - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - $id: 'sajal12', - age: '22', - name: 'Test', - description: 'Sample description', - }, - value: 3000, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track event call, with make email or phone as primary identifier toggle on', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - enforceEmailAsPrimary: true, - }, - }, - message: { - type: 'track', - event: 'TestEven001', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'TestEven001', - }, - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - age: '22', - _id: 'sajal12', - }, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: - 'Track event call, without email and phone & with (make email or phone as primary identifier) toggle on', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - enforceEmailAsPrimary: true, - }, - }, - message: { - type: 'track', - event: 'TestEven001', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - anonymousId: '9c6bd77ea9da3e68', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - error: 'None of email and phone are present in the payload', - statTags: { - destType: 'KLAVIYO', - errorCategory: 'dataValidation', - errorType: 'instrumentation', - feature: 'processor', - implementation: 'native', - module: 'destination', - }, - statusCode: 400, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'group call', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - userId: 'user123', - type: 'group', - groupId: 'XUepkK', - traits: { - subscribe: true, - }, - context: { - traits: { - email: 'test@rudderstack.com', - phone: '+12 345 678 900', - consent: ['email'], - }, - ip: '14.5.67.21', - library: { - name: 'http', - }, - }, - timestamp: '2020-01-21T00:21:34.208Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - body: { - FORM: {}, - JSON: { - data: { - attributes: { - list_id: 'XUepkK', - subscriptions: [ - { email: 'test@rudderstack.com', phone_number: '+12 345 678 900' }, - ], - }, - type: 'profile-subscription-bulk-create-job', - }, - }, - JSON_ARRAY: {}, - XML: {}, - }, - endpoint: 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', - files: {}, - headers: { - Accept: 'application/json', - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - revision: '2023-02-22', - }, - method: 'POST', - params: {}, - type: 'REST', - userId: '', - version: '1', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'group call without groupId', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - userId: 'user123', - type: 'group', - groupId: '', - traits: { - subscribe: true, - }, - context: { - traits: { - email: 'test@rudderstack.com', - phone: '+12 345 678 900', - consent: 'email', - }, - ip: '14.5.67.21', - library: { - name: 'http', - }, - }, - timestamp: '2020-01-21T00:21:34.208Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - error: 'groupId is a required field for group events', - statTags: { - destType: 'KLAVIYO', - errorCategory: 'dataValidation', - errorType: 'instrumentation', - feature: 'processor', - implementation: 'native', - module: 'destination', - }, - statusCode: 400, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: '[Error]: Check for unsupported message type', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - userId: 'user123', - type: 'random', - groupId: 'XUepkK', - traits: { - subscribe: true, - }, - context: { - traits: { - email: 'test@rudderstack.com', - phone: '+12 345 678 900', - consent: 'email', - }, - ip: '14.5.67.21', - library: { - name: 'http', - }, - }, - timestamp: '2020-01-21T00:21:34.208Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - error: 'Event type random is not supported', - statTags: { - destType: 'KLAVIYO', - errorCategory: 'dataValidation', - errorType: 'instrumentation', - feature: 'processor', - implementation: 'native', - module: 'destination', - }, - statusCode: 400, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track call with Ecom events (Viewed Product)', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'track', - event: 'product viewed', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - name: 'Test', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - description: 'Sample description', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - name: 'test product', - product_id: '1114', - sku: 'WINNIePuh12', - image_url: 'http://www.example.com/path/to/product/image.png', - url: 'http://www.example.com/path/to/product', - brand: 'Not for Kids', - price: 9.9, - categories: ['Fiction', 'Children'], - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'Viewed Product', - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - $id: 'sajal12', - age: '22', - name: 'Test', - description: 'Sample description', - }, - properties: { - ProductName: 'test product', - ProductID: '1114', - SKU: 'WINNIePuh12', - ImageURL: 'http://www.example.com/path/to/product/image.png', - URL: 'http://www.example.com/path/to/product', - Brand: 'Not for Kids', - Price: 9.9, - Categories: ['Fiction', 'Children'], - }, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track event call -> Invalid event i.e. sent as non-string', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'track', - event: { name: 'TestEven002' }, - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - name: 'Test', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - description: 'Sample description', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - PreviouslyVicePresident: true, - YearElected: 1801, - VicePresidents: ['Aaron Burr', 'George Clinton'], - revenue: 3000, - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - error: 'Event type should be a string', - statTags: { - destType: 'KLAVIYO', - errorCategory: 'dataValidation', - errorType: 'instrumentation', - feature: 'processor', - implementation: 'native', - module: 'destination', - }, - statusCode: 400, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track call with Ecom events (Checkout Started) with enabled flattenProperties', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - flattenProperties: true, - }, - }, - message: { - type: 'track', - event: 'checkout started', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - name: 'Test', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - description: 'Sample description', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - order_id: '1234', - affiliation: 'Apple Store', - value: 20, - revenue: 15, - shipping: 4, - tax: 1, - discount: 1.5, - coupon: 'ImagePro', - currency: 'USD', - products: [ - { - product_id: '123', - sku: 'G-32', - name: 'Monopoly', - price: 14, - quantity: 1, - category: 'Games', - url: 'https://www.website.com/product/path', - image_url: 'https://www.website.com/product/path.jpg', - }, - { - product_id: '345', - sku: 'F-32', - name: 'UNO', - price: 3.45, - quantity: 2, - category: 'Games', - }, - ], - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'Started Checkout', - }, - properties: { - $event_id: '1234', - $value: 20, - 'items[0].ProductID': '123', - 'items[0].SKU': 'G-32', - 'items[0].ProductName': 'Monopoly', - 'items[0].Quantity': 1, - 'items[0].ItemPrice': 14, - 'items[0].ProductURL': 'https://www.website.com/product/path', - 'items[0].ImageURL': 'https://www.website.com/product/path.jpg', - 'items[1].ProductID': '345', - 'items[1].SKU': 'F-32', - 'items[1].ProductName': 'UNO', - 'items[1].Quantity': 2, - 'items[1].ItemPrice': 3.45, - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - $id: 'sajal12', - age: '22', - name: 'Test', - description: 'Sample description', - }, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, - { - name: 'klaviyo', - description: 'Track call with Ecom events (Added to Cart) with properties.products', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination: { - Config: { - publicApiKey: 'dummyPublicApiKey', - privateApiKey: 'dummyPrivateApiKey', - }, - }, - message: { - type: 'track', - event: 'product added', - sentAt: '2021-01-25T16:12:02.048Z', - userId: 'sajal12', - channel: 'mobile', - context: { - os: { - name: 'Android', - version: '10', - }, - app: { - name: 'KlaviyoTest', - build: '1', - version: '1.0', - namespace: 'com.rudderstack.android.rudderstack.sampleAndroidApp', - }, - device: { - id: '9c6bd77ea9da3e68', - name: 'raphaelin', - type: 'android', - model: 'Redmi K20 Pro', - manufacturer: 'Xiaomi', - }, - locale: 'en-IN', - screen: { - width: 1080, - height: 2210, - density: 440, - }, - traits: { - id: 'user@1', - age: '22', - name: 'Test', - email: 'test@rudderstack.com', - phone: '9112340375', - anonymousId: '9c6bd77ea9da3e68', - description: 'Sample description', - }, - library: { - name: 'com.rudderstack.android.sdk.core', - version: '1.0.2', - }, - network: { - wifi: true, - carrier: 'airtel', - cellular: true, - bluetooth: false, - }, - timezone: 'Asia/Kolkata', - userAgent: - 'Dalvik/2.1.0 (Linux; U; Android 10; Redmi K20 Pro MIUI/V12.0.4.0.QFKINXM)', - }, - rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', - messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', - properties: { - order_id: '1234', - value: 12.12, - categories: ['Fiction3', 'Children3'], - checkout_url: 'http://www.heythere.com', - item_names: ['book1', 'book2'], - products: [ - { - product_id: 'b1pid', - sku: '123x', - name: 'book1', - url: 'heyther.com', - price: 12, - }, - { - product_id: 'b2pid', - sku: '123x', - name: 'book2', - url: 'heyther2.com', - price: 14, - }, - ], - }, - anonymousId: '9c6bd77ea9da3e68', - integrations: { - All: true, - }, - originalTimestamp: '2021-01-25T15:32:56.409Z', - }, - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - output: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://a.klaviyo.com/api/events', - headers: { - Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', - 'Content-Type': 'application/json', - Accept: 'application/json', - revision: '2023-02-22', - }, - params: {}, - body: { - JSON: { - data: { - type: 'event', - attributes: { - metric: { - name: 'Added to Cart', - }, - profile: { - $email: 'test@rudderstack.com', - $phone_number: '9112340375', - $id: 'sajal12', - age: '22', - name: 'Test', - description: 'Sample description', - }, - properties: { - $value: 12.12, - AddedItemCategories: ['Fiction3', 'Children3'], - ItemNames: ['book1', 'book2'], - CheckoutURL: 'http://www.heythere.com', - items: [ - { - ProductID: 'b1pid', - SKU: '123x', - ProductName: 'book1', - ItemPrice: 12, - ProductURL: 'heyther.com', - }, - { - ProductID: 'b2pid', - SKU: '123x', - ProductName: 'book2', - ItemPrice: 14, - ProductURL: 'heyther2.com', - }, - ], - }, - }, - }, - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - statusCode: 200, - }, - ], - }, - }, - }, + ...identifyData, + ...trackTestData, + ...screenTestData, + ...groupTestData, + ...ecomTestData, + ...validationTestData, ]; diff --git a/test/integrations/destinations/klaviyo/processor/ecomTestData.ts b/test/integrations/destinations/klaviyo/processor/ecomTestData.ts new file mode 100644 index 0000000000..fab4cf85ce --- /dev/null +++ b/test/integrations/destinations/klaviyo/processor/ecomTestData.ts @@ -0,0 +1,344 @@ +import { overrideDestination, transformResultBuilder } from '../../../testUtils'; + +const destination = { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKey', + }, +}; + +const commonTraits = { + id: 'user@1', + age: '22', + name: 'Test', + email: 'test@rudderstack.com', + phone: '9112340375', + anonymousId: '9c6bd77ea9da3e68', + description: 'Sample description', +}; + +const eventsEndpoint = 'https://a.klaviyo.com/api/events'; + +const commonOutputHeaders = { + Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', + 'Content-Type': 'application/json', + Accept: 'application/json', + revision: '2023-02-22', +}; + +export const ecomTestData = [ + { + id: 'klaviyo-ecom-test-1', + name: 'klaviyo', + description: 'Track call with Ecom events (Viewed Product)', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain contextual traits and properties in the payload the event name should be Viewed Product and the properties should be mapped to the Klaviyo event properties', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: { + type: 'track', + event: 'product viewed', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + channel: 'mobile', + context: { + traits: commonTraits, + }, + properties: { + name: 'test product', + product_id: '1114', + sku: 'WINNIePuh12', + image_url: 'http://www.example.com/path/to/product/image.png', + url: 'http://www.example.com/path/to/product', + brand: 'Not for Kids', + price: 9.9, + categories: ['Fiction', 'Children'], + }, + anonymousId: '9c6bd77ea9da3e68', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: eventsEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'Viewed Product', + }, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + $id: 'sajal12', + age: '22', + name: 'Test', + description: 'Sample description', + }, + properties: { + ProductName: 'test product', + ProductID: '1114', + SKU: 'WINNIePuh12', + ImageURL: 'http://www.example.com/path/to/product/image.png', + URL: 'http://www.example.com/path/to/product', + Brand: 'Not for Kids', + Price: 9.9, + Categories: ['Fiction', 'Children'], + }, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-ecom-test-2', + name: 'klaviyo', + description: 'Track call with Ecom events (Checkout Started) with enabled flattenProperties', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain contextual traits and properties in the payload the event name should be Started Checkout and the properties should be mapped to the Klaviyo event properties with flattened properties', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { flattenProperties: true }), + message: { + type: 'track', + event: 'checkout started', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + channel: 'mobile', + context: { + traits: commonTraits, + }, + properties: { + order_id: '1234', + affiliation: 'Apple Store', + value: 20, + revenue: 15, + shipping: 4, + tax: 1, + discount: 1.5, + coupon: 'ImagePro', + currency: 'USD', + products: [ + { + product_id: '123', + sku: 'G-32', + name: 'Monopoly', + price: 14, + quantity: 1, + category: 'Games', + url: 'https://www.website.com/product/path', + image_url: 'https://www.website.com/product/path.jpg', + }, + { + product_id: '345', + sku: 'F-32', + name: 'UNO', + price: 3.45, + quantity: 2, + category: 'Games', + }, + ], + }, + anonymousId: '9c6bd77ea9da3e68', + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: eventsEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'Started Checkout', + }, + properties: { + $event_id: '1234', + $value: 20, + 'items[0].ProductID': '123', + 'items[0].SKU': 'G-32', + 'items[0].ProductName': 'Monopoly', + 'items[0].Quantity': 1, + 'items[0].ItemPrice': 14, + 'items[0].ProductURL': 'https://www.website.com/product/path', + 'items[0].ImageURL': 'https://www.website.com/product/path.jpg', + 'items[1].ProductID': '345', + 'items[1].SKU': 'F-32', + 'items[1].ProductName': 'UNO', + 'items[1].Quantity': 2, + 'items[1].ItemPrice': 3.45, + }, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + $id: 'sajal12', + age: '22', + name: 'Test', + description: 'Sample description', + }, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-ecom-test-3', + name: 'klaviyo', + description: 'Track call with Ecom events (Added to Cart) with properties.products', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain contextual traits and properties in the payload the event name should be Added to Cart and the properties should be mapped to the Klaviyo event properties with flattened properties and products array should be mapped to items array in the payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: { + type: 'track', + event: 'product added', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + channel: 'mobile', + context: { + traits: commonTraits, + }, + rudderId: 'b7b24f86-f7bf-46d8-b2b4-ccafc080239c', + messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce', + properties: { + order_id: '1234', + value: 12.12, + categories: ['Fiction3', 'Children3'], + checkout_url: 'http://www.heythere.com', + item_names: ['book1', 'book2'], + products: [ + { + product_id: 'b1pid', + sku: '123x', + name: 'book1', + url: 'heyther.com', + price: 12, + }, + { + product_id: 'b2pid', + sku: '123x', + name: 'book2', + url: 'heyther2.com', + price: 14, + }, + ], + }, + anonymousId: '9c6bd77ea9da3e68', + integrations: { + All: true, + }, + originalTimestamp: '2021-01-25T15:32:56.409Z', + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: 'https://a.klaviyo.com/api/events', + headers: commonOutputHeaders, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'Added to Cart', + }, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + $id: 'sajal12', + age: '22', + name: 'Test', + description: 'Sample description', + }, + properties: { + $value: 12.12, + AddedItemCategories: ['Fiction3', 'Children3'], + ItemNames: ['book1', 'book2'], + CheckoutURL: 'http://www.heythere.com', + items: [ + { + ProductID: 'b1pid', + SKU: '123x', + ProductName: 'book1', + ItemPrice: 12, + ProductURL: 'heyther.com', + }, + { + ProductID: 'b2pid', + SKU: '123x', + ProductName: 'book2', + ItemPrice: 14, + ProductURL: 'heyther2.com', + }, + ], + }, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, +]; diff --git a/test/integrations/destinations/klaviyo/processor/groupTestData.ts b/test/integrations/destinations/klaviyo/processor/groupTestData.ts new file mode 100644 index 0000000000..031c949c4b --- /dev/null +++ b/test/integrations/destinations/klaviyo/processor/groupTestData.ts @@ -0,0 +1,136 @@ +import { generateSimplifiedGroupPayload, transformResultBuilder } from '../../../testUtils'; + +const destination = { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKey', + }, +}; + +const headers = { + Accept: 'application/json', + Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', + 'Content-Type': 'application/json', + revision: '2023-02-22', +}; + +const commonEndpoint = 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs'; + +export const groupTestData = [ + { + id: 'klaviyo-group-test-1', + name: 'klaviyo', + description: 'Simple group call', + scenario: 'Business', + successCriteria: + 'Response should contain only group payload and status code should be 200, for the group payload a subscription payload should be present in the final payload with email and phone', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: generateSimplifiedGroupPayload({ + userId: 'user123', + groupId: 'XUepkK', + traits: { + subscribe: true, + }, + context: { + traits: { + email: 'test@rudderstack.com', + phone: '+12 345 678 900', + consent: ['email'], + }, + }, + timestamp: '2020-01-21T00:21:34.208Z', + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + JSON: { + data: { + attributes: { + list_id: 'XUepkK', + subscriptions: [ + { email: 'test@rudderstack.com', phone_number: '+12 345 678 900' }, + ], + }, + type: 'profile-subscription-bulk-create-job', + }, + }, + endpoint: commonEndpoint, + headers: headers, + method: 'POST', + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-group-test-2', + name: 'klaviyo', + description: 'Simple group call without groupId', + scenario: 'Business', + successCriteria: + 'Response should contain error message and status code should be 400, as we are not sending groupId in the payload and groupId is a required field for group events', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: generateSimplifiedGroupPayload({ + userId: 'user123', + groupId: '', + traits: { + subscribe: true, + }, + context: { + traits: { + email: 'test@rudderstack.com', + phone: '+12 345 678 900', + consent: 'email', + }, + }, + timestamp: '2020-01-21T00:21:34.208Z', + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + error: 'groupId is a required field for group events', + statTags: { + destType: 'KLAVIYO', + errorCategory: 'dataValidation', + errorType: 'instrumentation', + feature: 'processor', + implementation: 'native', + module: 'destination', + }, + statusCode: 400, + }, + ], + }, + }, + }, +]; diff --git a/test/integrations/destinations/klaviyo/processor/identifyTestData.ts b/test/integrations/destinations/klaviyo/processor/identifyTestData.ts new file mode 100644 index 0000000000..8b5503fad9 --- /dev/null +++ b/test/integrations/destinations/klaviyo/processor/identifyTestData.ts @@ -0,0 +1,551 @@ +import { removeUndefinedAndNullValues } from '@rudderstack/integrations-lib'; +import { + overrideDestination, + transformResultBuilder, + generateSimplifiedIdentifyPayload, +} from '../../../testUtils'; + +const destination = { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKey', + }, +}; + +const commonTraits = { + firstName: 'Test', + lastName: 'Rudderlabs', + email: 'test@rudderstack.com', + phone: '+12 345 578 900', + userId: 'user@1', + title: 'Developer', + organization: 'Rudder', + city: 'Tokyo', + region: 'Kanto', + country: 'JP', + zip: '100-0001', + Flagged: false, + Residence: 'Shibuya', + properties: { + listId: 'XUepkK', + subscribe: true, + consent: ['email', 'sms'], + }, +}; + +const commonOutputUserProps = { + external_id: 'user@1', + email: 'test@rudderstack.com', + first_name: 'Test', + last_name: 'Rudderlabs', + phone_number: '+12 345 578 900', + title: 'Developer', + organization: 'Rudder', + location: { + city: 'Tokyo', + region: 'Kanto', + country: 'JP', + zip: '100-0001', + }, + properties: { + Flagged: false, + Residence: 'Shibuya', + }, +}; + +const commonOutputSubscriptionProps = { + list_id: 'XUepkK', + subscriptions: [ + { + email: 'test@rudderstack.com', + phone_number: '+12 345 578 900', + channels: { + email: ['MARKETING'], + sms: ['MARKETING'], + }, + }, + ], +}; + +const commonOutputHeaders = { + Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', + 'Content-Type': 'application/json', + Accept: 'application/json', + revision: '2023-02-22', +}; + +const anonymousId = '97c46c81-3140-456d-b2a9-690d70aaca35'; +const userId = 'user@1'; +const sentAt = '2021-01-03T17:02:53.195Z'; +const originalTimestamp = '2021-01-03T17:02:53.193Z'; +const commonUserUpdateEndpoint = 'https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX'; +const subscribeEndpoint = 'https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs'; + +export const identifyData = [ + { + id: 'klaviyo-identify-test-1', + name: 'klaviyo', + description: + 'Identify and Subscribe user where the user doesnot exists[mock] (without suppression status code feature from server)', + scenario: 'Business + Framework', + successCriteria: + 'Response should containt two payloads one for profile updation and other for subscription, response status code should be 200', + comment: + 'Reasoning: As suppression status code feature is not enabled from server, so we would expect 2 responses from transformer one for profile updation (deafult behaviour) and other for subscription', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: generateSimplifiedIdentifyPayload({ + context: { + traits: commonTraits, + }, + anonymousId, + userId, + sentAt, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + userId: '', + method: 'PATCH', + endpoint: commonUserUpdateEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile', + attributes: commonOutputUserProps, + id: '01GW3PHVY0MTCDGS0A1612HARX', + }, + }, + }), + statusCode: 200, + }, + { + output: transformResultBuilder({ + method: 'POST', + userId: '', + endpoint: subscribeEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile-subscription-bulk-create-job', + attributes: commonOutputSubscriptionProps, + }, + }, + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-identify-test-2', + name: 'klaviyo', + description: 'Identify call for with flattenProperties enabled in destination config', + scenario: 'Business', + successCriteria: + 'The profile updation response should contain the flattened properties of the friend object', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { flattenProperties: true }), + message: generateSimplifiedIdentifyPayload({ + sentAt, + userId, + context: { + traits: { + ...commonTraits, + friend: { + names: { + first: 'Alice', + last: 'Smith', + }, + age: 25, + }, + }, + }, + anonymousId, + originalTimestamp, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + userId: '', + method: 'PATCH', + endpoint: commonUserUpdateEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile', + id: '01GW3PHVY0MTCDGS0A1612HARX', + attributes: { + ...commonOutputUserProps, + properties: { + ...commonOutputUserProps.properties, + 'friend.age': 25, + 'friend.names.first': 'Alice', + 'friend.names.last': 'Smith', + }, + }, + }, + }, + }), + statusCode: 200, + }, + { + output: transformResultBuilder({ + userId: '', + method: 'POST', + endpoint: subscribeEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile-subscription-bulk-create-job', + attributes: commonOutputSubscriptionProps, + }, + }, + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-identify-test-3', + name: 'klaviyo', + description: 'Negative Test Case for Profile updation call and subcribe user', + scenario: 'Business + Framework', + successCriteria: + 'Response should contain error message and status code should be 500, as we are getting a network error from klaviyo', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKeyforfailure', + }, + }, + message: generateSimplifiedIdentifyPayload({ + sentAt, + userId, + context: { + traits: { + ...commonTraits, + email: 'test3@rudderstack.com', + }, + }, + anonymousId, + originalTimestamp, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + error: + '{"message":"Failed to create user due to \\"\\"","destinationResponse":"\\"\\""}', + statTags: { + destType: 'KLAVIYO', + errorCategory: 'network', + errorType: 'retryable', + feature: 'processor', + implementation: 'native', + module: 'destination', + }, + statusCode: 500, + }, + ], + }, + }, + }, + { + id: 'klaviyo-identify-test-4', + name: 'klaviyo', + description: 'Profile create update without subscribing the user', + scenario: 'Business', + successCriteria: + 'Response should contain only profile update payload and status code should be 200 as subscribe is set to false in the payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: generateSimplifiedIdentifyPayload({ + sentAt, + userId, + context: { + traits: { + ...commonTraits, + properties: { ...commonTraits.properties, subscribe: false }, + }, + }, + anonymousId, + originalTimestamp, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'PATCH', + endpoint: commonUserUpdateEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile', + attributes: commonOutputUserProps, + id: '01GW3PHVY0MTCDGS0A1612HARX', + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-identify-test-5', + name: 'klaviyo', + description: 'Identify call with enforceEmailAsPrimary enabled in destination config', + scenario: 'Business', + successCriteria: + 'Response should contain two payloads one for profile updation and other for subscription, response status code should be 200, for the profile updation payload there should be no external_id field in the payload as enforceEmailAsPrimary is set to true in the destination config and the userId should be mapped to _id field in the properties object', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { enforceEmailAsPrimary: true }), + message: generateSimplifiedIdentifyPayload({ + sentAt, + userId, + context: { + traits: commonTraits, + }, + anonymousId, + originalTimestamp, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + userId: '', + method: 'PATCH', + endpoint: commonUserUpdateEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile', + attributes: removeUndefinedAndNullValues({ + ...commonOutputUserProps, + properties: { + ...commonOutputUserProps.properties, + _id: userId, + }, + // remove external_id from the payload + external_id: undefined, + }), + id: '01GW3PHVY0MTCDGS0A1612HARX', + }, + }, + }), + statusCode: 200, + }, + { + output: transformResultBuilder({ + userId: '', + method: 'POST', + endpoint: subscribeEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile-subscription-bulk-create-job', + attributes: commonOutputSubscriptionProps, + }, + }, + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-identify-test-6', + name: 'klaviyo', + description: 'Identify call without user custom Properties', + scenario: 'Business', + successCriteria: + 'Response should contain two payloads one for profile updation and other for subscription, response status code should be 200, for the profile updation payload does not have any custom properties in the payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: destination, + message: generateSimplifiedIdentifyPayload({ + sentAt, + userId, + context: { + traits: removeUndefinedAndNullValues({ + ...commonTraits, + Flagged: undefined, + Residence: undefined, + }), + }, + anonymousId, + originalTimestamp, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + userId: '', + method: 'PATCH', + endpoint: commonUserUpdateEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile', + attributes: removeUndefinedAndNullValues({ + ...commonOutputUserProps, + properties: undefined, + }), + id: '01GW3PHVY0MTCDGS0A1612HARX', + }, + }, + }), + statusCode: 200, + }, + { + output: transformResultBuilder({ + userId: '', + method: 'POST', + endpoint: subscribeEndpoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'profile-subscription-bulk-create-job', + attributes: commonOutputSubscriptionProps, + }, + }, + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-identify-test-7', + name: 'klaviyo', + description: 'Identify call without email and phone & enforceEmailAsPrimary enabled from UI', + scenario: 'Business', + successCriteria: + 'Response should contain error message and status code should be 400, as we are not sending email and phone in the payload and enforceEmailAsPrimary is enabled from UI', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { enforceEmailAsPrimary: true }), + message: generateSimplifiedIdentifyPayload({ + sentAt, + userId, + context: { + traits: removeUndefinedAndNullValues({ + ...commonTraits, + email: undefined, + phone: undefined, + }), + }, + anonymousId, + originalTimestamp, + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + error: 'None of email and phone are present in the payload', + statTags: { + destType: 'KLAVIYO', + errorCategory: 'dataValidation', + errorType: 'instrumentation', + feature: 'processor', + implementation: 'native', + module: 'destination', + }, + statusCode: 400, + }, + ], + }, + }, + }, +]; diff --git a/test/integrations/destinations/klaviyo/processor/screenTestData.ts b/test/integrations/destinations/klaviyo/processor/screenTestData.ts new file mode 100644 index 0000000000..3779747a4e --- /dev/null +++ b/test/integrations/destinations/klaviyo/processor/screenTestData.ts @@ -0,0 +1,97 @@ +import { generateSimplifiedPageOrScreenPayload, transformResultBuilder } from '../../../testUtils'; + +const destination = { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKey', + }, +}; + +export const screenTestData = [ + { + id: 'klaviyo-screen-test-1', + name: 'klaviyo', + description: 'Screen event call with properties and contextual traits', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain properties and contextual traits in the payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: generateSimplifiedPageOrScreenPayload( + { + event: 'TestEven001', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + context: { + traits: { + id: 'user@1', + age: '22', + email: 'test@rudderstack.com', + phone: '9112340375', + anonymousId: '9c6bd77ea9da3e68', + }, + }, + properties: { + PreviouslyVicePresident: true, + YearElected: 1801, + VicePresidents: ['Aaron Burr', 'George Clinton'], + }, + anonymousId: '9c6bd77ea9da3e68', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }, + 'screen', + ), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: 'https://a.klaviyo.com/api/events', + headers: { + Accept: 'application/json', + Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', + 'Content-Type': 'application/json', + revision: '2023-02-22', + }, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'TestEven001', + }, + properties: { + PreviouslyVicePresident: true, + YearElected: 1801, + VicePresidents: ['Aaron Burr', 'George Clinton'], + }, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + $id: 'sajal12', + age: '22', + }, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, +]; diff --git a/test/integrations/destinations/klaviyo/processor/trackTestData.ts b/test/integrations/destinations/klaviyo/processor/trackTestData.ts new file mode 100644 index 0000000000..f3bbfb96b9 --- /dev/null +++ b/test/integrations/destinations/klaviyo/processor/trackTestData.ts @@ -0,0 +1,316 @@ +import { + generateSimplifiedTrackPayload, + generateTrackPayload, + overrideDestination, + transformResultBuilder, +} from '../../../testUtils'; + +const destination = { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKey', + }, +}; + +const commonTraits = { + id: 'user@1', + age: '22', + anonymousId: '9c6bd77ea9da3e68', +}; + +const commonProps = { + PreviouslVicePresident: true, + YearElected: 1801, + VicePresidents: ['AaronBurr', 'GeorgeClinton'], +}; + +const commonOutputHeaders = { + Accept: 'application/json', + Authorization: 'Klaviyo-API-Key dummyPrivateApiKey', + 'Content-Type': 'application/json', + revision: '2023-02-22', +}; + +const eventEndPoint = 'https://a.klaviyo.com/api/events'; + +export const trackTestData = [ + { + id: 'klaviyo-track-test-1', + name: 'klaviyo', + description: 'Track event call with flatten properties enabled in destination config', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain flattened properties in the payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { flattenProperties: true }), + message: generateSimplifiedTrackPayload({ + type: 'track', + event: 'TestEven001', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + context: { + traits: { + ...commonTraits, + email: 'test@rudderstack.com', + phone: '9112340375', + plan_details: { + plan_type: 'gold', + duration: '3 months', + }, + }, + }, + properties: { + vicePresdentInfo: commonProps, + }, + anonymousId: '9c6bd77ea9da3e68', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: eventEndPoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'TestEven001', + }, + properties: { + 'vicePresdentInfo.PreviouslVicePresident': true, + 'vicePresdentInfo.VicePresidents': ['AaronBurr', 'GeorgeClinton'], + 'vicePresdentInfo.YearElected': 1801, + }, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + $id: 'sajal12', + age: '22', + 'plan_details.plan_type': 'gold', + 'plan_details.duration': '3 months', + }, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-track-test-2', + name: 'klaviyo', + description: 'Simple track event call', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain contextual traits and properties in the payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination, + message: generateSimplifiedTrackPayload({ + type: 'track', + event: 'TestEven002', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + context: { + traits: { + ...commonTraits, + name: 'Test', + email: 'test@rudderstack.com', + phone: '9112340375', + description: 'Sample description', + }, + }, + properties: { + ...commonProps, + revenue: 3000, + }, + anonymousId: '9c6bd77ea9da3e68', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: eventEndPoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'TestEven002', + }, + properties: commonProps, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + $id: 'sajal12', + age: '22', + name: 'Test', + description: 'Sample description', + }, + value: 3000, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-track-test-3', + name: 'klaviyo', + description: 'Track event call, with make email or phone as primary identifier toggle on', + scenario: 'Business', + successCriteria: + 'Response should contain only event payload and status code should be 200, for the event payload should contain contextual traits and properties in the payload, and email should be mapped to $email and userId should be mapped to _id', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { enforceEmailAsPrimary: true }), + message: generateSimplifiedTrackPayload({ + type: 'track', + event: 'TestEven001', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + context: { + traits: { + ...commonTraits, + email: 'test@rudderstack.com', + phone: '9112340375', + }, + }, + properties: commonProps, + anonymousId: '9c6bd77ea9da3e68', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + endpoint: eventEndPoint, + headers: commonOutputHeaders, + JSON: { + data: { + type: 'event', + attributes: { + metric: { + name: 'TestEven001', + }, + properties: commonProps, + profile: { + $email: 'test@rudderstack.com', + $phone_number: '9112340375', + age: '22', + _id: 'sajal12', + }, + }, + }, + }, + userId: '', + }), + statusCode: 200, + }, + ], + }, + }, + }, + { + id: 'klaviyo-track-test-4', + name: 'klaviyo', + description: + 'Track event call, without email and phone & with (make email or phone as primary identifier) toggle on', + scenario: 'Business', + successCriteria: + 'Response should contain error message and status code should be 400, as we are not sending email and phone in the payload and enforceEmailAsPrimary is enabled from UI', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: overrideDestination(destination, { enforceEmailAsPrimary: true }), + message: generateSimplifiedTrackPayload({ + type: 'track', + event: 'TestEven001', + sentAt: '2021-01-25T16:12:02.048Z', + userId: 'sajal12', + context: { + traits: commonTraits, + }, + properties: commonProps, + anonymousId: '9c6bd77ea9da3e68', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + error: 'None of email and phone are present in the payload', + statTags: { + destType: 'KLAVIYO', + errorCategory: 'dataValidation', + errorType: 'instrumentation', + feature: 'processor', + implementation: 'native', + module: 'destination', + }, + statusCode: 400, + }, + ], + }, + }, + }, +]; diff --git a/test/integrations/destinations/klaviyo/processor/validationTestData.ts b/test/integrations/destinations/klaviyo/processor/validationTestData.ts new file mode 100644 index 0000000000..59556cfe5f --- /dev/null +++ b/test/integrations/destinations/klaviyo/processor/validationTestData.ts @@ -0,0 +1,62 @@ +export const validationTestData = [ + { + id: 'klaviyo-validation-test-1', + name: 'klaviyo', + description: '[Error]: Check for unsupported message type', + scenario: 'Framework', + successCriteria: + 'Response should contain error message and status code should be 400, as we are sending a message type which is not supported by Klaviyo destination and the error message should be Event type random is not supported', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: { + Config: { + publicApiKey: 'dummyPublicApiKey', + privateApiKey: 'dummyPrivateApiKey', + }, + }, + message: { + userId: 'user123', + type: 'random', + groupId: 'XUepkK', + traits: { + subscribe: true, + }, + context: { + traits: { + email: 'test@rudderstack.com', + phone: '+12 345 678 900', + consent: 'email', + }, + }, + timestamp: '2020-01-21T00:21:34.208Z', + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + error: 'Event type random is not supported', + statTags: { + destType: 'KLAVIYO', + errorCategory: 'dataValidation', + errorType: 'instrumentation', + feature: 'processor', + implementation: 'native', + module: 'destination', + }, + statusCode: 400, + }, + ], + }, + }, + }, +]; diff --git a/test/integrations/destinations/klaviyo/router/data.ts b/test/integrations/destinations/klaviyo/router/data.ts index 0fb735d6bf..83b494199c 100644 --- a/test/integrations/destinations/klaviyo/router/data.ts +++ b/test/integrations/destinations/klaviyo/router/data.ts @@ -1,7 +1,10 @@ export const data = [ { + id: 'klaviyo-router-test-1', name: 'klaviyo', - description: 'Test 0', + description: 'Basic Router Test to test multiple payloads', + scenario: 'Framework', + successCriteria: 'All the subscription events should be batched', feature: 'router', module: 'destination', version: 'v0', diff --git a/test/integrations/destinations/tiktok_ads/mocks.ts b/test/integrations/destinations/tiktok_ads/mocks.ts index 6003027d23..a5d8fc4a63 100644 --- a/test/integrations/destinations/tiktok_ads/mocks.ts +++ b/test/integrations/destinations/tiktok_ads/mocks.ts @@ -1,6 +1,5 @@ import config from '../../../../src/v0/destinations/tiktok_ads/config'; export const defaultMockFns = () => { - - jest.replaceProperty(config, 'maxBatchSizeV2', 3) - }; + jest.replaceProperty(config, 'maxBatchSizeV2', 3); +}; diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index 21a12e5174..334dba9440 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -5141,7 +5141,7 @@ export const data = [ channel: 'web', context: { traits: { - email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f' + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', }, userAgent: 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', @@ -5176,7 +5176,7 @@ export const data = [ content_id: '1197218', }, ], - url: "http://demo.mywebsite.com/purchase", + url: 'http://demo.mywebsite.com/purchase', clickId: 'dummyclickId', currency: 'USD', value: 46, @@ -5225,7 +5225,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -5244,10 +5244,10 @@ export const data = [ value: 46, }, page: { - url: 'http://demo.mywebsite.com/purchase' + url: 'http://demo.mywebsite.com/purchase', }, user: { - locale: "en-US", + locale: 'en-US', email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', external_id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', @@ -5273,7 +5273,8 @@ export const data = [ }, { name: 'tiktok_ads', - description: 'Test 33 -> V2 -> Event mapped to one standard event with contents present as it is in properties', + description: + 'Test 33 -> V2 -> Event mapped to one standard event with contents present as it is in properties', feature: 'processor', module: 'destination', version: 'v0', @@ -5286,7 +5287,7 @@ export const data = [ channel: 'web', context: { traits: { - email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f' + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', }, page: { url: 'http://demo.mywebsite.com/purchase', @@ -5352,7 +5353,7 @@ export const data = [ { from: 'addToCart', to: 'download', - } + }, ], }, }, @@ -5386,7 +5387,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -5409,7 +5410,7 @@ export const data = [ referrer: 'http://demo.mywebsite.com', }, user: { - locale: "en-US", + locale: 'en-US', email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', external_id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', @@ -5448,10 +5449,10 @@ export const data = [ channel: 'web', context: { traits: { - email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f' + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', }, page: { - url: 'http://demo.mywebsite.com/purchase' + url: 'http://demo.mywebsite.com/purchase', }, userAgent: 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', @@ -5517,7 +5518,7 @@ export const data = [ { from: 'AddToCart', to: 'AddToWishlist', - } + }, ], }, }, @@ -5551,7 +5552,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -5573,7 +5574,7 @@ export const data = [ url: 'http://demo.mywebsite.com/purchase', }, user: { - locale: "en-US", + locale: 'en-US', email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', external_id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', @@ -5587,7 +5588,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -5609,7 +5610,7 @@ export const data = [ url: 'http://demo.mywebsite.com/purchase', }, user: { - locale: "en-US", + locale: 'en-US', email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', external_id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', @@ -5657,7 +5658,10 @@ export const data = [ externalId: [ { type: 'tiktokExternalId', - id: ['f0e388f53921a51f0bb0fc8a2944109ec188b5', '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc'], + id: [ + 'f0e388f53921a51f0bb0fc8a2944109ec188b5', + '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + ], }, ], }, @@ -5687,8 +5691,7 @@ export const data = [ currency: 'USD', value: 46, phone: ['+12345432', '+134234325'], - email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f' - + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', }, integrations: { All: true, @@ -5710,7 +5713,7 @@ export const data = [ { from: 'AddToCart', to: 'AddToWishlist', - } + }, ], }, }, @@ -5744,7 +5747,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -5769,7 +5772,10 @@ export const data = [ user: { phone: ['+12345432', '+134234325'], email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', - external_id: ['f0e388f53921a51f0bb0fc8a2944109ec188b5', '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc'], + external_id: [ + 'f0e388f53921a51f0bb0fc8a2944109ec188b5', + '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + ], ip: '13.57.97.131', user_agent: 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', @@ -5780,7 +5786,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -5805,7 +5811,10 @@ export const data = [ user: { phone: ['+12345432', '+134234325'], email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', - external_id: ['f0e388f53921a51f0bb0fc8a2944109ec188b5', '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc'], + external_id: [ + 'f0e388f53921a51f0bb0fc8a2944109ec188b5', + '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + ], ip: '13.57.97.131', user_agent: 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', @@ -5841,7 +5850,7 @@ export const data = [ channel: 'web', context: { traits: { - email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f' + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', }, page: { url: 'http://demo.mywebsite.com/purchase', @@ -5979,7 +5988,7 @@ export const data = [ accessToken: 'dummyAccessToken', pixelCode: '{{PIXEL-CODE}}', hashUserProperties: false, - version: 'v2' + version: 'v2', }, }, }, @@ -5992,8 +6001,7 @@ export const data = [ body: [ { statusCode: 400, - error: - 'Event type is required', + error: 'Event type is required', statTags: { errorCategory: 'dataValidation', errorType: 'instrumentation', @@ -6048,8 +6056,7 @@ export const data = [ body: [ { statusCode: 400, - error: - 'Event name is required', + error: 'Event name is required', statTags: { errorCategory: 'dataValidation', errorType: 'instrumentation', @@ -6103,8 +6110,7 @@ export const data = [ body: [ { statusCode: 400, - error: - 'Access Token not found. Aborting', + error: 'Access Token not found. Aborting', statTags: { errorCategory: 'dataValidation', errorType: 'configuration', @@ -6158,8 +6164,7 @@ export const data = [ body: [ { statusCode: 400, - error: - 'Pixel Code not found. Aborting', + error: 'Pixel Code not found. Aborting', statTags: { errorCategory: 'dataValidation', errorType: 'configuration', @@ -6188,7 +6193,7 @@ export const data = [ channel: 'web', context: { traits: { - email: 'abc@xyz.com' + email: 'abc@xyz.com', }, page: { url: 'http://demo.mywebsite.com/purchase', @@ -6200,7 +6205,10 @@ export const data = [ externalId: [ { type: 'tiktokExternalId', - id: ['f0e388f53921a51f0bb0fc8a2944109ec188b5', '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc'], + id: [ + 'f0e388f53921a51f0bb0fc8a2944109ec188b5', + '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + ], }, ], }, @@ -6229,7 +6237,7 @@ export const data = [ clickId: 'dummyclickId', currency: 'USD', value: 46, - phone: ['+12345432', '+134234325'] + phone: ['+12345432', '+134234325'], }, integrations: { All: true, @@ -6251,7 +6259,7 @@ export const data = [ { from: 'AddToCart', to: 'AddToWishlist', - } + }, ], }, }, @@ -6285,7 +6293,7 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", + content_type: 'product', contents: [ { price: 8, @@ -6309,16 +6317,19 @@ export const data = [ }, user: { email: 'ee278943de84e5d6243578ee1a1057bcce0e50daad9755f45dfa64b60b13bc5d', - external_id: ["3e0c7a51acd326b87f29596e38c22cbeb732df37bc5c8f5f524c14b55d3472db", "f8be04e62f5a3eba31c8b9380843666f28f3ab5f44a380f47fac04e9ce7b2168",], + external_id: [ + '3e0c7a51acd326b87f29596e38c22cbeb732df37bc5c8f5f524c14b55d3472db', + 'f8be04e62f5a3eba31c8b9380843666f28f3ab5f44a380f47fac04e9ce7b2168', + ], ip: '13.57.97.131', phone: [ - "49a15e38bdc2572d362a924c2ddd100baed0fe29db44270d3700fcef03b18c39", - "5a6a7a09b18278e220312ce26d711ff7c8263d0965ee3b1d26b1b6f0ac7e71b3", + '49a15e38bdc2572d362a924c2ddd100baed0fe29db44270d3700fcef03b18c39', + '5a6a7a09b18278e220312ce26d711ff7c8263d0965ee3b1d26b1b6f0ac7e71b3', ], user_agent: 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', }, - } + }, ], }, JSON_ARRAY: {}, @@ -6349,7 +6360,7 @@ export const data = [ channel: 'web', context: { traits: { - email: 'abc@xyz.com' + email: 'abc@xyz.com', }, page: { url: 'http://demo.mywebsite.com/purchase', @@ -6361,7 +6372,10 @@ export const data = [ externalId: [ { type: 'tiktokExternalId', - id: ['f0e388f53921a51f0bb0fc8a2944109ec188b5', '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc'], + id: [ + 'f0e388f53921a51f0bb0fc8a2944109ec188b5', + '1f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + ], }, ], }, @@ -6374,8 +6388,8 @@ export const data = [ properties: { order_id: 1234, shop_id: 4567, - description: "Viewed games", - query: "New age games", + description: 'Viewed games', + query: 'New age games', contentType: 'product_group', eventId: '1616318632825_357', products: [ @@ -6402,7 +6416,7 @@ export const data = [ clickId: 'dummyclickId', currency: 'USD', value: 46, - phone: ['+12345432', '+134234325'] + phone: ['+12345432', '+134234325'], }, integrations: { All: true, @@ -6424,7 +6438,7 @@ export const data = [ { from: 'AddToCart', to: 'AddToWishlist', - } + }, ], }, }, @@ -6458,11 +6472,11 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - order_id: "1234", - shop_id: "4567", - description: "Viewed games", - query: "New age games", - content_type: "product_group", + order_id: '1234', + shop_id: '4567', + description: 'Viewed games', + query: 'New age games', + content_type: 'product_group', contents: [ { price: 14, @@ -6470,13 +6484,13 @@ export const data = [ content_category: 'Games', content_id: '123', content_name: 'Monopoly', - brand: 'adidas' + brand: 'adidas', }, { price: 3.45, quantity: 2, content_id: '345', - content_name: 'UNO' + content_name: 'UNO', }, ], currency: 'USD', @@ -6488,16 +6502,19 @@ export const data = [ }, user: { email: 'ee278943de84e5d6243578ee1a1057bcce0e50daad9755f45dfa64b60b13bc5d', - external_id: ["3e0c7a51acd326b87f29596e38c22cbeb732df37bc5c8f5f524c14b55d3472db", "f8be04e62f5a3eba31c8b9380843666f28f3ab5f44a380f47fac04e9ce7b2168",], + external_id: [ + '3e0c7a51acd326b87f29596e38c22cbeb732df37bc5c8f5f524c14b55d3472db', + 'f8be04e62f5a3eba31c8b9380843666f28f3ab5f44a380f47fac04e9ce7b2168', + ], ip: '13.57.97.131', phone: [ - "49a15e38bdc2572d362a924c2ddd100baed0fe29db44270d3700fcef03b18c39", - "5a6a7a09b18278e220312ce26d711ff7c8263d0965ee3b1d26b1b6f0ac7e71b3", + '49a15e38bdc2572d362a924c2ddd100baed0fe29db44270d3700fcef03b18c39', + '5a6a7a09b18278e220312ce26d711ff7c8263d0965ee3b1d26b1b6f0ac7e71b3', ], user_agent: 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', }, - } + }, ], }, JSON_ARRAY: {}, @@ -6528,7 +6545,7 @@ export const data = [ channel: 'web', context: { traits: { - email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f' + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', }, page: { url: 'http://demo.mywebsite.com/purchase', @@ -6579,7 +6596,7 @@ export const data = [ { from: 'addToCart', to: 'download', - } + }, ], }, }, @@ -6613,13 +6630,15 @@ export const data = [ event_id: '1616318632825_357', event_time: 1600372167, properties: { - content_type: "product", - contents: [{ - price: 8, - quantity: 2, - content_type: 'socks', - content_id: '1077218', - }], + content_type: 'product', + contents: [ + { + price: 8, + quantity: 2, + content_type: 'socks', + content_id: '1077218', + }, + ], currency: 'USD', value: 46, }, @@ -6628,7 +6647,7 @@ export const data = [ referrer: 'http://demo.mywebsite.com', }, user: { - locale: "en-US", + locale: 'en-US', email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', external_id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', @@ -6687,7 +6706,7 @@ export const data = [ accessToken: 'dummyAccessToken', pixelCode: '{{PIXEL-CODE}}', hashUserProperties: false, - version: "v2" + version: 'v2', }, }, }, @@ -6716,7 +6735,8 @@ export const data = [ }, { name: 'tiktok_ads', - description: 'Test 45-> events 1.0 build contents from properties.product.$ where length of prodicts is 0', + description: + 'Test 45-> events 1.0 build contents from properties.product.$ where length of prodicts is 0', feature: 'processor', module: 'destination', version: 'v0', diff --git a/test/integrations/destinations/tiktok_ads/router/data.ts b/test/integrations/destinations/tiktok_ads/router/data.ts index cbf8da0cf8..0298979212 100644 --- a/test/integrations/destinations/tiktok_ads/router/data.ts +++ b/test/integrations/destinations/tiktok_ads/router/data.ts @@ -2749,7 +2749,6 @@ export const data = [ }, }, ], - }, }, }, diff --git a/test/integrations/testUtils.ts b/test/integrations/testUtils.ts index f5be8107ed..09f3a82d40 100644 --- a/test/integrations/testUtils.ts +++ b/test/integrations/testUtils.ts @@ -4,7 +4,10 @@ import { MockHttpCallsData, TestCaseData } from './testTypes'; import MockAdapter from 'axios-mock-adapter'; import isMatch from 'lodash/isMatch'; import { OptionValues } from 'commander'; +import { removeUndefinedAndNullValues } from '@rudderstack/integrations-lib'; +const generateAlphanumericId = (size = 36) => + [...Array(size)].map(() => ((Math.random() * size) | 0).toString(size)).join(''); export const getTestDataFilePaths = (dirPath: string, opts: OptionValues): string[] => { const globPattern = join(dirPath, '**', 'data.ts'); let testFilePaths = globSync(globPattern); @@ -74,3 +77,290 @@ export const overrideDestination = (destination, overrideConfigValues) => { Config: { ...destination.Config, ...overrideConfigValues }, }); }; + +export const generateIndentifyPayload = (parametersOverride: any) => { + const payload = { + type: 'identify', + sentAt: parametersOverride.sentAt || '2021-01-03T17:02:53.195Z', + userId: parametersOverride.userId || 'default-userId', + channel: 'web', + context: removeUndefinedAndNullValues({ + externalId: parametersOverride.externalId, + os: { name: '', version: '1.12.3' }, + app: { + name: 'RudderLabs JavaScript SDK', + build: '1.0.0', + version: '1.1.11', + namespace: 'com.rudderlabs.javascript', + }, + traits: parametersOverride.context.traits, + locale: 'en-US', + device: { token: 'token', id: 'id', type: 'ios' }, + screen: { density: 2 }, + library: { name: 'RudderLabs JavaScript SDK', version: '1.1.11' }, + campaign: {}, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', + }), + traits: parametersOverride.traits, + integrations: parametersOverride.integrations, + rudderId: parametersOverride.rudderId || generateAlphanumericId(36), + messageId: parametersOverride.messageId || generateAlphanumericId(36), + anonymousId: parametersOverride.anonymousId || 'default-anonymousId', + originalTimestamp: parametersOverride.originalTimestamp || '2021-01-03T17:02:53.193Z', + }; + + return removeUndefinedAndNullValues(payload); +}; + +export const generateSimplifiedIdentifyPayload = (parametersOverride: any) => { + return removeUndefinedAndNullValues({ + type: 'identify', + sentAt: parametersOverride.sentAt || '2021-01-03T17:02:53.195Z', + userId: parametersOverride.userId || 'default-userId', + traits: parametersOverride.traits, + integrations: parametersOverride.integrations, + rudderId: parametersOverride.rudderId || generateAlphanumericId(36), + messageId: parametersOverride.messageId || generateAlphanumericId(36), + context: { + externalId: parametersOverride.externalId, + traits: parametersOverride.context.traits, + }, + anonymousId: parametersOverride.anonymousId || 'default-anonymousId', + originalTimestamp: parametersOverride.originalTimestamp || '2021-01-03T17:02:53.193Z', + }); +}; + +export const generateTrackPayload = (parametersOverride: any) => { + const payload = { + type: 'track', + sentAt: parametersOverride.sentAt || '2021-01-03T17:02:53.195Z', + userId: parametersOverride.userId || 'default-user-id', + channel: 'web', + context: removeUndefinedAndNullValues({ + externalId: parametersOverride.externalId, + os: { name: '', version: '1.12.3' }, + app: { + name: 'RudderLabs JavaScript SDK', + build: '1.0.0', + version: '1.1.11', + namespace: 'com.rudderlabs.javascript', + }, + traits: parametersOverride.context.traits, + locale: 'en-US', + device: { token: 'token', id: 'id', type: 'ios' }, + screen: { density: 2 }, + library: { name: 'RudderLabs JavaScript SDK', version: '1.1.11' }, + campaign: {}, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0', + }), + rudderId: parametersOverride.rudderId || generateAlphanumericId(36), + messageId: parametersOverride.messageId || generateAlphanumericId(36), + anonymousId: parametersOverride.anonymousId || 'default-anonymousId', + originalTimestamp: parametersOverride.originalTimestamp || '2021-01-03T17:02:53.193Z', + timestamp: parametersOverride.timestamp, + event: parametersOverride.event || 'test-event', + integrations: parametersOverride.integrations, + properties: parametersOverride.properties, + }; + return removeUndefinedAndNullValues(payload); +}; + +export const generateSimplifiedTrackPayload = (parametersOverride: any) => { + return removeUndefinedAndNullValues({ + type: 'track', + sentAt: parametersOverride.sentAt || '2021-01-03T17:02:53.195Z', + userId: parametersOverride.userId || 'default-user-id', + event: parametersOverride.event || 'test-event', + properties: parametersOverride.properties, + integrations: parametersOverride.integrations, + rudderId: parametersOverride.rudderId || generateAlphanumericId(36), + messageId: parametersOverride.messageId || generateAlphanumericId(36), + context: removeUndefinedAndNullValues({ + externalId: parametersOverride.externalId, + traits: parametersOverride.context.traits, + }), + anonymousId: parametersOverride.anonymousId || 'default-anonymousId', + originalTimestamp: parametersOverride.originalTimestamp || '2021-01-03T17:02:53.193Z', + }); +}; + +export const generatePageOrScreenPayload = (parametersOverride: any, eventType: string) => { + const payload = { + channel: 'web', + userId: parametersOverride.userId || 'default-userId', + rudderId: parametersOverride.rudderId || generateAlphanumericId(36), + originalTimestamp: parametersOverride.originalTimestamp || '2022-04-26T05:17:09Z', + timestamp: parametersOverride.timestamp, + context: removeUndefinedAndNullValues({ + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.0', + }, + device: { + adTrackingEnabled: 'false', + advertisingId: 'T0T0T072-5e28-45a1-9eda-ce22a3e36d1a', + id: '3f034872-5e28-45a1-9eda-ce22a3e36d1a', + manufacturer: 'Google', + model: 'AOSP on IA Emulator', + name: 'generic_x86_arm', + type: 'ios', + attTrackingStatus: 3, + }, + ip: '0.0.0.0', + library: { + name: 'RudderLabs JavaScript SDK', + version: '1.0.0', + }, + locale: 'en-US', + os: { + name: 'iOS', + version: '14.4.1', + }, + screen: { + density: 2, + }, + traits: parametersOverride.context.traits, + externalId: parametersOverride.externalId, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', + }), + event: parametersOverride.event, + anonymousId: parametersOverride.anonymousId || 'default-anonymousId', + properties: parametersOverride.properties, + type: eventType || 'page', + integrations: parametersOverride.integrations, + sentAt: '2022-04-20T15:20:57Z', + }; + + return removeUndefinedAndNullValues(payload); +}; + +export const generateSimplifiedPageOrScreenPayload = ( + parametersOverride: any, + eventType: string, +) => { + return removeUndefinedAndNullValues({ + channel: 'web', + userId: parametersOverride.userId || 'default-userId', + type: eventType || 'page', + event: parametersOverride.event, + properties: parametersOverride.properties, + integrations: parametersOverride.integrations, + rudderId: parametersOverride.rudderId || generateAlphanumericId(36), + context: removeUndefinedAndNullValues({ + externalId: parametersOverride.externalId, + traits: parametersOverride.context.traits, + }), + timestamp: parametersOverride.timestamp, + anonymousId: parametersOverride.anonymousId || 'default-anonymousId', + originalTimestamp: parametersOverride.originalTimestamp || '2022-04-26T05:17:09Z', + }); +}; + +export const generateGroupPayload = (parametersOverride: any) => { + const payload = { + channel: 'web', + context: removeUndefinedAndNullValues({ + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.0', + }, + library: { + name: 'RudderLabs JavaScript SDK', + version: '1.0.0', + }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', + locale: 'en-US', + ip: '0.0.0.0', + os: { + name: '', + version: '', + }, + screen: { + density: 2, + }, + traits: parametersOverride.context.traits, + externalId: parametersOverride.externalId, + }), + messageId: parametersOverride.messageId || generateAlphanumericId(36), + session_id: parametersOverride.session_id || generateAlphanumericId(36), + originalTimestamp: parametersOverride.originalTimestamp || '2019-10-14T09:03:17.562Z', + timestamp: parametersOverride.timestamp, + anonymousId: parametersOverride.anonymousId || generateAlphanumericId(36), + userId: parametersOverride.userId || 'default-user-id', + type: 'group', + groupId: parametersOverride.groupId, + traits: parametersOverride.traits, + integrations: parametersOverride.integrations, + sentAt: parametersOverride.sentAt || '2019-10-14T09:03:22.563Z', + }; + return removeUndefinedAndNullValues(payload); +}; + +export const generateSimplifiedGroupPayload = (parametersOverride: any) => { + return removeUndefinedAndNullValues({ + channel: 'web', + userId: parametersOverride.userId || 'default-userId', + type: 'group', + groupId: parametersOverride.groupId, + traits: parametersOverride.traits, + integrations: parametersOverride.integrations, + context: removeUndefinedAndNullValues({ + externalId: parametersOverride.externalId, + traits: parametersOverride.context.traits, + }), + timestamp: parametersOverride.timestamp, + anonymousId: parametersOverride.anonymousId || generateAlphanumericId(36), + originalTimestamp: parametersOverride.originalTimestamp || '2019-10-14T09:03:17.562Z', + }); +}; + +export const transformResultBuilder = (matchData) => { + return removeUndefinedAndNullValues({ + version: '1', + type: 'REST', + userId: matchData.userId, + method: matchData.method || 'POST', + endpoint: matchData.endpoint || '', + headers: matchData.headers || {}, + params: matchData.params || {}, + body: { + JSON: matchData.JSON || {}, + JSON_ARRAY: matchData.JSON_ARRAY || {}, + XML: matchData.XML || {}, + FORM: matchData.FORM || {}, + }, + files: matchData.files || {}, + }); +}; + +export const compareObjects = (obj1, obj2, logPrefix = '', differences: string[] = []) => { + for (const key in obj1) { + if (obj1.hasOwnProperty(key)) { + const fullKey = logPrefix ? `${logPrefix}.${key}` : key; + + if (typeof obj1[key] === 'object' && typeof obj2[key] === 'object') { + compareObjects(obj1[key], obj2[key], fullKey, differences); + } else if (obj1[key] !== obj2[key]) { + differences.push(fullKey); + } + } + } + + // Check for keys in obj2 that are not present in obj1 + for (const key in obj2) { + if (obj2.hasOwnProperty(key) && !obj1.hasOwnProperty(key)) { + const fullKey = logPrefix ? `${logPrefix}.${key}` : key; + differences.push(fullKey); + } + } + + return differences; +}; diff --git a/test/test_reporter/reporter.ts b/test/test_reporter/reporter.ts new file mode 100644 index 0000000000..135f980398 --- /dev/null +++ b/test/test_reporter/reporter.ts @@ -0,0 +1,133 @@ +import fs from 'fs'; +import { compareObjects } from '../integrations/testUtils'; + +// Step 1: Generate the template HTML +const generateHTMLTemplate = () => ` + + + + + + Test Report + + + + + +

Test Report

+ + + + + + + + + + + + + + + + + +
Integration NameIdDescriptionSuccess CriteriaScenarioModuleFeatureAPI VersionTest InputTest OutputExpected OutputDiff KeysTest Status
+ + + +`; + +// Step 2: Iterate through each test data element and add it to the HTML template +const generateHTMLContent = (testData, expectedData, testStatus) => { + let htmlContent = ''; + let diffKeys: string[] = []; + diffKeys = compareObjects(testData.output.response.body, expectedData); + htmlContent += ` + + ${testData.name} + ${testData.id} + ${testData.description} + ${testData.successCriteria} + ${testData.scenario} + ${testData.module} + ${testData.feature} + ${testData.version} + ${JSON.stringify(testData.input.request.body)} + ${JSON.stringify(testData.output.response.body)} + ${JSON.stringify(expectedData)} + ${JSON.stringify(diffKeys)} + ${testStatus} + + + `; + + return htmlContent; +}; + +// Step 3: Write the HTML report to a file +export const generateTestReport = (testData, output, result) => { + fs.readFile('test_reports/test-report.html', 'utf8', (err, htmlTemplate) => { + if (err) { + console.error(err); + return; + } + + const htmlContent = generateHTMLContent(testData, output, result); + const finalHTML = htmlTemplate.replace('', htmlContent); + fs.writeFileSync('test_reports/test-report.html', finalHTML); + }); +}; + +export const initaliseReport = () => { + const htmlTemplate = generateHTMLTemplate(); + if (!fs.existsSync('test_reports')){ + fs.mkdirSync('test_reports'); +} + fs.writeFileSync('test_reports/test-report.html', htmlTemplate); + console.log('Report initialised'); +};