diff --git a/src/v0/destinations/sprig/deleteUsers.js b/src/v0/destinations/sprig/deleteUsers.js index f0532d91e8..147e9ac906 100644 --- a/src/v0/destinations/sprig/deleteUsers.js +++ b/src/v0/destinations/sprig/deleteUsers.js @@ -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 @@ -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, diff --git a/test/integrations/destinations/sprig/deleteUsers/data.ts b/test/integrations/destinations/sprig/deleteUsers/data.ts index bf71a5ff9b..7ab5620e66 100644 --- a/test/integrations/destinations/sprig/deleteUsers/data.ts +++ b/test/integrations/destinations/sprig/deleteUsers/data.ts @@ -65,10 +65,10 @@ export const data = [ }, output: { response: { - status: 401, + status: 403, body: [ { - statusCode: 401, + statusCode: 403, error: 'User deletion request failed', }, ], @@ -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', @@ -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', @@ -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', diff --git a/test/integrations/destinations/sprig/network.ts b/test/integrations/destinations/sprig/network.ts index 1cc286cd5c..e5f2ff23b1 100644 --- a/test/integrations/destinations/sprig/network.ts +++ b/test/integrations/destinations/sprig/network.ts @@ -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, }, }, {