@@ -1467,63 +1467,82 @@ describe('Collection', function () {
14671467 context (
14681468 'when the aggregation fails with error code `13388`' ,
14691469 function ( ) {
1470- beforeEach ( function ( ) {
1471- const tryNext = sinon . stub ( ) ;
1472- const mockError : any = new Error ( 'test error' ) ;
1473- mockError . code = 13388 ;
1474- tryNext . onCall ( 0 ) . rejects ( mockError ) ;
1475- serviceProvider . aggregate . returns ( { tryNext } as any ) ;
1476- } ) ;
1477-
1478- it ( 'runs the deprecated collStats command with the default scale' , async function ( ) {
1479- await collection . stats ( ) ;
1480-
1481- expect (
1482- serviceProvider . runCommandWithCheck
1483- ) . to . have . been . calledWith ( database . _name , {
1484- collStats : collection . _name ,
1485- scale : 1 ,
1486- } ) ;
1487- } ) ;
1488-
1489- it ( 'runs the deprecated collStats command with a custom scale' , async function ( ) {
1490- await collection . stats ( {
1491- scale : 1024 , // Scale to kilobytes.
1492- } ) ;
1493-
1494- expect (
1495- serviceProvider . runCommandWithCheck
1496- ) . to . have . been . calledWith ( database . _name , {
1497- collStats : collection . _name ,
1498- scale : 1024 ,
1499- } ) ;
1500- } ) ;
1501-
1502- it ( 'runs the deprecated collStats command with the legacy scale parameter' , async function ( ) {
1503- await collection . stats ( 2 ) ;
1504-
1505- expect (
1506- serviceProvider . runCommandWithCheck
1507- ) . to . have . been . calledWith ( database . _name , {
1508- collStats : collection . _name ,
1509- scale : 2 ,
1510- } ) ;
1511- } ) ;
1512-
1513- context ( 'when the fallback collStats command fails' , function ( ) {
1514- beforeEach ( function ( ) {
1515- serviceProvider . runCommandWithCheck . rejects (
1516- new Error ( 'not our error' )
1470+ for ( const mockError of [
1471+ {
1472+ ...new Error ( 'Code 13388' ) ,
1473+ code : 13388 ,
1474+ } ,
1475+ {
1476+ ...new Error ( 'Stale Config' ) ,
1477+ codeName : 'StaleConfig' ,
1478+ } ,
1479+ {
1480+ ...new Error ( 'Failed to Parse' ) ,
1481+ codeName : 'FailedToParse' ,
1482+ } ,
1483+ ] ) {
1484+ context ( `in case of ${ mockError . name } error` , function ( ) {
1485+ beforeEach ( function ( ) {
1486+ const tryNext = sinon . stub ( ) ;
1487+ tryNext . onCall ( 0 ) . rejects ( mockError ) ;
1488+ serviceProvider . aggregate . returns ( { tryNext } as any ) ;
1489+ } ) ;
1490+
1491+ it ( 'runs the deprecated collStats command with the default scale' , async function ( ) {
1492+ await collection . stats ( ) ;
1493+
1494+ expect (
1495+ serviceProvider . runCommandWithCheck
1496+ ) . to . have . been . calledWith ( database . _name , {
1497+ collStats : collection . _name ,
1498+ scale : 1 ,
1499+ } ) ;
1500+ } ) ;
1501+
1502+ it ( 'runs the deprecated collStats command with a custom scale' , async function ( ) {
1503+ await collection . stats ( {
1504+ scale : 1024 , // Scale to kilobytes.
1505+ } ) ;
1506+
1507+ expect (
1508+ serviceProvider . runCommandWithCheck
1509+ ) . to . have . been . calledWith ( database . _name , {
1510+ collStats : collection . _name ,
1511+ scale : 1024 ,
1512+ } ) ;
1513+ } ) ;
1514+
1515+ it ( 'runs the deprecated collStats command with the legacy scale parameter' , async function ( ) {
1516+ await collection . stats ( 2 ) ;
1517+
1518+ expect (
1519+ serviceProvider . runCommandWithCheck
1520+ ) . to . have . been . calledWith ( database . _name , {
1521+ collStats : collection . _name ,
1522+ scale : 2 ,
1523+ } ) ;
1524+ } ) ;
1525+
1526+ context (
1527+ 'when the fallback collStats command fails' ,
1528+ function ( ) {
1529+ beforeEach ( function ( ) {
1530+ serviceProvider . runCommandWithCheck . rejects (
1531+ new Error ( 'not our error' )
1532+ ) ;
1533+ } ) ;
1534+
1535+ it ( 'surfaces the original aggregation error' , async function ( ) {
1536+ const error = await collection . stats ( ) . catch ( ( e ) => e ) ;
1537+
1538+ expect ( serviceProvider . runCommandWithCheck ) . to . have . been
1539+ . called ;
1540+ expect ( error . message ) . to . equal ( mockError . message ) ;
1541+ } ) ;
1542+ }
15171543 ) ;
15181544 } ) ;
1519-
1520- it ( 'surfaces the original aggregation error' , async function ( ) {
1521- const error = await collection . stats ( ) . catch ( ( e ) => e ) ;
1522-
1523- expect ( serviceProvider . runCommandWithCheck ) . to . have . been . called ;
1524- expect ( error . message ) . to . equal ( 'test error' ) ;
1525- } ) ;
1526- } ) ;
1545+ }
15271546 }
15281547 ) ;
15291548 } ) ;
0 commit comments