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 9, 2024
1 parent d4e0ae3 commit bab0617
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 5 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); //TODO fix
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); //TODO fix
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
6 changes: 5 additions & 1 deletion test/__tests__/utilities/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
64 changes: 62 additions & 2 deletions test/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}},`)

Check warning on line 18 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L18

Added line #L18 was not covered by tests
}
}

const assertRouterOutput = (output, input) => {
if (!input.metadata) {
return;
}

const returnedJobids = {};
output.forEach((outEvent) => {

Check warning on line 28 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L27-L28

Added lines #L27 - L28 were not covered by tests
//Assert that metadata is present and is an array
const metadata = outEvent.metadata;
expect(Array.isArray(metadata)).toEqual(true);

Check warning on line 31 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L30-L31

Added lines #L30 - L31 were not covered by tests

//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);

Check warning on line 36 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L34-L36

Added lines #L34 - L36 were not covered by tests
const validStatusCode = statusCode >= 200 && statusCode < 600;
expect(validStatusCode).toEqual(true);

Check warning on line 38 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L38

Added line #L38 was not covered by tests

//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;

Check warning on line 44 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L41-L44

Added lines #L41 - L44 were not covered by tests
});
});

const inputJobids = {};
input.forEach((input) => {
const jobId = input.metadata.jobId;
inputJobids[jobId] = true;

Check warning on line 51 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L48-L51

Added lines #L48 - L51 were not covered by tests
});

expect(returnedJobids).toEqual(inputJobids);

Check warning on line 54 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L54

Added line #L54 was not covered by tests

let userIdJobIdMap = {};
output.forEach((outEvent) => {

Check warning on line 57 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L56-L57

Added lines #L56 - L57 were not covered by tests
//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;

Check warning on line 63 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L60-L63

Added lines #L60 - L63 were not covered by tests
let arr = userIdJobIdMap[userId] || [];
arr.push(jobId);
userIdJobIdMap[userId] = arr;

Check warning on line 66 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L65-L66

Added lines #L65 - L66 were not covered by tests
});
}
});

//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);

Check warning on line 75 in test/testHelper.js

View check run for this annotation

Codecov / codecov/patch

test/testHelper.js#L72-L75

Added lines #L72 - L75 were not covered by tests
}
});
};

module.exports = {
getFuncTestData,
responses,
setResponsesForMockAxiosAdapter
setResponsesForMockAxiosAdapter,
assertRouterOutput
};

0 comments on commit bab0617

Please sign in to comment.