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 index 7ce8847cf4..8ba964e2dd 100644 --- a/test/integrations/destinations/algolia/dataDelivery/business.ts +++ b/test/integrations/destinations/algolia/dataDelivery/business.ts @@ -1,102 +1,21 @@ import { ProxyV1TestData } from '../../../testTypes'; -import { - generateMetadata, - generateProxyV0Payload, - generateProxyV1Payload, -} from '../../../testUtils'; -import { commonRequestParameters } from './constant'; - -const pardotResponseRogerEmail = { - '@attributes': { stat: 'ok', version: 1 }, - prospect: { - id: 123435, - campaign_id: 42213, - salutation: null, - first_name: 'Roger_12', - last_name: 'Federer_12', - email: 'Roger_12@federer.io', - password: null, - company: null, - website: 'https://rudderstack.com', - job_title: null, - department: null, - country: 'AU', - address_one: null, - address_two: null, - city: null, - state: null, - territory: null, - zip: null, - phone: null, - fax: null, - source: null, - annual_revenue: null, - employees: null, - industry: null, - years_in_business: null, - comments: null, - notes: null, - score: 14, - grade: null, - last_activity_at: null, - recent_interaction: 'Never active.', - crm_lead_fid: '00Q6r000002LKhTPVR', - crm_contact_fid: null, - crm_owner_fid: '00G2v000004WYXaEAO', - crm_account_fid: null, - salesforce_fid: '00Q6r000002LKhTPVR', - crm_last_sync: '2022-01-21 18:47:37', - crm_url: 'https://testcompany.my.salesforce.com/00Q6r000002LKhTPVR', - is_do_not_email: null, - is_do_not_call: null, - opted_out: null, - is_reviewed: 1, - is_starred: null, - created_at: '2022-01-21 18:21:46', - updated_at: '2022-01-21 18:48:41', - campaign: { id: 42113, name: 'Test', crm_fid: '7012y000000MNOCLL4' }, - assigned_to: { - user: { - id: 38443703, - email: 'test_rudderstack@testcompany.com', - first_name: 'Rudderstack', - last_name: 'User', - job_title: null, - role: 'Administrator', - account: 489853, - created_at: '2021-02-26 06:25:17', - updated_at: '2021-02-26 06:25:17', - }, - }, - Are_you_shipping_large_fragile_or_bulky_items: false, - Calendly: false, - Country_Code: 'AU', - Currency: 'AUD', - Inventory_or_Warehouse_Management_System: false, - Lead_Status: 'New', - Marketing_Stage: 'SAL', - Record_Type_ID: 'TestCompany Lead', - profile: { - id: 304, - name: 'Default', - profile_criteria: [ - { id: 1500, name: 'Shipping Volume', matches: 'Unknown' }, - { id: 1502, name: 'Industry', matches: 'Unknown' }, - { id: 1506, name: 'Job Title', matches: 'Unknown' }, - { id: 1508, name: 'Department', matches: 'Unknown' }, - ], - }, - visitors: null, - visitor_activities: null, - lists: null, - }, +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 no batching', + description: '[Proxy v0 API] :: algolia all valid events', successCriteria: 'Proper response from destination is received', scenario: 'Business', feature: 'dataDelivery', @@ -105,7 +24,7 @@ export const testScenariosForV0API = [ input: { request: { body: generateProxyV0Payload({ - ...commonRequestParameters, + ...commonRequestProperties.commonHeaders, endpoint: 'https://insights.algolia.io/1/events', }), method: 'POST', @@ -132,10 +51,10 @@ export const testScenariosForV0API = [ }, }, { - id: 'algolia_v0_bussiness_scenario_1', + id: 'algolia_v0_bussiness_scenario_2', name: 'algolia', - description: '[Proxy v0 API] :: algolia all valid events with batching batching', - successCriteria: 'Proper response from destination is received', + description: '[Proxy v0 API] :: algolia with invalid event', + successCriteria: 'Error Response from destination is received', scenario: 'Business', feature: 'dataDelivery', module: 'destination', @@ -143,27 +62,69 @@ export const testScenariosForV0API = [ input: { request: { body: generateProxyV0Payload({ - ...commonRequestParameters, + ...commonRequestProperties.commonHeaders, endpoint: 'https://insights.algolia.io/1/events', + JSON: commonRequestProperties.singleInValidEvent, }), method: 'POST', }, }, output: { response: { - status: 200, + status: 422, body: { output: { - status: 200, + status: 422, message: - '[Generic Response Handler] Request for destination: algolia Processed Successfully', + '[Generic Response Handler] Request failed for destination algolia with status: 422', destinationResponse: { response: { - message: 'OK', - status: 200, + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', }, - status: 200, + 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, }, }, }, @@ -175,18 +136,71 @@ export const testScenariosForV1API: ProxyV1TestData[] = [ { id: 'algolia_v1_bussiness_scenario_1', name: 'algolia', - description: '[Proxy v1 API] :: pardot email type upsert', - successCriteria: 'Proper response from destination is received', - scenario: 'business', + 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({ - ...commonRequestParameters, - endpoint: - 'https://pi.pardot.com/api/prospect/version/4/do/upsert/email/Roger_12@waltair.io', + ...commonRequestProperties.commonHeaders, + endpoint: 'https://insights.algolia.io/1/events', + JSON: commonRequestProperties.singleInValidEvent, }), method: 'POST', }, @@ -196,15 +210,119 @@ export const testScenariosForV1API: ProxyV1TestData[] = [ status: 200, body: { output: { - status: 201, - message: 'Request Processed Successfully', + 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: [ { - statusCode: 201, - metadata: generateMetadata(1), - error: JSON.stringify('{}'), + 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 index 689e8fb0c4..e8d0817a7f 100644 --- a/test/integrations/destinations/algolia/dataDelivery/constant.ts +++ b/test/integrations/destinations/algolia/dataDelivery/constant.ts @@ -1,25 +1,118 @@ -export const retryStatTags = { - destType: 'PARDOT', +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', - errorType: 'retryable', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', -}; -const commonHeaders = { - 'X-Algolia-API-Key': 'dummyApiKey', - 'X-Algolia-Application-Id': 'O2YARRI15I', }; -export const commonRequestParameters = { - headers: commonHeaders, - FORM: { - first_name: 'Roger12', - last_name: 'Federer12', - website: 'https://rudderstack.com', - score: 14, - campaign_id: 42213, +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 index 37f96a02fe..feb4eb46c5 100644 --- a/test/integrations/destinations/algolia/dataDelivery/data.ts +++ b/test/integrations/destinations/algolia/dataDelivery/data.ts @@ -1,3 +1,9 @@ -import { testScenariosForV0API } from './business'; +import { testScenariosForV0API, testScenariosForV1API } from './business'; +import { otherScenariosV0, otherScenariosV1 } from './other'; -export const data = [...testScenariosForV0API]; +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 index 2ddab58839..84e932bbdb 100644 --- a/test/integrations/destinations/algolia/network.ts +++ b/test/integrations/destinations/algolia/network.ts @@ -1,308 +1,117 @@ -import { getFormData } from '../../../../src/adapters/network'; - export const networkCallsData = [ { httpReq: { url: 'https://insights.algolia.io/1/events', - method: 'POST', - headers: { - 'X-Algolia-API-Key': 'dummyApiKey', - 'X-Algolia-Application-Id': 'O2YARRI15I', + 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: 200, - message: 'OK', + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', }, - status: 200, + status: 422, }, }, { httpReq: { - url: 'https://pi.pardot.com/api/prospect/version/4/do/upsert/fid/00Q6r000002LKhTPVR', - method: 'POST', - }, - httpRes: { + url: 'https://insights.algolia.io/1/events', data: { - '@attributes': { - stat: 'ok', - version: 1, - }, - prospect: { - id: 123435, - campaign_id: 42213, - salutation: null, - first_name: 'Roger_12', - last_name: 'Federer_12', - email: 'Roger_12@federer.io', - password: null, - company: null, - website: 'https://rudderstack.com', - job_title: null, - department: null, - country: 'AU', - address_one: null, - address_two: null, - city: null, - state: null, - territory: null, - zip: null, - phone: null, - fax: null, - source: null, - annual_revenue: null, - employees: null, - industry: null, - years_in_business: null, - comments: null, - notes: null, - score: 14, - grade: null, - last_activity_at: null, - recent_interaction: 'Never active.', - crm_lead_fid: '00Q6r000002LKhTPVR', - crm_contact_fid: null, - crm_owner_fid: '00G2v000004WYXaEAO', - crm_account_fid: null, - salesforce_fid: '00Q6r000002LKhTPVR', - crm_last_sync: '2022-01-21 18:47:37', - crm_url: 'https://testcompany.my.salesforce.com/00Q6r000002LKhTPVR', - is_do_not_email: null, - is_do_not_call: null, - opted_out: null, - is_reviewed: 1, - is_starred: null, - created_at: '2022-01-21 18:21:46', - updated_at: '2022-01-21 18:48:41', - campaign: { - id: 42113, - name: 'Test', - crm_fid: '7012y000000MNOCLL4', + events: [ + { + eventName: 'product clicked', + eventType: 'abc', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', }, - assigned_to: { - user: { - id: 38443703, - email: 'test_rudderstack@testcompany.com', - first_name: 'Rudderstack', - last_name: 'User', - job_title: null, - role: 'Administrator', - account: 489853, - created_at: '2021-02-26 06:25:17', - updated_at: '2021-02-26 06:25:17', - }, + { + eventName: 'product clicked', + eventType: 'click', + filters: ['field1:hello', 'val1:val2'], + index: 'products', + userToken: 'testuserId1', }, - Are_you_shipping_large_fragile_or_bulky_items: false, - Calendly: false, - Country_Code: 'AU', - Currency: 'AUD', - Inventory_or_Warehouse_Management_System: false, - Lead_Status: 'New', - Marketing_Stage: 'SAL', - Record_Type_ID: 'TestCompany Lead', - profile: { - id: 304, - name: 'Default', - profile_criteria: [ - { - id: 1500, - name: 'Shipping Volume', - matches: 'Unknown', - }, - { - id: 1502, - name: 'Industry', - matches: 'Unknown', - }, - { - id: 1506, - name: 'Job Title', - matches: 'Unknown', - }, - { - id: 1508, - name: 'Department', - matches: 'Unknown', - }, - ], - }, - visitors: null, - visitor_activities: null, - lists: null, - }, + ], }, - status: 200, - statusText: 'OK', - }, - }, - { - httpReq: { - url: 'https://pi.pardot.com/api/prospect/version/4/do/upsert/email/rolex_waltair@mywebsite.io', + params: {}, + headers: { 'User-Agent': 'RudderLabs' }, method: 'POST', }, httpRes: { data: { - '@attributes': { - stat: 'fail', - version: 1, - err_code: 184, - }, - err: 'access_token is invalid, unknown, or malformed: Inactive token', + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', }, - status: 401, - statusText: 'Unauthorized', + status: 422, }, }, { httpReq: { - url: 'https://pi.pardot.com/api/prospect/version/4/do/upsert/id/123435', - data: getFormData({ - first_name: 'Roger12', - last_name: 'Federer12', - website: 'https://rudderstack.com', - score: 14, - campaign_id: 42213, - format: 'json', - }).toString(), - params: { destination: 'pardot' }, - headers: { - Authorization: 'Bearer myToken', - 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', - 'Pardot-Business-Unit-Id': '0Uv2v000000k9tHCAQ', - 'User-Agent': 'RudderLabs', + 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: { - '@attributes': { - stat: 'ok', - version: 1, - }, - prospect: { - id: 123435, - campaign_id: 42213, - salutation: null, - first_name: 'Roger12', - last_name: 'Federer12', - email: 'Roger12@waltair.io', - password: null, - company: null, - website: 'https://rudderstack.com', - job_title: null, - department: null, - country: 'AU', - address_one: null, - address_two: null, - city: null, - state: null, - territory: null, - zip: null, - phone: null, - fax: null, - source: null, - annual_revenue: null, - employees: null, - industry: null, - years_in_business: null, - comments: null, - notes: null, - score: 14, - grade: null, - last_activity_at: null, - recent_interaction: 'Never active.', - crm_lead_fid: null, - crm_contact_fid: null, - crm_owner_fid: '00G2v000004WYXaEAO', - crm_account_fid: null, - salesforce_fid: null, - crm_last_sync: null, - crm_url: null, - is_do_not_email: null, - is_do_not_call: null, - opted_out: null, - is_reviewed: 1, - is_starred: null, - created_at: '2022-01-21 18:21:46', - updated_at: '2022-01-21 18:48:41', - campaign: { - id: 42113, - name: 'Test', - crm_fid: '7012y000000MNOCLL4', - }, - assigned_to: { - user: { - id: 38443703, - email: 'test_rudderstack@testcompany.com', - first_name: 'Rudderstack', - last_name: 'User', - job_title: null, - role: 'Administrator', - account: 489853, - created_at: '2021-02-26 06:25:17', - updated_at: '2021-02-26 06:25:17', - }, - }, - Are_you_shipping_large_fragile_or_bulky_items: false, - Calendly: false, - Country_Code: 'AU', - Currency: 'AUD', - Inventory_or_Warehouse_Management_System: false, - Lead_Status: 'New', - Marketing_Stage: 'SAL', - Record_Type_ID: 'TestCompany Lead', - profile: { - id: 304, - name: 'Default', - profile_criteria: [ - { - id: 1500, - name: 'Shipping Volume', - matches: 'Unknown', - }, - { - id: 1502, - name: 'Industry', - matches: 'Unknown', - }, - { - id: 1506, - name: 'Job Title', - matches: 'Unknown', - }, - { - id: 1508, - name: 'Department', - matches: 'Unknown', - }, - ], - }, - visitors: null, - visitor_activities: null, - lists: null, - }, + status: 422, + message: 'EventType must be one of "click", "conversion" or "view"', }, - status: 200, - statusText: 'OK', + status: 422, }, }, { httpReq: { - url: 'https://pi.pardot.com/api/prospect/version/4/do/upsert/email/rolex_waltair@test.com', + url: 'https://insights.algolia.io/1/events', method: 'POST', + headers: { + 'User-Agent': 'RudderLabs', + }, }, httpRes: { data: { - '@attributes': { - stat: 'fail', - version: 1, - err_code: 120, - }, - err: 'Unable to verify Salesforce connector', + status: 200, + message: 'OK', }, - status: 500, - statusText: 'Invalid action', + status: 200, }, }, ];