Skip to content

Commit

Permalink
fix: add test-cases for 5xx, 4xx failures
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Sankeerth <[email protected]>
  • Loading branch information
Sai Sankeerth committed Dec 12, 2023
1 parent 05e1803 commit a0a0f78
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/v0/destinations/active_campaign/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
feature: 'transformation',
});
if (res.success === false) {
errorHandler(res.response, 'Failed to fetch already created tags');
errorHandler(res, 'Failed to fetch already created tags');

Check warning on line 101 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L101

Added line #L101 was not covered by tests
}

const storedTags = {};
Expand Down Expand Up @@ -169,7 +169,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
feature: 'transformation',
});
if (res.success === false) {
errorHandler(res.response, 'Failed to create new tag');
errorHandler(res, 'Failed to create new tag');

Check warning on line 172 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L172

Added line #L172 was not covered by tests
// For each tags successfully created the response id is pushed to tagIds
}
if (res.response.status === 201) tagIds.push(res.response.data.tag.id);
Expand Down Expand Up @@ -201,7 +201,7 @@ const customTagProcessor = async (message, category, destination, contactId) =>
);
responsesArr.forEach((respItem) => {
if (respItem.success === false)
errorHandler(respItem.response, 'Failed to merge created contact with created tags');
errorHandler(respItem, 'Failed to merge created contact with created tags');

Check warning on line 204 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L204

Added line #L204 was not covered by tests
});
};

Expand All @@ -219,7 +219,7 @@ const customFieldProcessor = async (message, category, destination) => {
// Step - 2
// Get the existing field data from dest and store it in responseStaging
// Ref - https://developers.activecampaign.com/reference/retrieve-fields
let endpoint = `${destination.Config.apiUrl}${`${category.fieldEndPoint}?limit=100`}`;
let endpoint = `${destination.Config.apiUrl}${category.fieldEndPoint}?limit=100`;
const requestOptions = {
headers: {
'Api-Token': destination.Config.apiKey,
Expand All @@ -230,7 +230,7 @@ const customFieldProcessor = async (message, category, destination) => {
feature: 'transformation',
});
if (res.success === false) {
errorHandler(res.response, 'Failed to get existing field data');
errorHandler(res, 'Failed to get existing field data');

Check warning on line 233 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L233

Added line #L233 was not covered by tests
}
responseStaging.push(res.response.status === 200 ? res.response.data.fields : []);

Expand All @@ -257,7 +257,7 @@ const customFieldProcessor = async (message, category, destination) => {
if (resp.success === true && resp.response.status === 200) {
responseStaging.push(resp.response.data.fields);
} else {
errorHandler(resp.response, 'Failed to get existing field data');
errorHandler(resp, 'Failed to get existing field data');

Check warning on line 260 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L260

Added line #L260 was not covered by tests
}
});
}
Expand Down Expand Up @@ -352,7 +352,7 @@ const customListProcessor = async (message, category, destination, contactId) =>
const responses = await Promise.all(promises);
responses.forEach((respItem) => {
if (respItem.success === false) {
errorHandler(respItem.response, 'Failed to map created contact with the list');
errorHandler(respItem, 'Failed to map created contact with the list');

Check warning on line 355 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L355

Added line #L355 was not covered by tests
}
});
};
Expand Down Expand Up @@ -431,11 +431,11 @@ const screenRequestHandler = async (message, category, destination) => {
feature: 'transformation',
});
if (res.success === false) {
errorHandler(res.response, 'Failed to create event');
errorHandler(res, 'Failed to create event');

Check warning on line 434 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L434

Added line #L434 was not covered by tests
}

if (res.response.status !== 201) {
errorHandler(res.response, 'Unable to create event');
errorHandler(res, 'Unable to create event');

Check warning on line 438 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L438

Added line #L438 was not covered by tests
}
}
// Previous operations successfull then
Expand Down Expand Up @@ -468,11 +468,11 @@ const trackRequestHandler = async (message, category, destination) => {
});

if (res.success === false) {
errorHandler(res.response, 'Failed to retrieve events');
errorHandler(res, 'Failed to retrieve events');

Check warning on line 471 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L471

Added line #L471 was not covered by tests
}

if (res.response.status !== 200) {
errorHandler(res.response, 'Unable to fetch events. Aborting');
errorHandler(res, 'Unable to fetch events. Aborting');

Check warning on line 475 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L475

Added line #L475 was not covered by tests
}

const storedEventsArr = res.response?.data?.eventTrackingEvents;
Expand All @@ -495,7 +495,7 @@ const trackRequestHandler = async (message, category, destination) => {
feature: 'transformation',
});
if (res.response?.status !== 201) {
errorHandler(res.response, 'Unable to create event. Aborting');
errorHandler(res, 'Unable to create event. Aborting');

Check warning on line 498 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L498

Added line #L498 was not covered by tests
}
}

Expand Down
Loading

0 comments on commit a0a0f78

Please sign in to comment.