Skip to content

Commit

Permalink
fix: attentive tag bugsnag issue (#3663)
Browse files Browse the repository at this point in the history
* fix: attentive tag bugsnag issue

* fix: review comment addressed

* fix: review comment addressed

* fix: editing test caes

* fix: editing test caes
  • Loading branch information
shrouti1507 authored Aug 20, 2024
1 parent 1a61675 commit 866dbf3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/v0/destinations/attentive_tag/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
const {
getDestinationItemProperties,
getExternalIdentifiersMapping,
getPropertiesKeyValidation,
arePropertiesValid,
validateTimestamp,
} = require('./util');
const { JSON_MIME_TYPE } = require('../../util/constant');
Expand Down Expand Up @@ -137,9 +137,9 @@ const trackResponseBuilder = (message, { Config }) => {
payload = constructPayload(message, mappingConfig[ConfigCategory.TRACK.name]);
endpoint = ConfigCategory.TRACK.endpoint;
payload.type = get(message, 'event');
if (!getPropertiesKeyValidation(payload)) {
if (!arePropertiesValid(payload.properties)) {
throw new InstrumentationError(
'[Attentive Tag]:The event name contains characters which is not allowed',
'[Attentive Tag]:The properties contains characters which is not allowed',
);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/v0/destinations/attentive_tag/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ const { mappingConfig, ConfigCategory } = require('./config');
* The keys should not contain any of the values inside the validationArray.
* STEP 1: Storing keys in the array.
* Checking for the non-valid characters inside the keys of properties.
* ref: https://docs.attentivemobile.com/openapi/reference/tag/Custom-Events/
* @param {*} payload
* @returns
*/
const getPropertiesKeyValidation = (payload) => {
const arePropertiesValid = (properties) => {
if (!isDefinedAndNotNullAndNotEmpty(properties)) {
return true;
}
if (typeof properties !== 'object') {
return false;
}
const validationArray = [`'`, `"`, `{`, `}`, `[`, `]`, ',', `,`];
const keys = Object.keys(payload.properties);
const keys = Object.keys(properties);
for (const key of keys) {
for (const validationChar of validationArray) {
if (key.includes(validationChar)) {
Expand Down Expand Up @@ -134,6 +141,6 @@ const getDestinationItemProperties = (message, isItemsRequired) => {
module.exports = {
getDestinationItemProperties,
getExternalIdentifiersMapping,
getPropertiesKeyValidation,
arePropertiesValid,
validateTimestamp,
};
51 changes: 51 additions & 0 deletions src/v0/destinations/attentive_tag/util.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { arePropertiesValid } = require('./util');

describe('arePropertiesValid', () => {
// returns true for valid properties object with no special characters in keys
it('should return true when properties object has no special characters in keys', () => {
const properties = { key1: 'value1', key2: 'value2' };
const result = arePropertiesValid(properties);
expect(result).toBe(true);
});

// returns true for null properties input
it('should return true when properties input is null', () => {
const properties = null;
const result = arePropertiesValid(properties);
expect(result).toBe(true);
});

// returns false for properties object with keys containing special characters
it('should return false for properties object with keys containing special characters', () => {
const properties = {
key1: 'value1',
'key,2': 'value2',
key3: 'value3',
};
expect(arePropertiesValid(properties)).toBe(false);
});

// returns true for empty properties object
it('should return true for empty properties object', () => {
const properties = {};
expect(arePropertiesValid(properties)).toBe(true);
});

// returns true for undefined properties input
it('should return true for undefined properties input', () => {
const result = arePropertiesValid(undefined);
expect(result).toBe(true);
});

// returns true for empty string properties input
it('should return true for empty string properties input', () => {
const result = arePropertiesValid('');
expect(result).toBe(true);
});

// returns false for empty string properties input
it('should return false for non object properties input', () => {
const result = arePropertiesValid('1234');
expect(result).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ export const data = [
body: [
{
statusCode: 400,
error: '[Attentive Tag]:The event name contains characters which is not allowed',
error: '[Attentive Tag]:The properties contains characters which is not allowed',
statTags: {
destType: 'ATTENTIVE_TAG',
errorCategory: 'dataValidation',
Expand Down

0 comments on commit 866dbf3

Please sign in to comment.