-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce v1/source/sourceType endpoint (#2722)
* source routing handle * migrate webhook to v1 * using folder structure to fetch varsionMap dynamically * small fix * update feature.json for v1 support boolean * temp commit * chore: comments addressed * chore: add test cases * chore: use map to store source version mapping * chore: resolve conflicts * chore: fix test cases and adressed comments * chore: fix test cases and adressed comments * chore: removed unnecessary types for source * chore: add test case for version v1 for webhook source means no alters in payload
- Loading branch information
1 parent
8eb1e1d
commit 0996e81
Showing
13 changed files
with
387 additions
and
8 deletions.
There are no files selected for viewing
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,149 @@ | ||
import ControllerUtility from './index'; | ||
|
||
describe('adaptInputToVersion', () => { | ||
it('should return the input unchanged when the implementation version is not found', () => { | ||
const sourceType = 'NA_SOURCE'; | ||
const requestVersion = 'v0'; | ||
const input = [ | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
]; | ||
const expected = { | ||
implementationVersion: undefined, | ||
input: [ | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
], | ||
}; | ||
|
||
const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
it('should return the input unchanged when the implementation version and request version are the same i.e. v0', () => { | ||
const sourceType = 'pipedream'; | ||
const requestVersion = 'v0'; | ||
const input = [ | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
]; | ||
const expected = { | ||
implementationVersion: 'v0', | ||
input: [ | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
], | ||
}; | ||
|
||
const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
it('should return the input unchanged when the implementation version and request version are the same i.e. v1', () => { | ||
const sourceType = 'webhook'; | ||
const requestVersion = 'v1'; | ||
const input = [ | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
]; | ||
const expected = { | ||
implementationVersion: 'v1', | ||
input: [ | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
], | ||
}; | ||
|
||
const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
it('should convert input from v0 to v1 when the request version is v0 and the implementation version is v1', () => { | ||
const sourceType = 'webhook'; | ||
const requestVersion = 'v0'; | ||
const input = [ | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
]; | ||
const expected = { | ||
implementationVersion: 'v1', | ||
input: [ | ||
{ event: { key1: 'val1', key2: 'val2' }, source: undefined }, | ||
{ event: { key1: 'val1', key2: 'val2' }, source: undefined }, | ||
{ event: { key1: 'val1', key2: 'val2' }, source: undefined }, | ||
], | ||
}; | ||
|
||
const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should convert input from v1 to v0 format when the request version is v1 and the implementation version is v0', () => { | ||
const sourceType = 'pipedream'; | ||
const requestVersion = 'v1'; | ||
const input = [ | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
{ | ||
event: { key1: 'val1', key2: 'val2' }, | ||
source: { id: 'source_id', config: { configField1: 'configVal1' } }, | ||
}, | ||
]; | ||
const expected = { | ||
implementationVersion: 'v0', | ||
input: [ | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
{ key1: 'val1', key2: 'val2' }, | ||
], | ||
}; | ||
|
||
const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
|
||
// Should return an empty array when the input is an empty array | ||
it('should return an empty array when the input is an empty array', () => { | ||
const sourceType = 'pipedream'; | ||
const requestVersion = 'v1'; | ||
const input = []; | ||
const expected = { implementationVersion: 'v0', input: [] }; | ||
|
||
const result = ControllerUtility.adaptInputToVersion(sourceType, requestVersion, input); | ||
|
||
expect(result).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
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 |
---|---|---|
|
@@ -61,5 +61,6 @@ | |
"ORTTO": true, | ||
"ONE_SIGNAL": true, | ||
"TIKTOK_AUDIENCE": true | ||
} | ||
}, | ||
"supportSourceTransformV1": true | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,27 @@ | ||
{ | ||
"input": [ | ||
{ | ||
"event": { | ||
"anonymousId": "63767499ca6fb1b7c988d5bb", | ||
"artist": "Gautam", | ||
"genre": "Jazz", | ||
"song": "Take Five" | ||
}, | ||
"source": { | ||
"id": "source_id", | ||
"config": { | ||
"configField1": "configVal1" | ||
} | ||
} | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"statusCode": 500, | ||
"error": "Cannot find module '../undefined/sources/NA_SOURCE/transform' from 'src/services/misc.ts'", | ||
"statTags": { | ||
"errorCategory": "transformation" | ||
} | ||
} | ||
] | ||
} |
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,49 @@ | ||
{ | ||
"input": [ | ||
{ | ||
"event": { | ||
"anonymousId": "63767499ca6fb1b7c988d5bb", | ||
"artist": "Gautam", | ||
"genre": "Jazz", | ||
"song": "Take Five" | ||
}, | ||
"source": { | ||
"id": "source_id", | ||
"config": { | ||
"configField1": "configVal1" | ||
} | ||
} | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"output": { | ||
"batch": [ | ||
{ | ||
"event": "pipedream_source_event", | ||
"anonymousId": "63767499ca6fb1b7c988d5bb", | ||
"context": { | ||
"integration": { | ||
"name": "PIPEDREAM" | ||
}, | ||
"library": { | ||
"name": "unknown", | ||
"version": "unknown" | ||
} | ||
}, | ||
"integrations": { | ||
"PIPEDREAM": false | ||
}, | ||
"type": "track", | ||
"properties": { | ||
"anonymousId": "63767499ca6fb1b7c988d5bb", | ||
"artist": "Gautam", | ||
"genre": "Jazz", | ||
"song": "Take Five" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.