-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: adding transformer proxy for iterable #3878
Open
shrouti1507
wants to merge
20
commits into
develop
Choose a base branch
from
fix.iterable-networkhandler
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
096d008
fix: adding transformer proxy for iterable
shrouti1507 2a10f70
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 2b34182
fix: adding component test cases
shrouti1507 8742244
fix: adding factory pattern
shrouti1507 25a5ced
fix: code redesigning
shrouti1507 c87c5ce
fix: decoupling networkHandler and specific strategy
shrouti1507 1058ec1
fix: simplifying logic
shrouti1507 f11d7eb
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 909cad0
fix: convert to registry pattern
shrouti1507 2337c7b
fix: converting to typescript
shrouti1507 9eb31bf
fix: removing unnecessary comments
shrouti1507 97d531f
fix: adding data delivery test cases for all endpoints
shrouti1507 3789652
chore: improve iterable network handler (#3918)
sanpj2292 aae7b3d
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 9ee2847
fix: review comments addressed
shrouti1507 a5ba58c
fix: small refactoring
shrouti1507 d00f31f
fix: update for supporting disallowed events
shrouti1507 707dfe8
fix: code review suggestion
shrouti1507 8e5d6ab
fix: fixing test cases
shrouti1507 9ce4575
fix: review comment addressed
shrouti1507 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ const { | |
updateUserEventPayloadBuilder, | ||
registerDeviceTokenEventPayloadBuilder, | ||
registerBrowserTokenEventPayloadBuilder, | ||
checkIfEventIsAbortableAndExtractErrorMessage, | ||
} = require('./util'); | ||
|
||
const { ConfigCategory } = require('./config'); | ||
|
@@ -799,4 +800,155 @@ describe('iterable utils test', () => { | |
); | ||
}); | ||
}); | ||
describe('checkIfEventIsAbortableAndExtractErrorMessage', () => { | ||
// Returns non-abortable and empty error message when failCount is 0 | ||
it('should return non-abortable and empty error message when failCount is 0', () => { | ||
const event = { | ||
email: '[email protected]', | ||
userId: 'user123', | ||
eventName: 'testEvent', | ||
}; | ||
const destinationResponse = { | ||
response: { | ||
failCount: 0, | ||
}, | ||
}; | ||
|
||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
expect(result).toEqual({ isAbortable: false, errorMsg: '' }); | ||
}); | ||
|
||
// Handles undefined or null event fields gracefully | ||
it('should handle undefined or null event fields gracefully', () => { | ||
const event = { | ||
email: null, | ||
userId: undefined, | ||
eventName: 'testEvent', | ||
}; | ||
const destinationResponse = { | ||
response: { | ||
failCount: 1, | ||
invalidEmails: ['[email protected]'], | ||
}, | ||
}; | ||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
expect(result).toEqual({ isAbortable: false, errorMsg: '' }); | ||
}); | ||
|
||
// Handles events with all expected fields present | ||
it('should handle events with all expected fields present and return non-abortable when no match', () => { | ||
const event = { | ||
email: '[email protected]', | ||
userId: 'user123', | ||
eventName: 'purchase', | ||
id: 'event123', | ||
createdAt: '2023-10-01T00:00:00Z', | ||
campaignId: 'campaign123', | ||
templateId: 'template123', | ||
createNewFields: true, | ||
dataFields: { field1: 'value1' }, | ||
}; | ||
|
||
const destinationResponse = { | ||
response: { | ||
failCount: 1, | ||
invalidEmails: ['[email protected]'], | ||
}, | ||
}; | ||
|
||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
|
||
expect(result.isAbortable).toBe(false); | ||
expect(result.errorMsg).toBe(''); | ||
}); | ||
|
||
// Returns appropriate error message for abortable event | ||
|
||
it('should find the right value for which it should fail and passes otherwise for emails', () => { | ||
const event = { | ||
email: 'test', | ||
userId: 'user123', | ||
eventName: 'purchase', | ||
dataFields: { customField1: 'value1', customField2: 'value2' }, | ||
}; | ||
const destinationResponse = { | ||
response: { | ||
failCount: 1, | ||
failedUpdates: { | ||
invalidEmails: ['test'], | ||
}, | ||
}, | ||
}; | ||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
expect(result).toEqual({ | ||
isAbortable: true, | ||
errorMsg: 'email error:"test" in "failedUpdates.invalidEmails".', | ||
}); | ||
}); | ||
|
||
it('should find the right value for which it should fail', () => { | ||
const event = { | ||
email: '[email protected]', | ||
userId: 'user123', | ||
eventName: 'purchase', | ||
dataFields: { customField1: 'test', customField2: 'value2' }, | ||
}; | ||
const destinationResponse = { | ||
response: { | ||
failCount: 1, | ||
failedUpdates: { | ||
invalidEmails: ['test'], | ||
}, | ||
}, | ||
}; | ||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
expect(result.isAbortable).toBe(false); | ||
expect(result.errorMsg).toBe(''); | ||
}); | ||
|
||
it('should find the right value for which it should fail and passes otherwise for userIds', () => { | ||
const event = { | ||
email: 'test', | ||
userId: 'user123', | ||
eventName: 'purchase', | ||
dataFields: { customField1: 'value1', customField2: 'value2' }, | ||
}; | ||
const destinationResponse = { | ||
response: { | ||
failCount: 1, | ||
failedUpdates: { | ||
invalidUserIds: ['user123'], | ||
}, | ||
}, | ||
}; | ||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
expect(result).toEqual({ | ||
isAbortable: true, | ||
errorMsg: 'userId error:"user123" in "failedUpdates.invalidUserIds".', | ||
}); | ||
}); | ||
|
||
it('should find the right value for which it should fail and passes otherwise for disallowed events', () => { | ||
const event = { | ||
email: 'test', | ||
userId: 'user123', | ||
eventName: 'purchase', | ||
dataFields: { customField1: 'value1', customField2: 'value2' }, | ||
}; | ||
const destinationResponse = { | ||
response: { | ||
failCount: 1, | ||
disallowedEventNames: ['purchase'], | ||
failedUpdates: { | ||
invalidUserIds: [], | ||
}, | ||
}, | ||
}; | ||
const result = checkIfEventIsAbortableAndExtractErrorMessage(event, destinationResponse); | ||
expect(result).toEqual({ | ||
isAbortable: true, | ||
errorMsg: 'eventName error:"purchase" in "disallowedEventNames".', | ||
}); | ||
}); | ||
}); | ||
}); |
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,38 @@ | ||
import { prepareProxyRequest, proxyRequest } from '../../../adapters/network'; | ||
import { processAxiosResponse } from '../../../adapters/utils/networkUtils'; | ||
import { BULK_ENDPOINTS } from '../../../v0/destinations/iterable/config'; | ||
import { GenericStrategy } from './strategies/generic'; | ||
import { TrackIdentifyStrategy } from './strategies/track-identify'; | ||
|
||
type ResponseParams = { | ||
destinationRequest: { | ||
endpoint: string; | ||
}; | ||
}; | ||
|
||
const strategyRegistry: { [key: string]: any } = { | ||
[TrackIdentifyStrategy.name]: new TrackIdentifyStrategy(), | ||
[GenericStrategy.name]: new GenericStrategy(), | ||
}; | ||
|
||
const getResponseStrategy = (endpoint: string) => { | ||
if (BULK_ENDPOINTS.some((path) => endpoint.includes(path))) { | ||
return strategyRegistry[TrackIdentifyStrategy.name]; | ||
} | ||
return strategyRegistry[GenericStrategy.name]; | ||
}; | ||
|
||
const responseHandler = (responseParams: ResponseParams) => { | ||
const { destinationRequest } = responseParams; | ||
const strategy = getResponseStrategy(destinationRequest.endpoint); | ||
return strategy.handleResponse(responseParams); | ||
}; | ||
|
||
function networkHandler(this: any) { | ||
this.prepareProxy = prepareProxyRequest; | ||
this.proxy = proxyRequest; | ||
this.processAxiosResponse = processAxiosResponse; | ||
this.responseHandler = responseHandler; | ||
} | ||
|
||
export { networkHandler }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add test-case with multiple path matches for same email(for example) as well ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added