Skip to content

Commit

Permalink
fix: update for supporting disallowed events
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Dec 12, 2024
1 parent a5ba58c commit d00f31f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/v0/destinations/iterable/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,13 @@ const checkIfEventIsAbortableAndExtractErrorMessage = (event, destinationRespons
ITERABLE_RESPONSE_EMAIL_PATHS.find((emailPath) =>
isValueInResponseArray(emailPath, eventValues.email, destinationResponse.response),
) ||
isValueInResponseArray(
(isValueInResponseArray(
'disallowedEventNames',
eventValues.eventName,
destinationResponse.response,
);
)
? 'disallowedEventNames'
: null);

if (matchingPath) {
const responseValueArray = getValueFromResponse(matchingPath, destinationResponse.response);
Expand All @@ -818,7 +820,7 @@ const checkIfEventIsAbortableAndExtractErrorMessage = (event, destinationRespons
if (ITERABLE_RESPONSE_USER_ID_PATHS.some((userIdPath) => matchingPath.includes(userIdPath))) {
return value === eventValues.userId;
}
if (matchingPath.includes('disallowedEventNames')) {
if (matchingPath === 'disallowedEventNames') {
return value === eventValues.eventName;
}
return false;

Check warning on line 826 in src/v0/destinations/iterable/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/iterable/util.js#L826

Added line #L826 was not covered by tests
Expand Down
48 changes: 47 additions & 1 deletion src/v0/destinations/iterable/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ describe('iterable utils test', () => {

// Returns appropriate error message for abortable event

it('should find the right value for which it should fail and passes otherwise', () => {
it('should find the right value for which it should fail and passes otherwise for emails', () => {
const event = {
email: 'test',
userId: 'user123',
Expand Down Expand Up @@ -905,5 +905,51 @@ describe('iterable utils test', () => {
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:
'Request failed for value "user123" because it is "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: 'Request failed for value "purchase" because it is "disallowedEventNames".',
});
});
});
});

0 comments on commit d00f31f

Please sign in to comment.