Skip to content

Commit

Permalink
fix: remove unnecessary extra properties in all network mock requests
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Sankeerth <[email protected]>
  • Loading branch information
Sai Sankeerth committed Sep 25, 2023
1 parent bdb6f5c commit 2029fb4
Show file tree
Hide file tree
Showing 23 changed files with 220 additions and 7,742 deletions.
24 changes: 6 additions & 18 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const httpSend = async (options, statTags = {}) => {
fireHTTPStats(clientResponse, startTime, statTags);
}

setResponsesForMockAxiosAdapter({ url, data, method, options: opts }, clientResponse);
setResponsesForMockAxiosAdapter({ url, data, method, options }, clientResponse);
return clientResponse;
};

Expand All @@ -122,7 +122,7 @@ const httpGET = async (url, options, statTags = {}) => {
} finally {
fireHTTPStats(clientResponse, startTime, statTags);
}
setResponsesForMockAxiosAdapter({ url, options: requestOptions, method: 'GET' }, clientResponse);
setResponsesForMockAxiosAdapter({ url, options, method: 'GET' }, clientResponse);
return clientResponse;
};

Expand All @@ -148,10 +148,7 @@ const httpDELETE = async (url, options, statTags = {}) => {
} finally {
fireHTTPStats(clientResponse, startTime, statTags);
}
setResponsesForMockAxiosAdapter(
{ url, options: requestOptions, method: 'DELETE' },
clientResponse,
);
setResponsesForMockAxiosAdapter({ url, options, method: 'DELETE' }, clientResponse);
return clientResponse;
};

Expand All @@ -178,10 +175,7 @@ const httpPOST = async (url, data, options, statTags = {}) => {
} finally {
fireHTTPStats(clientResponse, startTime, statTags);
}
setResponsesForMockAxiosAdapter(
{ url, data, options: requestOptions, method: 'POST' },
clientResponse,
);
setResponsesForMockAxiosAdapter({ url, data, options, method: 'POST' }, clientResponse);
return clientResponse;
};

Expand All @@ -208,10 +202,7 @@ const httpPUT = async (url, data, options, statTags = {}) => {
} finally {
fireHTTPStats(clientResponse, startTime, statTags);
}
setResponsesForMockAxiosAdapter(
{ url, data, options: requestOptions, method: 'PUT' },
clientResponse,
);
setResponsesForMockAxiosAdapter({ url, data, options, method: 'PUT' }, clientResponse);
return clientResponse;
};

Expand All @@ -238,10 +229,7 @@ const httpPATCH = async (url, data, options, statTags = {}) => {
} finally {
fireHTTPStats(clientResponse, startTime, statTags);
}
setResponsesForMockAxiosAdapter(
{ url, data, options: requestOptions, method: 'PATCH' },
clientResponse,
);
setResponsesForMockAxiosAdapter({ url, data, options, method: 'PATCH' }, clientResponse);
return clientResponse;
};

Expand Down
15 changes: 10 additions & 5 deletions src/v0/destinations/canny/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const retrieveUserId = async (apiKey, message) => {
message.traits?.email || message.context?.traits?.email || message.properties?.email;
const { userId } = message;

const header = {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: JSON_MIME_TYPE,
};
Expand All @@ -38,10 +38,15 @@ const retrieveUserId = async (apiKey, message) => {
} else {
requestBody.userID = `${userId}`;
}
const response = await httpPOST(url, qs.stringify(requestBody), header, {
destType: 'canny',
feature: 'transformation',
});
const response = await httpPOST(
url,
qs.stringify(requestBody),
{ headers },
{
destType: 'canny',
feature: 'transformation',
},
);
logger.debug(response);
// If the request fails, throwing error.
if (response.success === false) {
Expand Down
6 changes: 3 additions & 3 deletions src/v0/destinations/yahoo_dsp/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const qs = require('qs');
const sha256 = require('sha256');
const { generateJWTToken } = require('../../../util/jwtTokenGenerator');
const { httpPOST } = require('../../../adapters/network');
const { httpSend } = require('../../../adapters/network');
const { isDefinedAndNotNullAndNotEmpty } = require('../../util');
const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils');
const { ACCESS_TOKEN_CACHE_TTL, AUDIENCE_ATTRIBUTE, DSP_SUPPORTED_OPERATION } = require('./config');
Expand Down Expand Up @@ -119,7 +119,7 @@ const getAccessToken = async (destination) => {
};

const request = {
header: {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: JSON_MIME_TYPE,
},
Expand All @@ -134,7 +134,7 @@ const getAccessToken = async (destination) => {
}),
method: 'POST',
};
const dspAuthorisationData = await httpPOST(request.url, request.data, request.header, {
const dspAuthorisationData = await httpSend(request, {
destType: 'yahoo_dsp',
feature: 'transformation',
});
Expand Down
17 changes: 12 additions & 5 deletions test/integrations/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Server } from 'http';
import { appendFileSync } from 'fs';
import { responses } from '../testHelper';
import utils from '../../src/v0/util';
import isMatch from 'lodash/isMatch';

// To run single destination test cases
// npm run test:ts -- component --destination=adobe_analytics
Expand Down Expand Up @@ -79,26 +80,32 @@ if (!opts.generate || opts.generate === 'false') {
const { url, method, data: reqData, ...opts } = axiosMock.httpReq;
const { data, headers, status } = axiosMock.httpRes;

const headersAsymMatch = {
asymmetricMatch: function (actual) {
return isMatch(actual, opts.headers);
},
};

switch (method.toLowerCase()) {
case 'get':
// @ts-ignore
mock.onGet(url, reqData, opts.headers).reply(status, data, headers);
mock.onGet(url, reqData, headersAsymMatch).reply(status, data, headers);
break;
case 'delete':
// @ts-ignore
mock.onDelete(url, reqData, opts.headers).reply(status, data, headers);
mock.onDelete(url, reqData, headersAsymMatch).reply(status, data, headers);
break;
case 'post':
// @ts-ignore
mock.onPost(url, reqData, opts.headers).reply(status, data, headers);
mock.onPost(url, reqData, headersAsymMatch).reply(status, data, headers);
break;
case 'patch':
// @ts-ignore
mock.onPatch(url, reqData, opts.headers).reply(status, data, headers);
mock.onPatch(url, reqData, headersAsymMatch).reply(status, data, headers);
break;
case 'put':
// @ts-ignore
mock.onPut(url, reqData, opts.headers).reply(status, data, headers);
mock.onPut(url, reqData, headersAsymMatch).reply(status, data, headers);
break;
default:
break;
Expand Down
Loading

0 comments on commit 2029fb4

Please sign in to comment.