@@ -366,15 +366,12 @@ describe('AtlasUserData', function () {
366366 | 'FavoriteQueries'
367367 | 'SavedPipelines' = 'FavoriteQueries'
368368 ) => {
369- return new AtlasUserData (
370- getTestSchema ( validatorOpts ) ,
371- type ,
369+ return new AtlasUserData ( getTestSchema ( validatorOpts ) , type , {
372370 orgId,
373371 projectId,
374- getResourceUrlStub ,
375- authenticatedFetchStub ,
376- { }
377- ) ;
372+ getResourceUrl : getResourceUrlStub ,
373+ authenticatedFetch : authenticatedFetchStub ,
374+ } ) ;
378375 } ;
379376
380377 const mockResponse = ( data : unknown , ok = true , status = 200 ) => {
@@ -415,8 +412,10 @@ describe('AtlasUserData', function () {
415412 expect ( new Date ( body . createdAt as string ) ) . to . be . instanceOf ( Date ) ;
416413 } ) ;
417414
418- it ( 'returns false when response is not ok' , async function ( ) {
419- authenticatedFetchStub . resolves ( mockResponse ( { } , false , 500 ) ) ;
415+ it ( 'returns false when authenticatedFetch throws an error' , async function ( ) {
416+ authenticatedFetchStub . rejects (
417+ new Error ( 'HTTP 500: Internal Server Error' )
418+ ) ;
420419 getResourceUrlStub . resolves (
421420 'cluster-connection.cloud.mongodb.com/FavoriteQueries/test-org/test-proj'
422421 ) ;
@@ -449,17 +448,13 @@ describe('AtlasUserData', function () {
449448 'cluster-connection.cloud.mongodb.com/FavoriteQueries/test-org/test-proj'
450449 ) ;
451450
452- const userData = new AtlasUserData (
453- getTestSchema ( ) ,
454- 'FavoriteQueries' ,
455- 'test-org' ,
456- 'test-proj' ,
457- getResourceUrlStub ,
458- authenticatedFetchStub ,
459- {
460- serialize : ( data ) => `custom:${ JSON . stringify ( data ) } ` ,
461- }
462- ) ;
451+ const userData = new AtlasUserData ( getTestSchema ( ) , 'FavoriteQueries' , {
452+ orgId : 'test-org' ,
453+ projectId : 'test-proj' ,
454+ getResourceUrl : getResourceUrlStub ,
455+ authenticatedFetch : authenticatedFetchStub ,
456+ serialize : ( data ) => `custom:${ JSON . stringify ( data ) } ` ,
457+ } ) ;
463458
464459 await userData . write ( 'test-id' , { name : 'Custom' } ) ;
465460
@@ -489,8 +484,8 @@ describe('AtlasUserData', function () {
489484 expect ( options . method ) . to . equal ( 'DELETE' ) ;
490485 } ) ;
491486
492- it ( 'returns false when response is not ok ' , async function ( ) {
493- authenticatedFetchStub . resolves ( mockResponse ( { } , false , 404 ) ) ;
487+ it ( 'returns false when authenticatedFetch throws an error ' , async function ( ) {
488+ authenticatedFetchStub . rejects ( new Error ( 'HTTP 404: Not Found' ) ) ;
494489 getResourceUrlStub . resolves (
495490 'cluster-connection.cloud.mongodb.com/FavoriteQueries/test-org/test-proj'
496491 ) ;
@@ -583,8 +578,10 @@ describe('AtlasUserData', function () {
583578 expect ( result . errors [ 0 ] . message ) . to . equal ( 'Unknown error' ) ;
584579 } ) ;
585580
586- it ( 'handles non-ok response gracefully' , async function ( ) {
587- authenticatedFetchStub . resolves ( mockResponse ( { } , false , 500 ) ) ;
581+ it ( 'handles authenticatedFetch errors gracefully' , async function ( ) {
582+ authenticatedFetchStub . rejects (
583+ new Error ( 'HTTP 500: Internal Server Error' )
584+ ) ;
588585 getResourceUrlStub . resolves (
589586 'cluster-connection.cloud.mongodb.com/FavoriteQueries/test-org/test-proj'
590587 ) ;
@@ -594,7 +591,9 @@ describe('AtlasUserData', function () {
594591
595592 expect ( result . data ) . to . have . lengthOf ( 0 ) ;
596593 expect ( result . errors ) . to . have . lengthOf ( 1 ) ;
597- expect ( result . errors [ 0 ] . message ) . to . contain ( 'Failed to get data: 500' ) ;
594+ expect ( result . errors [ 0 ] . message ) . to . contain (
595+ 'HTTP 500: Internal Server Error'
596+ ) ;
598597 } ) ;
599598
600599 it ( 'uses custom deserializer when provided' , async function ( ) {
@@ -604,22 +603,18 @@ describe('AtlasUserData', function () {
604603 'cluster-connection.cloud.mongodb.com/FavoriteQueries/test-org/test-proj'
605604 ) ;
606605
607- const userData = new AtlasUserData (
608- getTestSchema ( ) ,
609- 'FavoriteQueries' ,
610- 'test-org' ,
611- 'test-proj' ,
612- getResourceUrlStub ,
613- authenticatedFetchStub ,
614- {
615- deserialize : ( data ) => {
616- if ( data . startsWith ( 'custom:' ) ) {
617- return JSON . parse ( data . slice ( 7 ) ) ;
618- }
619- return JSON . parse ( data ) ;
620- } ,
621- }
622- ) ;
606+ const userData = new AtlasUserData ( getTestSchema ( ) , 'FavoriteQueries' , {
607+ orgId : 'test-org' ,
608+ projectId : 'test-proj' ,
609+ getResourceUrl : getResourceUrlStub ,
610+ authenticatedFetch : authenticatedFetchStub ,
611+ deserialize : ( data ) => {
612+ if ( data . startsWith ( 'custom:' ) ) {
613+ return JSON . parse ( data . slice ( 7 ) ) ;
614+ }
615+ return JSON . parse ( data ) ;
616+ } ,
617+ } ) ;
623618
624619 const result = await userData . readAll ( ) ;
625620
@@ -705,7 +700,7 @@ describe('AtlasUserData', function () {
705700 expect ( putOptions . headers [ 'Content-Type' ] ) . to . equal ( 'application/json' ) ;
706701 } ) ;
707702
708- it ( 'returns false when response is not ok ' , async function ( ) {
703+ it ( 'returns false when authenticatedFetch throws an error ' , async function ( ) {
709704 const getResponse = {
710705 data : JSON . stringify ( { name : 'Original Name' , hasDarkMode : true } ) ,
711706 } ;
@@ -714,7 +709,7 @@ describe('AtlasUserData', function () {
714709 . onFirstCall ( )
715710 . resolves ( mockResponse ( getResponse ) )
716711 . onSecondCall ( )
717- . resolves ( mockResponse ( { } , false , 400 ) ) ;
712+ . rejects ( new Error ( 'HTTP 400: Bad Request' ) ) ;
718713
719714 getResourceUrlStub
720715 . onFirstCall ( )
@@ -756,17 +751,13 @@ describe('AtlasUserData', function () {
756751 'cluster-connection.cloud.mongodb.com/FavoriteQueries/test-org/test-proj/test-id'
757752 ) ;
758753
759- const userData = new AtlasUserData (
760- getTestSchema ( ) ,
761- 'FavoriteQueries' ,
762- 'test-org' ,
763- 'test-proj' ,
764- getResourceUrlStub ,
765- authenticatedFetchStub ,
766- {
767- serialize : ( data ) => `custom:${ JSON . stringify ( data ) } ` ,
768- }
769- ) ;
754+ const userData = new AtlasUserData ( getTestSchema ( ) , 'FavoriteQueries' , {
755+ orgId : 'test-org' ,
756+ projectId : 'test-proj' ,
757+ getResourceUrl : getResourceUrlStub ,
758+ authenticatedFetch : authenticatedFetchStub ,
759+ serialize : ( data ) => `custom:${ JSON . stringify ( data ) } ` ,
760+ } ) ;
770761
771762 await userData . updateAttributes ( 'test-id' , { name : 'Updated' } ) ;
772763
0 commit comments