From f00d411c254d69f0155c7aa267f187bf6f59f6d4 Mon Sep 17 00:00:00 2001 From: AASHISH MALIK Date: Fri, 15 Mar 2024 15:43:15 +0530 Subject: [PATCH] chore: algolia component tests (#3183) --- src/v1/destinations/algolia/networkHandler.js | 22 +- .../algolia/dataDelivery/business.ts | 331 +++++++++++ .../algolia/dataDelivery/constant.ts | 118 ++++ .../destinations/algolia/dataDelivery/data.ts | 9 + .../algolia/dataDelivery/other.ts | 524 ++++++++++++++++++ .../destinations/algolia/network.ts | 117 ++++ 6 files changed, 1117 insertions(+), 4 deletions(-) create mode 100644 test/integrations/destinations/algolia/dataDelivery/business.ts create mode 100644 test/integrations/destinations/algolia/dataDelivery/constant.ts create mode 100644 test/integrations/destinations/algolia/dataDelivery/data.ts create mode 100644 test/integrations/destinations/algolia/dataDelivery/other.ts create mode 100644 test/integrations/destinations/algolia/network.ts diff --git a/src/v1/destinations/algolia/networkHandler.js b/src/v1/destinations/algolia/networkHandler.js index 21f415197f..de25993fb1 100644 --- a/src/v1/destinations/algolia/networkHandler.js +++ b/src/v1/destinations/algolia/networkHandler.js @@ -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, @@ -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, ); }; diff --git a/test/integrations/destinations/algolia/dataDelivery/business.ts b/test/integrations/destinations/algolia/dataDelivery/business.ts new file mode 100644 index 0000000000..8ba964e2dd --- /dev/null +++ b/test/integrations/destinations/algolia/dataDelivery/business.ts @@ -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, + }, + }, + }, + }, + }, +]; diff --git a/test/integrations/destinations/algolia/dataDelivery/constant.ts b/test/integrations/destinations/algolia/dataDelivery/constant.ts new file mode 100644 index 0000000000..e8d0817a7f --- /dev/null +++ b/test/integrations/destinations/algolia/dataDelivery/constant.ts @@ -0,0 +1,118 @@ +const proxyMetdata1 = { + jobId: 1, + attemptNum: 1, + userId: 'dummyUserId', + sourceId: 'dummySourceId', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + secret: {}, + dontBatch: false, +}; + +const proxyMetdata2 = { + jobId: 2, + attemptNum: 1, + userId: 'dummyUserId', + sourceId: 'dummySourceId', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + secret: {}, + dontBatch: false, +}; + +export const metadataArray = [proxyMetdata1, proxyMetdata2]; + +export const abortStatTags = { + errorCategory: 'network', + errorType: 'aborted', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', +}; + +export const commonRequestProperties = { + commonHeaders: { + 'X-Algolia-API-Key': 'dummyApiKey', + 'X-Algolia-Application-Id': 'O2YARRI15I', + 'User-Agent': 'RudderLabs', + }, + singleValidEvent: { + events: [ + { + eventName: 'product clicked', + eventType: 'click', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, + singleInValidEvent: { + events: [ + { + eventName: 'product clicked', + eventType: 'abc', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, + multipleValidEvent: { + events: [ + { + eventName: 'product clicked', + eventType: 'click', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + { + eventName: 'product clicked', + eventType: 'view', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, + combinedValidInvalidEvents: { + events: [ + { + eventName: 'product clicked', + eventType: 'click', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + { + eventName: 'product clicked', + eventType: 'view', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + { + eventName: 'product clicked', + eventType: 'abc', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, +}; + +export const retryStatTags = { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', +}; diff --git a/test/integrations/destinations/algolia/dataDelivery/data.ts b/test/integrations/destinations/algolia/dataDelivery/data.ts new file mode 100644 index 0000000000..feb4eb46c5 --- /dev/null +++ b/test/integrations/destinations/algolia/dataDelivery/data.ts @@ -0,0 +1,9 @@ +import { testScenariosForV0API, testScenariosForV1API } from './business'; +import { otherScenariosV0, otherScenariosV1 } from './other'; + +export const data = [ + ...testScenariosForV0API, + ...testScenariosForV1API, + ...otherScenariosV0, + ...otherScenariosV1, +]; diff --git a/test/integrations/destinations/algolia/dataDelivery/other.ts b/test/integrations/destinations/algolia/dataDelivery/other.ts new file mode 100644 index 0000000000..f5ccc70337 --- /dev/null +++ b/test/integrations/destinations/algolia/dataDelivery/other.ts @@ -0,0 +1,524 @@ +import { ProxyV1TestData } from '../../../testTypes'; +import { generateProxyV0Payload, generateProxyV1Payload } from '../../../testUtils'; + +export const otherScenariosV0 = [ + { + id: 'algolia_v0_other_scenario_1', + name: 'algolia', + description: + '[Proxy v0 API] :: Scenario for testing Service Unavailable error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + endpoint: 'https://random_test_url/test_for_service_not_available', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 503, + body: { + output: { + status: 503, + message: + '[Generic Response Handler] Request failed for destination algolia with status: 503', + destinationResponse: { + response: { + error: { + message: 'Service Unavailable', + description: + 'The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later.', + }, + }, + status: 503, + }, + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + }, + }, + }, + }, + }, + { + id: 'algolia_v0_other_scenario_2', + name: 'algolia', + description: '[Proxy v0 API] :: Scenario for testing Internal Server error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + endpoint: 'https://random_test_url/test_for_internal_server_error', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 500, + body: { + output: { + status: 500, + message: + '[Generic Response Handler] Request failed for destination algolia with status: 500', + destinationResponse: { + response: 'Internal Server Error', + status: 500, + }, + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + }, + }, + }, + }, + }, + { + id: 'algolia_v0_other_scenario_3', + name: 'algolia', + description: '[Proxy v0 API] :: Scenario for testing Gateway Time Out error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + endpoint: 'https://random_test_url/test_for_gateway_time_out', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 504, + body: { + output: { + status: 504, + message: + '[Generic Response Handler] Request failed for destination algolia with status: 504', + destinationResponse: { + response: 'Gateway Timeout', + status: 504, + }, + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + }, + }, + }, + }, + }, + { + id: 'algolia_v0_other_scenario_4', + name: 'algolia', + description: '[Proxy v0 API] :: Scenario for testing null response from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + endpoint: 'https://random_test_url/test_for_null_response', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 500, + body: { + output: { + status: 500, + message: + '[Generic Response Handler] Request failed for destination algolia with status: 500', + destinationResponse: { + response: '', + status: 500, + }, + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + }, + }, + }, + }, + }, + { + id: 'algolia_v0_other_scenario_5', + name: 'algolia', + description: + '[Proxy v0 API] :: Scenario for testing null and no status response from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + endpoint: 'https://random_test_url/test_for_null_and_no_status', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 500, + body: { + output: { + status: 500, + message: + '[Generic Response Handler] Request failed for destination algolia with status: 500', + destinationResponse: { + response: '', + status: 500, + }, + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + }, + }, + }, + }, + }, +]; + +export const otherScenariosV1: ProxyV1TestData[] = [ + { + id: 'algolia_v1_other_scenario_1', + name: 'algolia', + description: + '[Proxy v1 API] :: Scenario for testing Service Unavailable error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_service_not_available', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: + '{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}', + statusCode: 503, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: true, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation', + status: 503, + }, + }, + }, + }, + }, + { + id: 'algolia_v1_other_scenario_2', + name: 'algolia', + description: '[Proxy v1 API] :: Scenario for testing Internal Server error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_internal_server_error', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: '"Internal Server Error"', + statusCode: 500, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: true, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation', + status: 500, + }, + }, + }, + }, + }, + { + id: 'algolia_v1_other_scenario_3', + name: 'algolia', + description: '[Proxy v1 API] :: Scenario for testing Gateway Time Out error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_gateway_time_out', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: '"Gateway Timeout"', + statusCode: 504, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: true, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation', + status: 504, + }, + }, + }, + }, + }, + { + id: 'algolia_v1_other_scenario_4', + name: 'algolia', + description: '[Proxy v1 API] :: Scenario for testing null response from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_null_response', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: '""', + statusCode: 500, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: true, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation', + status: 500, + }, + }, + }, + }, + }, + { + id: 'algolia_v1_other_scenario_5', + name: 'algolia', + description: + '[Proxy v1 API] :: Scenario for testing null and no status response from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_null_and_no_status', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: '""', + statusCode: 500, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: true, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ALGOLIA', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: 'ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation', + status: 500, + }, + }, + }, + }, + }, +]; diff --git a/test/integrations/destinations/algolia/network.ts b/test/integrations/destinations/algolia/network.ts new file mode 100644 index 0000000000..84e932bbdb --- /dev/null +++ b/test/integrations/destinations/algolia/network.ts @@ -0,0 +1,117 @@ +export const networkCallsData = [ + { + httpReq: { + url: 'https://insights.algolia.io/1/events', + data: { + events: [ + { + eventName: 'product clicked', + eventType: 'abc', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, + params: {}, + headers: { 'User-Agent': 'RudderLabs' }, + method: 'POST', + }, + httpRes: { + data: { + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', + }, + status: 422, + }, + }, + { + httpReq: { + url: 'https://insights.algolia.io/1/events', + data: { + events: [ + { + eventName: 'product clicked', + eventType: 'abc', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + { + eventName: 'product clicked', + eventType: 'click', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, + params: {}, + headers: { 'User-Agent': 'RudderLabs' }, + method: 'POST', + }, + httpRes: { + data: { + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', + }, + status: 422, + }, + }, + { + httpReq: { + url: 'https://insights.algolia.io/1/events', + data: { + events: [ + { + eventName: 'product clicked', + eventType: 'click', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + { + eventName: 'product clicked', + eventType: 'view', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + { + eventName: 'product clicked', + eventType: 'abc', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', + }, + ], + }, + params: {}, + headers: { 'User-Agent': 'RudderLabs' }, + method: 'POST', + }, + httpRes: { + data: { + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', + }, + status: 422, + }, + }, + { + httpReq: { + url: 'https://insights.algolia.io/1/events', + method: 'POST', + headers: { + 'User-Agent': 'RudderLabs', + }, + }, + httpRes: { + data: { + status: 200, + message: 'OK', + }, + status: 200, + }, + }, +];