Skip to content

Commit

Permalink
fix: fixing network handler for catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
manish339k committed Aug 8, 2024
1 parent d6a9059 commit 333fa07
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 4 deletions.
29 changes: 27 additions & 2 deletions src/v1/destinations/bloomreach/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,33 @@ const tags = require('../../../v0/util/tags');
// "end_time": 1710750816.8518236,
// "success": true
// }
// Catalog response =>
// [
// {
// "errors": {
// "properties": [
// "Fields [field1, field2] are not properly defined."
// ]
// },
// "queued": false,
// "success": false
// },
// {
// "success" : "True",
// "queued" : "True",
// },
// ]
const checkIfEventIsAbortableAndExtractErrorMessage = (element) => {
if (element.success) {
return { isAbortable: false, errorMsg: '' };
}

const errorMsg = element.errors.join(', ');
const errorMsg = Array.isArray(element.errors)
? element.errors.join(', ')
: Object.values(element.errors || {})
.flat()
.join(', ');

return { isAbortable: true, errorMsg };
};

Expand All @@ -41,7 +62,11 @@ const responseHandler = (responseParams) => {

if (isHttpStatusSuccess(status)) {
// check for Partial Event failures and Successes
const { results } = response;
let { results } = response;
// in case of catalog response
if (Array.isArray(response)) {
results = response;
}
results.forEach((event, idx) => {
const proxyOutput = {
statusCode: 200,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProxyV1TestData } from '../../../testTypes';
import { generateProxyV1Payload, generateMetadata } from '../../../testUtils';
import { destType, headers, properties, endpoint } from '../common';
import { destType, headers, properties, endpoint, updateEndpoint } from '../common';

const customerProperties = {
email: '[email protected]',
Expand Down Expand Up @@ -192,4 +192,69 @@ export const businessProxyV1: ProxyV1TestData[] = [
},
},
},
{
id: 'bloomreach_v1_business_scenario_3',
name: destType,
description:
'[Proxy v1 API] :: Test for a valid rETL request - where the destination responds with 200 with error',
successCriteria: 'Should return 400 with error message',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
headers,
params: {},
JSON: {},
JSON_ARRAY: {
batch: [
{
item_id: 'test-item-id-faulty',
properties: {
unprinted1: '1',
},
},
],
},
endpoint: updateEndpoint,
},
[generateMetadata(3)],
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
status: 200,
message: '[BLOOMREACH Response V1 Handler] - Request Processed Successfully',
destinationResponse: {
response: [
{
success: false,
queued: false,
errors: {
properties: ['Fields [unprinted1] are not properly defined.'],
},
},
],
status: 200,
},
response: [
{
statusCode: 400,
metadata: generateMetadata(3),
error: 'Fields [unprinted1] are not properly defined.',
},
],
},
},
},
},
},
];
31 changes: 30 additions & 1 deletion test/integrations/destinations/bloomreach/network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { destType, headers, properties, endpoint } from './common';
import { destType, headers, properties, endpoint, updateEndpoint } from './common';

export const networkCallsData = [
{
Expand Down Expand Up @@ -121,4 +121,33 @@ export const networkCallsData = [
statusText: 'Ok',
},
},
{
httpReq: {
url: updateEndpoint,
data: [
{
item_id: 'test-item-id-faulty',
properties: {
unprinted1: '1',
},
},
],
params: { destination: destType },
headers,
method: 'POST',
},
httpRes: {
data: [
{
success: false,
queued: false,
errors: {
properties: ['Fields [unprinted1] are not properly defined.'],
},
},
],
status: 200,
statusText: 'Ok',
},
},
];

0 comments on commit 333fa07

Please sign in to comment.