Skip to content

Commit

Permalink
chore: rt_batch_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandra shekar Varkala committed Jan 8, 2024
1 parent d4e0ae3 commit 46977a7
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 4 deletions.
2 changes: 2 additions & 0 deletions test/__tests__/lambda.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/leanplum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
);
Expand Down Expand Up @@ -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);
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/__tests__/lemniskMarketingAutomation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/mailjet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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);
expect(output).toEqual(dataPoint.output);
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/__tests__/mailmodo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -43,6 +44,7 @@ describe(`${name} Tests`, () => {
const routerOutput = await transformer.processRouterDest(
inputRouterData
);
assertRouterOutput(routerOutput, inputRouterData);
expect(routerOutput).toEqual(expectedRouterData);
} catch (error) {
expect(error.message).toEqual(expectedRouterData.error);
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/moengage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
);
Expand Down Expand Up @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/monetate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
);
Expand Down Expand Up @@ -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);
});
});
Expand Down
5 changes: 3 additions & 2 deletions test/__tests__/ometria.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
);
Expand Down Expand Up @@ -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);
});
2 changes: 2 additions & 0 deletions test/__tests__/one_signal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/__tests__/pagerduty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/pinterestConversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
);
Expand Down Expand Up @@ -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]);
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/__tests__/rockerbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/sendgrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/sfmc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
);
Expand Down Expand Up @@ -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);
});
});
Expand Down
60 changes: 58 additions & 2 deletions test/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,67 @@ 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) => {
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
};

0 comments on commit 46977a7

Please sign in to comment.