1+ import type { ShardedDataDistribution } from './helpers' ;
12import {
23 assertArgsDefinedType ,
34 coerceToJSNumber ,
@@ -135,6 +136,21 @@ describe('getPrintableShardStatus', function () {
135136 let serviceProvider : ServiceProvider ;
136137 let inBalancerRound = false ;
137138
139+ const mockedShardedDataDistribution : ShardedDataDistribution = [
140+ {
141+ ns : 'test.ns' ,
142+ shards : [
143+ {
144+ shardName : 'test' ,
145+ numOrphanedDocs : 1 ,
146+ numOwnedDocuments : 5 ,
147+ orphanedSizeBytes : 20 ,
148+ ownedSizeBytes : 80 ,
149+ } ,
150+ ] ,
151+ } ,
152+ ] ;
153+
138154 beforeEach ( async function ( ) {
139155 serviceProvider = await CliServiceProvider . connect (
140156 await testServer . connectionString ( ) ,
@@ -152,9 +168,20 @@ describe('getPrintableShardStatus', function () {
152168 configDatabase = new Database ( mongo , 'config_test' ) ;
153169 expect ( configDatabase . getName ( ) ) . to . equal ( 'config_test' ) ;
154170
171+ const mockedAdminDb = {
172+ aggregate : stub ( )
173+ . withArgs ( [ { $shardedDataDistribution : { } } ] )
174+ . resolves ( {
175+ toArray : stub ( ) . resolves ( mockedShardedDataDistribution ) ,
176+ } ) ,
177+ } ;
178+ const getSiblingDB = stub ( ) ;
179+ getSiblingDB . withArgs ( 'admin' ) . returns ( mockedAdminDb ) ;
180+ getSiblingDB . withArgs ( 'config' ) . returns ( configDatabase ) ;
181+
155182 db = {
156183 _maybeCachedHello : stub ( ) . returns ( { msg : 'isdbgrid' } ) ,
157- getSiblingDB : stub ( ) . withArgs ( 'config' ) . returns ( configDatabase ) ,
184+ getSiblingDB,
158185 } as unknown as Database ;
159186
160187 const origRunCommandWithCheck = serviceProvider . runCommandWithCheck ;
@@ -209,6 +236,10 @@ describe('getPrintableShardStatus', function () {
209236 ) ;
210237 expect ( status . databases ) . to . have . lengthOf ( 1 ) ;
211238 expect ( status . databases [ 0 ] . database . _id ) . to . equal ( 'config' ) ;
239+
240+ expect ( status . shardedDataDistribution ) . to . equal (
241+ mockedShardedDataDistribution
242+ ) ;
212243 } ) ;
213244
214245 describe ( 'hides all internal deprecated fields in shardingVersion' , function ( ) {
0 commit comments