-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chandra shekar Varkala
committed
Feb 12, 2024
1 parent
69c8348
commit 8ae49ce
Showing
12 changed files
with
242 additions
and
289 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { NativeIntegrationDestinationService } from './nativeIntegration'; | ||
import { DestinationPostTransformationService } from './postTransformation'; | ||
import { | ||
ProcessorTransformationRequest, | ||
ProcessorTransformationOutput, | ||
ProcessorTransformationResponse, | ||
} from '../../types/index'; | ||
|
||
jest.mock('../../v0/destinations/__rudder_test__/transform'); | ||
let __rudder_test__ = require('../../v0/destinations/__rudder_test__/transform'); | ||
|
||
describe('PostTransformation Service', () => { | ||
test('should handleProcessorTransformFailureEvents', async () => { | ||
const destType = '__rudder_test__'; | ||
const version = 'v0'; | ||
const requestMetadata = {}; | ||
const event = { message: { a: 'b' } } as ProcessorTransformationRequest; | ||
const events: ProcessorTransformationRequest[] = [event]; | ||
const expected: ProcessorTransformationOutput[] = [ | ||
{ | ||
version: 'v0', | ||
} as ProcessorTransformationOutput, | ||
]; | ||
|
||
const expectedResp: ProcessorTransformationResponse[] = []; | ||
__rudder_test__.process = jest.fn(() => expected); | ||
const postTransformSpy = jest | ||
.spyOn(DestinationPostTransformationService, 'handleProcessorTransformSucessEvents') | ||
.mockImplementation((e, t, d) => { | ||
console.log('handleProcessorTransformSucessEvents xyz'); | ||
return expectedResp; | ||
}); | ||
|
||
const service = new NativeIntegrationDestinationService(); | ||
service.doProcessorTransformation(events, destType, version, requestMetadata); | ||
|
||
//expect(postTransformSpy).toHaveBeenCalledTimes(1); | ||
//expect(postTransformSpy).toHaveBeenCalledWith(event, expected, __rudder_test__); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createMockContext } from '@shopify/jest-koa-mocks'; | ||
import { MetaTransferObject, ProcessorTransformationRequest } from '../../types/index'; | ||
import { DestinationPostTransformationService } from './postTransformation'; | ||
import { ProcessorTransformationResponse } from '../../types'; | ||
|
||
describe('PostTransformation Service', () => { | ||
test('should handleProcessorTransformFailureEvents', async () => { | ||
const e = new Error('test error'); | ||
const metaTo = { errorContext: 'error Context' } as MetaTransferObject; | ||
const resp = DestinationPostTransformationService.handleProcessorTransformFailureEvents( | ||
e, | ||
metaTo, | ||
); | ||
|
||
const expected = { | ||
statusCode: 500, | ||
error: 'test error', | ||
statTags: { errorCategory: 'transformation' }, | ||
} as ProcessorTransformationResponse; | ||
|
||
expect(resp).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createMockContext } from '@shopify/jest-koa-mocks'; | ||
import { ProcessorTransformationRequest } from '../../types/index'; | ||
import { DestinationPreTransformationService } from './preTransformation'; | ||
|
||
describe('PreTransformation Service', () => { | ||
test('should enhance events with query params', async () => { | ||
const ctx = createMockContext(); | ||
ctx.request.query = { cycle: 'true', x: 'y' }; | ||
|
||
const events: ProcessorTransformationRequest[] = [ | ||
{ message: { a: 'b' } } as ProcessorTransformationRequest, | ||
]; | ||
const expected: ProcessorTransformationRequest[] = [ | ||
{ | ||
message: { a: 'b' }, | ||
request: { query: { cycle: 'true', x: 'y' } }, | ||
} as ProcessorTransformationRequest, | ||
]; | ||
|
||
const resp = DestinationPreTransformationService.preProcess(events, ctx); | ||
expect(resp).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable no-restricted-syntax */ | ||
const groupBy = require('lodash/groupBy'); | ||
const lodash = require('lodash'); | ||
const { | ||
removeUndefinedAndNullValues, | ||
getSuccessRespEvents, | ||
getErrorRespEvents, | ||
} = require('../../util'); | ||
|
||
|
||
const batch = (destEvents) => { | ||
const respList = []; | ||
if (!Array.isArray(destEvents) || destEvents.length <= 0) { | ||
const respEvents = getErrorRespEvents(null, 400, 'Invalid event array'); | ||
return [respEvents]; | ||
} | ||
|
||
// Grouping the events by topic | ||
const groupedEvents = groupBy(destEvents, (event) => event.message.topic); | ||
|
||
// Creating a batched request for each topic | ||
// we are grouping the events based on topics | ||
// and creating a batched request for each topic | ||
// example: input events = [{event1,topic1},{event2,topic1},{event3,topic2}] | ||
// out from transformer: {batchedRequest:[{event1},{event2}]}, {batchedRequest:[{event3}]} (2 multilexed responses) | ||
for (const events of Object.values(groupedEvents)) { | ||
const response = { | ||
batchedRequest: events.map((event) => event.message), | ||
metadata: events.map((event) => event.metadata), | ||
destination: events[0].destination, | ||
}; | ||
respList.push( | ||
getSuccessRespEvents(response.batchedRequest, response.metadata, response.destination, true), | ||
); | ||
} | ||
return respList; | ||
}; | ||
|
||
const process = (event) => { | ||
console.log("called __rudder_test__ transform.js"); | ||
|
||
const { message, destination } = event; | ||
|
||
const userId = message.userId || message.anonymousId; | ||
const outputEvent = { | ||
message, | ||
userId, | ||
destination | ||
}; | ||
return removeUndefinedAndNullValues(outputEvent); | ||
}; | ||
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, processRouterDest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1047,7 +1047,7 @@ | |
} | ||
} | ||
], | ||
"destType": "am" | ||
"destType": "__rudder_test__" | ||
}, | ||
"output": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1049,7 +1049,7 @@ | |
} | ||
} | ||
], | ||
"destType": "am" | ||
"destType": "__rudder_test__" | ||
}, | ||
"output": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -713,7 +713,7 @@ | |
} | ||
} | ||
], | ||
"destType": "pinterest_tag" | ||
"destType": "__rudder_test__" | ||
}, | ||
"output": { | ||
"output": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,7 +488,7 @@ | |
} | ||
} | ||
], | ||
"destType": "webhook" | ||
"destType": "__rudder_test__" | ||
}, | ||
"output": { | ||
"output": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -974,7 +974,7 @@ | |
} | ||
} | ||
], | ||
"destType": "webhook" | ||
"destType": "__rudder_test__" | ||
}, | ||
"output": { | ||
"output": [ | ||
|
Oops, something went wrong.