Skip to content
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: attentive tag bugsnag issue #3663

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
* 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;
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
}
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
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
}
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 @@
module.exports = {
getDestinationItemProperties,
getExternalIdentifiersMapping,
getPropertiesKeyValidation,
arePropertiesValid,
validateTimestamp,
};
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 { 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);
});
});
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
Loading