@@ -1936,6 +1936,64 @@ describe('Database', () => {
1936
1936
expect ( catchedError ) . to . equal ( expectedError ) ;
1937
1937
} ) ;
1938
1938
} ) ;
1939
+
1940
+ describe ( 'commandHelp' , ( ) => {
1941
+ it ( 'calls serviceProvider.runCommand on the database with options' , async ( ) => {
1942
+ await database . commandHelp ( 'listDatabases' ) ;
1943
+
1944
+ expect ( serviceProvider . runCommand ) . to . have . been . calledWith (
1945
+ database . _name ,
1946
+ {
1947
+ listDatabases : 1 ,
1948
+ help : true
1949
+ }
1950
+ ) ;
1951
+ } ) ;
1952
+
1953
+ it ( 'returns whatever serviceProvider.runCommand().help returns' , async ( ) => {
1954
+ const expectedResult = { ok : 1 , help : 'help string' } ;
1955
+ serviceProvider . runCommand . resolves ( expectedResult ) ;
1956
+ const result = await database . commandHelp ( 'listDatabases' ) ;
1957
+ expect ( result ) . to . deep . equal ( 'help string' ) ;
1958
+ } ) ;
1959
+
1960
+ it ( 'throws if serviceProvider.runCommand rejects' , async ( ) => {
1961
+ const expectedError = new Error ( ) ;
1962
+ serviceProvider . runCommand . rejects ( expectedError ) ;
1963
+ const catchedError = await database . commandHelp ( 'listDatabases' )
1964
+ . catch ( e => e ) ;
1965
+ expect ( catchedError ) . to . equal ( expectedError ) ;
1966
+ } ) ;
1967
+ } ) ;
1968
+
1969
+ describe ( 'listCommands' , ( ) => {
1970
+ it ( 'calls serviceProvider.runCommand on the database' , async ( ) => {
1971
+ await database . listCommands ( ) ;
1972
+
1973
+ expect ( serviceProvider . runCommand ) . to . have . been . calledWith (
1974
+ database . _name ,
1975
+ {
1976
+ listCommands : 1
1977
+ }
1978
+ ) ;
1979
+ } ) ;
1980
+
1981
+ it ( 'returns ListCommandsResult' , async ( ) => {
1982
+ const expectedResult = { ok : 1 , commands : { c1 : { requiresAuth : false , slaveOk : true , adminOnly : false , help : 'help string' } } } ;
1983
+ serviceProvider . runCommand . resolves ( expectedResult ) ;
1984
+ const result = await database . listCommands ( ) ;
1985
+ expect ( result . value ) . to . deep . equal ( expectedResult . commands ) ;
1986
+ expect ( result . type ) . to . equal ( 'ListCommandsResult' ) ;
1987
+ } ) ;
1988
+
1989
+ it ( 'throws if serviceProvider.runCommand rejects' , async ( ) => {
1990
+ const expectedError = new Error ( ) ;
1991
+ serviceProvider . runCommand . rejects ( expectedError ) ;
1992
+ const catchedError = await database . listCommands ( )
1993
+ . catch ( e => e ) ;
1994
+ expect ( catchedError ) . to . equal ( expectedError ) ;
1995
+ } ) ;
1996
+ } ) ;
1939
1997
} ) ;
1940
1998
} ) ;
1941
1999
0 commit comments