@@ -205,6 +205,7 @@ describe('dedup utility tests', () => {
205205 // Mock the response from handleHttpRequest
206206 handleHttpRequest . mockResolvedValueOnce ( {
207207 processedResponse : {
208+ status : 200 ,
208209 response : {
209210 users : [
210211 {
@@ -272,31 +273,34 @@ describe('dedup utility tests', () => {
272273 // Call the function
273274 const users = await BrazeDedupUtility . doApiLookup ( identfierChunks , { destination } ) ;
274275
275- // Check the result
276+ // Check the result - now returns object with users and failedIdentifiers
276277 expect ( users ) . toEqual ( [
277- [
278- {
279- external_id : 'user1' ,
280- email : 'user1@example.com' ,
281- custom_attributes : {
282- key1 : 'value1' ,
278+ {
279+ users : [
280+ {
281+ external_id : 'user1' ,
282+ email : 'user1@example.com' ,
283+ custom_attributes : {
284+ key1 : 'value1' ,
285+ } ,
283286 } ,
284- } ,
285- {
286- external_id : 'user2' ,
287- email : 'user2@example.com' ,
288- custom_attributes : {
289- key2 : 'value2' ,
287+ {
288+ external_id : 'user2' ,
289+ email : 'user2@example.com ' ,
290+ custom_attributes : {
291+ key2 : 'value2' ,
292+ } ,
290293 } ,
291- } ,
292- {
293- user_aliases : [ { alias_name : 'user3' , alias_label : 'rudder_id' } ] ,
294- email : 'user3@example.com' ,
295- custom_attributes : {
296- key2 : 'value3' ,
294+ {
295+ user_aliases : [ { alias_name : 'user3' , alias_label : 'rudder_id' } ] ,
296+ email : 'user3@example.com' ,
297+ custom_attributes : {
298+ key2 : 'value3' ,
299+ } ,
297300 } ,
298- } ,
299- ] ,
301+ ] ,
302+ failedIdentifiers : [ ] ,
303+ } ,
300304 ] ) ;
301305
302306 // Check that handleHttpRequest was called once with the correct arguments
@@ -365,6 +369,7 @@ describe('dedup utility tests', () => {
365369 // Mock the handleHttpRequest function to return the same data every time it's called
366370 handleHttpRequest . mockImplementationOnce ( ( ) => ( {
367371 processedResponse : {
372+ status : 200 ,
368373 response : {
369374 users : Array . from ( { length : 50 } , ( _ , i ) =>
370375 removeUndefinedAndNullAndEmptyValues ( {
@@ -385,6 +390,7 @@ describe('dedup utility tests', () => {
385390
386391 handleHttpRequest . mockImplementationOnce ( ( ) => ( {
387392 processedResponse : {
393+ status : 200 ,
388394 response : {
389395 users : Array . from ( { length : 50 } , ( _ , i ) =>
390396 removeUndefinedAndNullAndEmptyValues ( {
@@ -405,6 +411,7 @@ describe('dedup utility tests', () => {
405411
406412 handleHttpRequest . mockImplementationOnce ( ( ) => ( {
407413 processedResponse : {
414+ status : 200 ,
408415 response : {
409416 users : Array . from ( { length : 10 } , ( _ , i ) =>
410417 removeUndefinedAndNullAndEmptyValues ( {
@@ -426,8 +433,10 @@ describe('dedup utility tests', () => {
426433 const chunkedUserData = await BrazeDedupUtility . doApiLookup ( identifierChunks , {
427434 destination,
428435 } ) ;
429- const result = _ . flatMap ( chunkedUserData ) ;
430- expect ( result ) . toHaveLength ( 110 ) ;
436+ // Each chunk now returns { users: [...], failedIdentifiers: [] }
437+ // So we need to extract users from each chunk and flatten
438+ const allUsers = chunkedUserData . flatMap ( ( chunk ) => chunk . users ) ;
439+ expect ( allUsers ) . toHaveLength ( 110 ) ;
431440 expect ( handleHttpRequest ) . toHaveBeenCalledTimes ( 3 ) ;
432441 } ) ;
433442
@@ -486,14 +495,20 @@ describe('dedup utility tests', () => {
486495
487496 expect ( handleHttpRequest ) . toHaveBeenCalledTimes ( 2 ) ;
488497 // Assert that the first chunk was successful and the second failed
489- // The failed chunked will be returned as undefined
498+ // The failed chunk will return empty users array with failedIdentifiers
490499 expect ( users ) . toEqual ( [
491- [
492- { external_id : 'user1' , email : 'user1@example.com' } ,
493- { alias_name : 'alias1' , alias_label : 'rudder_id' , email : 'alias1@example.com' } ,
494- { external_id : 'user2' , email : 'user2@example.com' } ,
495- ] ,
496- undefined ,
500+ {
501+ users : [
502+ { external_id : 'user1' , email : 'user1@example.com' } ,
503+ { alias_name : 'alias1' , alias_label : 'rudder_id' , email : 'alias1@example.com' } ,
504+ { external_id : 'user2' , email : 'user2@example.com' } ,
505+ ] ,
506+ failedIdentifiers : [ ] ,
507+ } ,
508+ {
509+ users : [ ] ,
510+ failedIdentifiers : [ 'user3' , 'alias2' ] ,
511+ } ,
497512 ] ) ;
498513 } ) ;
499514 } ) ;
@@ -515,11 +530,21 @@ describe('dedup utility tests', () => {
515530 [ { alias_name : 'alias1' , alias_label : 'rudder_id' } ] ,
516531 [ { alias_name : 'alias2' , alias_label : 'rudder_id' } ] ,
517532 ] ) ;
533+ // doApiLookup now returns { users: [...], failedIdentifiers: [...] } for each chunk
518534 const doApiLookupMock = jest . spyOn ( BrazeDedupUtility , 'doApiLookup' ) . mockResolvedValue ( [
519- [ { external_id : '123' , custom_attributes : { key1 : 'value1' } } ] ,
520- [ { external_id : '456' , custom_attributes : { key2 : 'value2' } } ] ,
521- undefined , // simulate failed api call
522- [ { alias_name : 'alias2' , custom_attributes : { key3 : 'value3' } } ] ,
535+ {
536+ users : [ { external_id : '123' , custom_attributes : { key1 : 'value1' } } ] ,
537+ failedIdentifiers : [ ] ,
538+ } ,
539+ {
540+ users : [ { external_id : '456' , custom_attributes : { key2 : 'value2' } } ] ,
541+ failedIdentifiers : [ ] ,
542+ } ,
543+ { users : [ ] , failedIdentifiers : [ 'alias1' ] } , // simulate failed api call
544+ {
545+ users : [ { alias_name : 'alias2' , custom_attributes : { key3 : 'value3' } } ] ,
546+ failedIdentifiers : [ ] ,
547+ } ,
523548 ] ) ;
524549
525550 // create input data for doLookup
@@ -532,12 +557,13 @@ describe('dedup utility tests', () => {
532557
533558 // call doLookup and verify the output
534559 const result = await BrazeDedupUtility . doLookup ( inputs ) ;
535- expect ( result ) . toEqual ( [
560+ // doLookup now returns { users: [...], failedIdentifiers: Set }
561+ expect ( result . users ) . toEqual ( [
536562 { external_id : '123' , custom_attributes : { key1 : 'value1' } } ,
537563 { external_id : '456' , custom_attributes : { key2 : 'value2' } } ,
538- undefined , // response of failed api call
539564 { alias_name : 'alias2' , custom_attributes : { key3 : 'value3' } } ,
540565 ] ) ;
566+ expect ( result . failedIdentifiers ) . toEqual ( new Set ( [ 'alias1' ] ) ) ;
541567
542568 // verify that the mocked functions were called with correct arguments
543569 expect ( prepareInputForDedupMock ) . toHaveBeenCalledWith ( inputs ) ;
0 commit comments