From bab06173fa502fcc494e6284c3f19b76f1012168 Mon Sep 17 00:00:00 2001 From: Chandra shekar Varkala Date: Mon, 8 Jan 2024 17:17:18 -0600 Subject: [PATCH] chore: rt_batch_tests --- test/__tests__/lambda.test.js | 2 + test/__tests__/leanplum.test.js | 3 + .../lemniskMarketingAutomation.test.js | 2 + test/__tests__/mailjet.test.js | 3 + test/__tests__/mailmodo.test.js | 2 + test/__tests__/moengage.test.js | 3 + test/__tests__/monetate.test.js | 3 + test/__tests__/ometria.test.js | 5 +- test/__tests__/one_signal.test.js | 2 + test/__tests__/pagerduty.test.js | 2 + test/__tests__/pinterestConversion.test.js | 3 + test/__tests__/rockerbox.test.js | 2 + test/__tests__/sendgrid.test.js | 3 + test/__tests__/sfmc.test.js | 3 + test/__tests__/utilities/test-utils.js | 6 +- test/testHelper.js | 64 ++++++++++++++++++- 16 files changed, 103 insertions(+), 5 deletions(-) diff --git a/test/__tests__/lambda.test.js b/test/__tests__/lambda.test.js index 9fd656b103..91dfebb9e6 100644 --- a/test/__tests__/lambda.test.js +++ b/test/__tests__/lambda.test.js @@ -6,6 +6,7 @@ const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); // Processor Test Data const testDataFile = fs.readFileSync( @@ -40,6 +41,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/leanplum.test.js b/test/__tests__/leanplum.test.js index eb55df54fe..3a99da1230 100644 --- a/test/__tests__/leanplum.test.js +++ b/test/__tests__/leanplum.test.js @@ -7,6 +7,8 @@ const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); + const inputDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}_input.json`) ); @@ -43,6 +45,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/lemniskMarketingAutomation.test.js b/test/__tests__/lemniskMarketingAutomation.test.js index 55c09ba63e..80ea76053b 100644 --- a/test/__tests__/lemniskMarketingAutomation.test.js +++ b/test/__tests__/lemniskMarketingAutomation.test.js @@ -6,6 +6,7 @@ const fs = require("fs"); const path = require("path"); const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); // Processor Test Data const testDataFile = fs.readFileSync( @@ -37,6 +38,7 @@ describe(`${name} Tests`, () => { routerTestData.forEach(dataPoint => { it("Payload", async () => { const output = await transformer.processRouterDest(dataPoint.input); + assertRouterOutput(output, dataPoint.input); expect(output).toEqual(dataPoint.output); }); }); diff --git a/test/__tests__/mailjet.test.js b/test/__tests__/mailjet.test.js index a732b9ca82..bd1b59df4a 100644 --- a/test/__tests__/mailjet.test.js +++ b/test/__tests__/mailjet.test.js @@ -6,6 +6,7 @@ const name = "mailjet"; const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); const testDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}.json`) @@ -41,6 +42,7 @@ describe(`${name} Tests`, () => { routerTestData.forEach(dataPoint => { it("Payload", () => { const output = transformer.processRouterDest(dataPoint.input); + assertRouterOutput(output, dataPoint.input); expect(output).toEqual(dataPoint.output); }); }); @@ -50,6 +52,7 @@ describe(`${name} Tests`, () => { batchData.forEach((dataPoint, index) => { it(`${index}. ${integration} - ${dataPoint.description}`, () => { const output = transformer.processRouterDest(dataPoint.input); + //assertRouterOutput(output, dataPoint.input); //TODO fix expect(output).toEqual(dataPoint.output); }); }); diff --git a/test/__tests__/mailmodo.test.js b/test/__tests__/mailmodo.test.js index d49049f5db..8a5a7b2587 100644 --- a/test/__tests__/mailmodo.test.js +++ b/test/__tests__/mailmodo.test.js @@ -7,6 +7,7 @@ const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); // Processor Test files const testDataFile = fs.readFileSync( @@ -43,6 +44,7 @@ describe(`${name} Tests`, () => { const routerOutput = await transformer.processRouterDest( inputRouterData ); + //assertRouterOutput(routerOutput, inputRouterData); //TODO fix expect(routerOutput).toEqual(expectedRouterData); } catch (error) { expect(error.message).toEqual(expectedRouterData.error); diff --git a/test/__tests__/moengage.test.js b/test/__tests__/moengage.test.js index 6f9ad38afc..2c8b90955e 100644 --- a/test/__tests__/moengage.test.js +++ b/test/__tests__/moengage.test.js @@ -6,6 +6,8 @@ const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); + const inputDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}_input.json`) ); @@ -42,6 +44,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/monetate.test.js b/test/__tests__/monetate.test.js index 2b5c39db64..7d5a4a8842 100644 --- a/test/__tests__/monetate.test.js +++ b/test/__tests__/monetate.test.js @@ -7,6 +7,8 @@ const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); + const inputDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}_input.json`) ); @@ -43,6 +45,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/ometria.test.js b/test/__tests__/ometria.test.js index 6d397c5ee4..c44fb798dc 100644 --- a/test/__tests__/ometria.test.js +++ b/test/__tests__/ometria.test.js @@ -7,6 +7,8 @@ const name = "Ometria"; const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); + const inputDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}_input.json`) ); @@ -45,8 +47,7 @@ test("Batching", async () => { const batchInputData = JSON.parse(batchInputDataFile); const batchExpectedData = JSON.parse(batchOutputDataFile); const output = await transformer.processRouterDest(batchInputData); - // console.log(JSON.stringify(batchInputData)); - // console.log(JSON.stringify(output)); + assertRouterOutput(output, batchInputData); expect(Array.isArray(output)).toEqual(true); expect(output).toEqual(batchExpectedData); }); diff --git a/test/__tests__/one_signal.test.js b/test/__tests__/one_signal.test.js index 393d3c7657..dcfdc8de98 100644 --- a/test/__tests__/one_signal.test.js +++ b/test/__tests__/one_signal.test.js @@ -6,6 +6,7 @@ const name = "OneSignal"; const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); // Processor Test Data const testDataFile = fs.readFileSync( @@ -40,6 +41,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/pagerduty.test.js b/test/__tests__/pagerduty.test.js index b5bd4cf4b3..48c9a7cb39 100644 --- a/test/__tests__/pagerduty.test.js +++ b/test/__tests__/pagerduty.test.js @@ -6,6 +6,7 @@ const name = "PagerDuty"; const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); const testDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}.json`) @@ -36,6 +37,7 @@ describe(`${name} Tests`, () => { routerTestData.forEach(dataPoint => { it("Payload", async () => { const output = await transformer.processRouterDest(dataPoint.input); + assertRouterOutput(output, dataPoint.input); expect(output).toEqual(dataPoint.output); }); }); diff --git a/test/__tests__/pinterestConversion.test.js b/test/__tests__/pinterestConversion.test.js index 351551753d..4c145f0383 100644 --- a/test/__tests__/pinterestConversion.test.js +++ b/test/__tests__/pinterestConversion.test.js @@ -7,6 +7,8 @@ const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); + const inputDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}_input.json`) ); @@ -44,6 +46,7 @@ describe(`${name} Tests`, () => { inputRouterData.forEach((input, index) => { it(`Payload: ${index}`, async () => { let output = await transformer.processRouterDest(input); + assertRouterOutput(output, input); expect(output).toEqual(expectedRouterData[index]); }); }); diff --git a/test/__tests__/rockerbox.test.js b/test/__tests__/rockerbox.test.js index 092b4b2806..a5851a35c0 100644 --- a/test/__tests__/rockerbox.test.js +++ b/test/__tests__/rockerbox.test.js @@ -5,6 +5,7 @@ const fs = require("fs"); const path = require("path"); const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); // Processor Test Data const testDataFile = fs.readFileSync( @@ -39,6 +40,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/sendgrid.test.js b/test/__tests__/sendgrid.test.js index 20b0ebc5ae..9ded09f3d1 100644 --- a/test/__tests__/sendgrid.test.js +++ b/test/__tests__/sendgrid.test.js @@ -6,6 +6,7 @@ const name = "SendGrid"; const version = "v0"; const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); const testDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}.json`) @@ -42,6 +43,7 @@ describe(`${name} Tests`, () => { routerTestData.forEach(dataPoint => { it("SendGrid router test case", async () => { const output = await transformer.processRouterDest(dataPoint.input); + assertRouterOutput(output, dataPoint.input); expect(output).toEqual(dataPoint.output); }); }); @@ -51,6 +53,7 @@ describe(`${name} Tests`, () => { batchData.forEach((dataPoint, index) => { it(`${index}. ${integration} - ${dataPoint.description}`, async () => { const output = await transformer.processRouterDest(dataPoint.input); + assertRouterOutput(output, dataPoint.input); expect(output).toEqual(dataPoint.output); }); }); diff --git a/test/__tests__/sfmc.test.js b/test/__tests__/sfmc.test.js index 69d67625b1..f23d6c0016 100644 --- a/test/__tests__/sfmc.test.js +++ b/test/__tests__/sfmc.test.js @@ -7,6 +7,8 @@ const fs = require("fs"); const path = require("path"); const transformer = require(`../../src/${version}/destinations/${integration}/transform`); +const { assertRouterOutput } = require('../testHelper'); + const inputDataFile = fs.readFileSync( path.resolve(__dirname, `./data/${integration}_input.json`) ); @@ -43,6 +45,7 @@ describe(`${name} Tests`, () => { describe("Router Tests", () => { it("Payload", async () => { const routerOutput = await transformer.processRouterDest(inputRouterData); + assertRouterOutput(routerOutput, inputRouterData); expect(routerOutput).toEqual(expectedRouterData); }); }); diff --git a/test/__tests__/utilities/test-utils.js b/test/__tests__/utilities/test-utils.js index 73353f1ded..4d5d7fc909 100644 --- a/test/__tests__/utilities/test-utils.js +++ b/test/__tests__/utilities/test-utils.js @@ -2,6 +2,7 @@ const fs = require("fs"); const _ = require("lodash"); const path = require("path"); const { ConfigFactory, Executor } = require("rudder-transformer-cdk"); +const { assertRouterOutput } = require('../../testHelper'); // TODO: separate this out later as the list grows const cdkEnabledDestinations = { @@ -95,7 +96,9 @@ function executeTransformationTest(dest, transformAt) { if (transformAt == "processor") { actualData = await transformer.process(tcInput); } else { - actualData = (await transformer.processRouterDest([tcInput]))[0]; + actual = await transformer.processRouterDest([tcInput]) + assertRouterOutput(actual, [tcInput]); + actualData = (actual)[0]; } } // Compare actual and expected data @@ -115,6 +118,7 @@ function executeTransformationTest(dest, transformAt) { const version = "v0"; const transformer = require(`../../../src/${version}/destinations/${dest}/transform`); actualData = await transformer.processRouterDest(commonInput); + assertRouterOutput(actualData, commonInput); const cloneActual = _.cloneDeep(actualData); cloneActual[0].statTags = "undefined"; // Compare actual and expected data diff --git a/test/testHelper.js b/test/testHelper.js index 5fe97fed67..34ab9ec991 100644 --- a/test/testHelper.js +++ b/test/testHelper.js @@ -15,11 +15,71 @@ const setResponsesForMockAxiosAdapter = ({url, method, data, options}, {response if (data) { reqObj.data = data } - responses.push(`{httpReq: ${JSON.stringify(reqObj)},httpRes: ${JSON.stringify(response)}},`) + responses.push(`{httpReq: ${JSON.stringify(reqObj)},httpRes: ${JSON.stringify(response)}},`) } } + +const assertRouterOutput = (output, input) => { + if (!input.metadata) { + return; + } + + const returnedJobids = {}; + output.forEach((outEvent) => { + //Assert that metadata is present and is an array + const metadata = outEvent.metadata; + expect(Array.isArray(metadata)).toEqual(true); + + //Assert that statusCode is present and is a number between 200 and 600 + const statusCode = outEvent.statusCode; + expect(statusCode).toBeDefined(); + expect(typeof statusCode === 'number').toEqual(true); + const validStatusCode = statusCode >= 200 && statusCode < 600; + expect(validStatusCode).toEqual(true); + + //Assert that every job_id in the input is present in the output one and only one time. + metadata.forEach((meta) => { + const jobId = meta.jobId; + expect(returnedJobids[jobId]).toBeUndefined(); + returnedJobids[jobId] = true; + }); + }); + + const inputJobids = {}; + input.forEach((input) => { + const jobId = input.metadata.jobId; + inputJobids[jobId] = true; + }); + + expect(returnedJobids).toEqual(inputJobids); + + let userIdJobIdMap = {}; + output.forEach((outEvent) => { + //Events with statusCode 400-499 are skipped. They are not sent to the destination. + if (outEvent.statusCode < 400 || outEvent.statusCode > 499) { + const metadata = outEvent.metadata; + metadata.forEach((meta) => { + const jobId = meta.jobId; + const userId = meta.userId; + let arr = userIdJobIdMap[userId] || []; + arr.push(jobId); + userIdJobIdMap[userId] = arr; + }); + } + }); + + //The jobids for a user should be in order. If not, there is an issue. + Object.keys(userIdJobIdMap).forEach((userId) => { + const jobIds = userIdJobIdMap[userId]; + for (let i = 0; i < jobIds.length - 1; i++) { + expect(jobIds[i] < jobIds[i + 1]).toEqual(true); + } + }); +}; + module.exports = { getFuncTestData, responses, - setResponsesForMockAxiosAdapter + setResponsesForMockAxiosAdapter, + assertRouterOutput };