From 04074af794016609b3ed7d38cd13a5e18ede0e5a Mon Sep 17 00:00:00 2001 From: Chandra shekar Varkala Date: Mon, 22 Jan 2024 14:18:38 -0600 Subject: [PATCH] chore: clean up --- .../destinations/__rudder_test__/transform.js | 26 ++++++---------- .../destination/batch/failure_batch.json | 2 +- .../destination/batch/successful_batch.json | 2 +- .../destination/router/failure_test.json | 2 +- .../destination/router/successful_test.json | 2 +- .../router/two_destination_test.json | 2 +- test/apitests/service.api.test.ts | 31 +++++++++++++------ 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/v0/destinations/__rudder_test__/transform.js b/src/v0/destinations/__rudder_test__/transform.js index 167e3b2b9b..81e5235500 100644 --- a/src/v0/destinations/__rudder_test__/transform.js +++ b/src/v0/destinations/__rudder_test__/transform.js @@ -1,6 +1,6 @@ /* eslint-disable no-restricted-syntax */ const groupBy = require('lodash/groupBy'); -const cloneDeep = require('lodash/cloneDeep'); +const lodash = require('lodash'); const { removeUndefinedAndNullValues, getSuccessRespEvents, @@ -49,21 +49,13 @@ const process = (event) => { }; return removeUndefinedAndNullValues(outputEvent); }; - -/** - * This functions takes event matadata and updates it based on the transformed and raw paylaod - * the outputEvent is the transformed event which is guranateed to contain the topic - * @param {*} input - * @returns {*} metadata - */ -const processMetadata = (input) => { - const { metadata, outputEvent } = input; - const clonedMetadata = cloneDeep(metadata); - const { topic } = outputEvent; - if (topic) { - clonedMetadata.rudderId = `${clonedMetadata.rudderId}<<>>${topic}`; - } - return clonedMetadata; +const processRouterDest = async (inputs, reqMetadata) => { + // group events by userId or anonymousId and then call process + const groupedInputs = lodash.groupBy( + inputs, + (input) => input.message.userId || input.message.anonymousId, + ); + return batch(groupedInputs); }; -module.exports = { process, batch, processMetadata }; +module.exports = { process, batch, processRouterDest }; diff --git a/test/apitests/data_scenarios/destination/batch/failure_batch.json b/test/apitests/data_scenarios/destination/batch/failure_batch.json index 8063bc74a1..fda57b5aa5 100644 --- a/test/apitests/data_scenarios/destination/batch/failure_batch.json +++ b/test/apitests/data_scenarios/destination/batch/failure_batch.json @@ -1047,7 +1047,7 @@ } } ], - "destType": "am" + "destType": "__rudder_test__" }, "output": [ { diff --git a/test/apitests/data_scenarios/destination/batch/successful_batch.json b/test/apitests/data_scenarios/destination/batch/successful_batch.json index 32745f49d5..f63f0abd3d 100644 --- a/test/apitests/data_scenarios/destination/batch/successful_batch.json +++ b/test/apitests/data_scenarios/destination/batch/successful_batch.json @@ -1049,7 +1049,7 @@ } } ], - "destType": "am" + "destType": "__rudder_test__" }, "output": [ { diff --git a/test/apitests/data_scenarios/destination/router/failure_test.json b/test/apitests/data_scenarios/destination/router/failure_test.json index 96c5cff54f..e649a70854 100644 --- a/test/apitests/data_scenarios/destination/router/failure_test.json +++ b/test/apitests/data_scenarios/destination/router/failure_test.json @@ -713,7 +713,7 @@ } } ], - "destType": "pinterest_tag" + "destType": "__rudder_test__" }, "output": { "output": [ diff --git a/test/apitests/data_scenarios/destination/router/successful_test.json b/test/apitests/data_scenarios/destination/router/successful_test.json index 3b0b89bd47..0b11609afb 100644 --- a/test/apitests/data_scenarios/destination/router/successful_test.json +++ b/test/apitests/data_scenarios/destination/router/successful_test.json @@ -488,7 +488,7 @@ } } ], - "destType": "webhook" + "destType": "__rudder_test__" }, "output": { "output": [ diff --git a/test/apitests/data_scenarios/destination/router/two_destination_test.json b/test/apitests/data_scenarios/destination/router/two_destination_test.json index 92191a3637..b2e5471499 100644 --- a/test/apitests/data_scenarios/destination/router/two_destination_test.json +++ b/test/apitests/data_scenarios/destination/router/two_destination_test.json @@ -974,7 +974,7 @@ } } ], - "destType": "webhook" + "destType": "__rudder_test__" }, "output": { "output": [ diff --git a/test/apitests/service.api.test.ts b/test/apitests/service.api.test.ts index a5f916f304..f0130e221a 100644 --- a/test/apitests/service.api.test.ts +++ b/test/apitests/service.api.test.ts @@ -6,6 +6,8 @@ import Koa from 'koa'; import bodyParser from 'koa-bodyparser'; import { applicationRoutes } from '../../src/routes'; import exp from 'constants'; +const testT = require('../../src/v0/destinations/__rudder_test__/transform'); + let server: any; const OLD_ENV = process.env; @@ -38,40 +40,49 @@ const getDataFromPath = (pathInput) => { describe('Destination api tests', () => { describe('Processor transform tests', () => { test('(webhook) success scenario with single event', async () => { - /* const data = getDataFromPath('./data_scenarios/destination/proc/sucess.json'); + const process = jest.spyOn(testT, 'process').mockImplementation((event, m) => { + console.log("testDest - process - mockImplementation"); + }); + + const data = getDataFromPath('./data_scenarios/destination/proc/sucess.json'); const response = await request(server) - .post('/v0/destinations/webhook') + .post('/v0/destinations/__rudder_test__') .set('Accept', 'application/json') .send(data.input); expect(response.status).toEqual(200); - expect(JSON.parse(response.text)).toEqual(data.output); */ - expect(true).toEqual(true); + //console.log(JSON.parse(response.text)); }); }); describe('Batch transform tests', () => { test('(am) successful batch transform', async () => { - /* const data = getDataFromPath('./data_scenarios/destination/batch/successful_batch.json'); + const batch = jest.spyOn(testT, 'batch').mockImplementation((event, m) => { + console.log("testDest - batch - mockImplementation"); + }); + + const data = getDataFromPath('./data_scenarios/destination/batch/successful_batch.json'); const response = await request(server) .post('/batch') .set('Accept', 'application/json') .send(data.input); expect(response.status).toEqual(200); - expect(JSON.parse(response.text)).toEqual(data.output); */ - expect(true).toEqual(true); + //expect(JSON.parse(response.text)).toEqual(data.output); }); }); describe('Router transform tests', () => { test('(webhook) successful router transform', async () => { - /* const data = getDataFromPath('./data_scenarios/destination/router/successful_test.json'); + const processRouterDest = jest.spyOn(testT, 'processRouterDest').mockImplementation((event, m) => { + console.log("testDest - processRouterDest - mockImplementation"); + }); + + const data = getDataFromPath('./data_scenarios/destination/router/successful_test.json'); const response = await request(server) .post('/routerTransform') .set('Accept', 'application/json') .send(data.input); expect(response.status).toEqual(200); - expect(JSON.parse(response.text)).toEqual(data.output); */ - expect(true).toEqual(true); + //expect(JSON.parse(response.text)).toEqual(data.output); }); }); });