Skip to content

Commit

Permalink
chore: code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-4116 committed Jan 3, 2024
1 parent f80fae2 commit 65263d9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/v0/destinations/sprig/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const userDeletionHandler = async (userAttributes, config) => {
* Ref doc : https://docs.sprig.com/reference/post-v2-purge-visitors-1
*/
const userIdBatches = getUserIdBatches(userAttributes, 100);
// Note: The logic here intentionally avoided to use Promise.all
// Note: we will only get 400 status code when no user deletion is present for given userIds so we will not throw error in that case
// eslint-disable-next-line no-restricted-syntax
for (const curBatch of userIdBatches) {
// eslint-disable-next-line no-await-in-loop
Expand All @@ -52,7 +52,7 @@ const userDeletionHandler = async (userAttributes, config) => {
},
);
const handledDelResponse = processAxiosResponse(deletionResponse);
if (!isHttpStatusSuccess(handledDelResponse.status)) {
if (!isHttpStatusSuccess(handledDelResponse.status) && handledDelResponse.status !== 400) {
throw new NetworkError(
'User deletion request failed',
handledDelResponse.status,
Expand Down
73 changes: 68 additions & 5 deletions test/integrations/destinations/sprig/deleteUsers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export const data = [
},
output: {
response: {
status: 401,
status: 403,
body: [
{
statusCode: 401,
statusCode: 403,
error: 'User deletion request failed',
},
],
Expand All @@ -77,7 +77,7 @@ export const data = [
},
{
name: 'sprig',
description: 'Given userId is not present for user deletion',
description: 'Too many requests',
feature: 'userDeletion',
module: 'destination',
version: 'v0',
Expand All @@ -87,9 +87,36 @@ export const data = [
{
destType: 'SPRIG',
userAttributes: [
{
userId: '1',
},
{
userId: '2',
},
{
userId: '3',
},
{
userId: '4',
},
{
userId: '5',
},
{
userId: '6',
},
{
userId: '7',
},
{
userId: '8',
},
{
userId: '9',
},
{
userId: '10',
},
],
config: {
apiKey: 'testApiKey',
Expand All @@ -100,16 +127,52 @@ export const data = [
},
output: {
response: {
status: 400,
status: 429,
body: [
{
statusCode: 400,
statusCode: 429,
error: 'User deletion request failed',
},
],
},
},
},
{
name: 'sprig',
description: 'Given userId is not present for user deletion',
feature: 'userDeletion',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destType: 'SPRIG',
userAttributes: [
{
userId: '9',
},
],
config: {
apiKey: 'testApiKey',
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
statusCode: 200,
status: 'successful',
},
,
],
},
},
},
{
name: 'sprig',
description: 'Successful user deletion',
Expand Down
22 changes: 20 additions & 2 deletions test/integrations/destinations/sprig/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,26 @@ const deleteNwData = [
},
},
httpRes: {
data: 'User deletion request failed',
status: 401,
data: 'Forbidden',
status: 403,
},
},
{
httpReq: {
method: 'post',
url: 'https://api.sprig.com/v2/purge/visitors',
data: {
userIds: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
},
headers: {
Accept: 'application/json',
Authorization: 'API-Key testApiKey',
'Content-Type': 'application/json',
},
},
httpRes: {
data: 'Your application has made too many requests in too short a time.',
status: 429,
},
},
{
Expand Down

0 comments on commit 65263d9

Please sign in to comment.