Skip to content

Commit

Permalink
Merge branch 'develop' into chore.addmetricsForReqSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayachand authored Mar 15, 2024
2 parents 8bb568d + f00d411 commit 2cb2d13
Show file tree
Hide file tree
Showing 6 changed files with 1,117 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/v1/destinations/algolia/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax */
const { TransformerProxyError } = require('../../../v0/util/errorTypes');
const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network');
const { isHttpStatusSuccess, getAuthErrCategoryFromStCode } = require('../../../v0/util/index');
const { isHttpStatusSuccess } = require('../../../v0/util/index');

const {
processAxiosResponse,
Expand Down Expand Up @@ -44,15 +44,29 @@ const responseHandler = (responseParams) => {
});
}

// sending back 500 for retry
// At least one event in the batch is invalid.
if (status === 422) {
// sending back 500 for retry
throw new TransformerProxyError(
`ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation`,
500,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(500),
},
destinationResponse,
'',
responseWithIndividualEvents,
);
}

throw new TransformerProxyError(
`ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation`,
500,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
getAuthErrCategoryFromStCode(status),
'',
responseWithIndividualEvents,
);
};
Expand Down
331 changes: 331 additions & 0 deletions test/integrations/destinations/algolia/dataDelivery/business.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
import { ProxyV1TestData } from '../../../testTypes';
import { generateProxyV0Payload, generateProxyV1Payload } from '../../../testUtils';
import { abortStatTags, commonRequestProperties, metadataArray, retryStatTags } from './constant';
const proxyMetdata3 = {
jobId: 3,
attemptNum: 1,
userId: 'dummyUserId',
sourceId: 'dummySourceId',
destinationId: 'dummyDestinationId',
workspaceId: 'dummyWorkspaceId',
secret: {},
dontBatch: false,
};
export const testScenariosForV0API = [
{
id: 'algolia_v0_bussiness_scenario_1',
name: 'algolia',
description: '[Proxy v0 API] :: algolia all valid events',
successCriteria: 'Proper response from destination is received',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: generateProxyV0Payload({
...commonRequestProperties.commonHeaders,
endpoint: 'https://insights.algolia.io/1/events',
}),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
status: 200,
message:
'[Generic Response Handler] Request for destination: algolia Processed Successfully',
destinationResponse: {
response: {
message: 'OK',
status: 200,
},
status: 200,
},
},
},
},
},
},
{
id: 'algolia_v0_bussiness_scenario_2',
name: 'algolia',
description: '[Proxy v0 API] :: algolia with invalid event',
successCriteria: 'Error Response from destination is received',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: generateProxyV0Payload({
...commonRequestProperties.commonHeaders,
endpoint: 'https://insights.algolia.io/1/events',
JSON: commonRequestProperties.singleInValidEvent,
}),
method: 'POST',
},
},
output: {
response: {
status: 422,
body: {
output: {
status: 422,
message:
'[Generic Response Handler] Request failed for destination algolia with status: 422',
destinationResponse: {
response: {
status: 422,
message: 'EventType must be one of "click", "conversion" or "view"',
},
status: 422,
},
statTags: abortStatTags,
},
},
},
},
},
{
id: 'algolia_v0_bussiness_scenario_3',
name: 'algolia',
description: '[Proxy v0 API] :: algolia with invalid events in batch',
successCriteria: 'Error Response from destination is received',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v0',
input: {
request: {
body: generateProxyV0Payload({
...commonRequestProperties.commonHeaders,
endpoint: 'https://insights.algolia.io/1/events',
JSON: commonRequestProperties.combinedValidInvalidEvents,
}),
method: 'POST',
},
},
output: {
response: {
status: 422,
body: {
output: {
status: 422,
message:
'[Generic Response Handler] Request failed for destination algolia with status: 422',
destinationResponse: {
response: {
status: 422,
message: 'EventType must be one of "click", "conversion" or "view"',
},
status: 422,
},
statTags: abortStatTags,
},
},
},
},
},
];

export const testScenariosForV1API: ProxyV1TestData[] = [
{
id: 'algolia_v1_bussiness_scenario_1',
name: 'algolia',
description: '[Proxy v1 API] :: algolia all valid events in batch',
successCriteria: 'Success response from destination is received',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
...commonRequestProperties.commonHeaders,
endpoint: 'https://insights.algolia.io/1/events',
JSON: commonRequestProperties.multipleValidEvent,
},
metadataArray,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
status: 200,
message: '[ALGOLIA Response V1 Handler] - Request Processed Successfully',
destinationResponse: {
response: {
message: 'OK',
status: 200,
},
status: 200,
},
response: [
{
error: 'success',
metadata: metadataArray[0],
statusCode: 200,
},
{
error: 'success',
metadata: metadataArray[1],
statusCode: 200,
},
],
},
},
},
},
},
{
id: 'algolia_v1_bussiness_scenario_2',
name: 'algolia',
description: '[Proxy v1 API] :: algolia all invalid events in batch',
successCriteria: 'Send response with dontBatch as true',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload({
...commonRequestProperties.commonHeaders,
endpoint: 'https://insights.algolia.io/1/events',
JSON: commonRequestProperties.singleInValidEvent,
}),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
status: 500,
message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation',
response: [
{
error:
'{"status":422,"message":"EventType must be one of \\"click\\", \\"conversion\\" or \\"view\\""}',
metadata: {
jobId: 1,
attemptNum: 1,
userId: 'default-userId',
destinationId: 'default-destinationId',
workspaceId: 'default-workspaceId',
sourceId: 'default-sourceId',
secret: {
accessToken: 'default-accessToken',
},
dontBatch: true,
},
statusCode: 500,
},
],
statTags: {
errorCategory: 'network',
errorType: 'retryable',
destType: 'ALGOLIA',
module: 'destination',
implementation: 'native',
feature: 'dataDelivery',
destinationId: 'default-destinationId',
workspaceId: 'default-workspaceId',
},
},
},
},
},
},
{
id: 'algolia_v1_bussiness_scenario_3',
name: 'algolia',
description: '[Proxy v1 API] :: algolia combination of valid and invalid events in batch',
successCriteria: 'Should use dontBatch true and proper response returned',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
...commonRequestProperties.commonHeaders,
endpoint: 'https://insights.algolia.io/1/events',
JSON: commonRequestProperties.combinedValidInvalidEvents,
},
[...metadataArray, proxyMetdata3],
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
status: 500,
message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation',
response: [
{
error:
'{"status":422,"message":"EventType must be one of \\"click\\", \\"conversion\\" or \\"view\\""}',
metadata: {
jobId: 1,
attemptNum: 1,
userId: 'dummyUserId',
sourceId: 'dummySourceId',
destinationId: 'dummyDestinationId',
workspaceId: 'dummyWorkspaceId',
secret: {},
dontBatch: true,
},
statusCode: 500,
},
{
error:
'{"status":422,"message":"EventType must be one of \\"click\\", \\"conversion\\" or \\"view\\""}',
metadata: {
jobId: 2,
attemptNum: 1,
userId: 'dummyUserId',
sourceId: 'dummySourceId',
destinationId: 'dummyDestinationId',
workspaceId: 'dummyWorkspaceId',
secret: {},
dontBatch: true,
},
statusCode: 500,
},
{
error:
'{"status":422,"message":"EventType must be one of \\"click\\", \\"conversion\\" or \\"view\\""}',
metadata: {
jobId: 3,
attemptNum: 1,
userId: 'dummyUserId',
sourceId: 'dummySourceId',
destinationId: 'dummyDestinationId',
workspaceId: 'dummyWorkspaceId',
secret: {},
dontBatch: true,
},
statusCode: 500,
},
],
statTags: retryStatTags,
},
},
},
},
},
];
Loading

0 comments on commit 2cb2d13

Please sign in to comment.