Skip to content

Commit

Permalink
fix: attentive tag bugsnag issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Aug 16, 2024
1 parent 5bae268 commit fc92084
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/v0/destinations/attentive_tag/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const trackResponseBuilder = (message, { Config }) => {
payload = constructPayload(message, mappingConfig[ConfigCategory.TRACK.name]);
endpoint = ConfigCategory.TRACK.endpoint;
payload.type = get(message, 'event');
if (!getPropertiesKeyValidation(payload)) {
if (!getPropertiesKeyValidation(payload.properties)) {
throw new InstrumentationError(
'[Attentive Tag]:The event name contains characters which is not allowed',
);
Expand Down
11 changes: 9 additions & 2 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 getPropertiesKeyValidation = (properties) => {
if (!isDefinedAndNotNullAndNotEmpty(properties)) {
return true;
}
if (typeof properties !== 'object') {
return false;

Check warning on line 26 in src/v0/destinations/attentive_tag/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/attentive_tag/util.js#L26

Added line #L26 was not covered by tests
}
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
45 changes: 45 additions & 0 deletions src/v0/destinations/attentive_tag/util.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { getPropertiesKeyValidation } = require('./util');

describe('getPropertiesKeyValidation', () => {
// 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 = getPropertiesKeyValidation(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 = getPropertiesKeyValidation(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(getPropertiesKeyValidation(properties)).toBe(false);
});

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

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

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

0 comments on commit fc92084

Please sign in to comment.