Skip to content

Commit

Permalink
test: add gzip support header in testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Oct 19, 2023
1 parent 29e03ea commit ec5c8a3
Show file tree
Hide file tree
Showing 6 changed files with 905 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/v0/destinations/mp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { getMappingConfig } = require('../../util');
const BASE_ENDPOINT = 'https://api.mixpanel.com';
const BASE_ENDPOINT_EU = 'https://api-eu.mixpanel.com';
const CREATE_DELETION_TASK_ENDPOINT = 'https://mixpanel.com/api/app/data-deletions/v3.0/';
const FEATURE_GZIP_SUPPORT = 'gzip-support';

const getCreateDeletionTaskEndpoint = (projectToken) =>
`${CREATE_DELETION_TASK_ENDPOINT}?token=${projectToken}`;
Expand Down Expand Up @@ -62,7 +61,6 @@ module.exports = {
DEL_MAX_BATCH_SIZE,
ConfigCategory,
BASE_ENDPOINT_EU,
FEATURE_GZIP_SUPPORT,
GEO_SOURCE_ALLOWED_VALUES,
MP_IDENTIFY_EXCLUSION_LIST,
getCreateDeletionTaskEndpoint,
Expand Down
10 changes: 1 addition & 9 deletions src/v0/destinations/mp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const {
batchMultiplexedEvents,
getSuccessRespEvents,
defaultBatchRequestConfig,
IsGzipSupported,
} = require('../../util');
const {
ConfigCategory,
MP_IDENTIFY_EXCLUSION_LIST,
GEO_SOURCE_ALLOWED_VALUES,
mappingConfig,
FEATURE_GZIP_SUPPORT,
} = require('./config');
const { InstrumentationError } = require('../../util/errorTypes');
const { CommonUtils } = require('../../../util/common');
Expand Down Expand Up @@ -213,14 +213,6 @@ const groupEventsByEndpoint = (events) => {
};
};

const IsGzipSupported = (reqMetadata = {}) => {
if (reqMetadata && typeof reqMetadata === 'object' && !Array.isArray(reqMetadata)) {
const { features } = reqMetadata;
return !!(features && features[FEATURE_GZIP_SUPPORT]);
}
return false;
};

const generateBatchedPayloadForArray = (events, reqMetadata) => {
const { batchedRequest } = defaultBatchRequestConfig();
const firstEvent = events[0];
Expand Down
9 changes: 7 additions & 2 deletions src/v0/destinations/mp/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
batchEvents,
generateBatchedPayloadForArray,
} = require('./util');
const { FEATURE_GZIP_SUPPORT } = require('../../util/constant');

const destinationMock = {
Config: {
Expand Down Expand Up @@ -524,7 +525,9 @@ describe('Mixpanel utils test', () => {
version: '1',
};

const result = generateBatchedPayloadForArray(events);
const result = generateBatchedPayloadForArray(events, {
features: { [FEATURE_GZIP_SUPPORT]: true },
});

expect(result).toEqual(expectedBatchedRequest);
});
Expand Down Expand Up @@ -560,7 +563,9 @@ describe('Mixpanel utils test', () => {
version: '1',
};

const result = generateBatchedPayloadForArray(events);
const result = generateBatchedPayloadForArray(events, {
features: { [FEATURE_GZIP_SUPPORT]: true },
});

expect(result).toEqual(expectedBatchedRequest);
});
Expand Down
2 changes: 2 additions & 0 deletions src/v0/util/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const API_CALL = 'api_call_count';
const JSON_MIME_TYPE = 'application/json';

const FEATURE_FILTER_CODE = 'filter-code';
const FEATURE_GZIP_SUPPORT = 'gzip-support';

const HTTP_STATUS_CODES = {
// 1xx Informational
Expand Down Expand Up @@ -89,4 +90,5 @@ module.exports = {
HTTP_STATUS_CODES,
USER_LEAD_CACHE_TTL,
FEATURE_FILTER_CODE,
FEATURE_GZIP_SUPPORT,
};
23 changes: 17 additions & 6 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const {
REFRESH_TOKEN,
AUTH_STATUS_INACTIVE,
} = require('../../adapters/networkhandler/authConstants');
const { FEATURE_FILTER_CODE } = require('./constant');
const { FEATURE_FILTER_CODE, FEATURE_GZIP_SUPPORT } = require('./constant');

// ========================================================================
// INLINERS
// ========================================================================
Expand Down Expand Up @@ -372,7 +373,7 @@ const hashToSha256 = (value) => sha256(value);

// Check what type of gender and convert to f or m
const getFbGenderVal = (gender) => {
if (typeof (gender) !== 'string') {
if (typeof gender !== 'string') {
return null;
}
if (
Expand Down Expand Up @@ -2050,11 +2051,20 @@ const getAuthErrCategoryFromStCode = (status) => {
return '';
};

const validateEventType = event => {
if(!event || typeof event !== "string"){
throw new InstrumentationError("Event is a required field and should be a string");
const validateEventType = (event) => {
if (!event || typeof event !== 'string') {
throw new InstrumentationError('Event is a required field and should be a string');
}
}
};

const IsGzipSupported = (reqMetadata = {}) => {
if (reqMetadata && typeof reqMetadata === 'object' && !Array.isArray(reqMetadata)) {
const { features } = reqMetadata;
return !!(features && features[FEATURE_GZIP_SUPPORT]);
}
return false;
};

// ========================================================================
// EXPORTS
// ========================================================================
Expand Down Expand Up @@ -2161,4 +2171,5 @@ module.exports = {
getAuthErrCategoryFromErrDetailsAndStCode,
getAuthErrCategoryFromStCode,
isNewStatusCodesAccepted,
IsGzipSupported,
};
Loading

0 comments on commit ec5c8a3

Please sign in to comment.