@@ -6,6 +6,7 @@ const expect = require('chai').expect;
66const testMethod = defineOperation ( kerberos . _testMethod , [
77 { name : 'string' , type : 'string' } ,
88 { name : 'shouldError' , type : 'boolean' , default : false } ,
9+ { name : 'optionalString' , type : 'string' , required : false } ,
910 { name : 'callback' , type : 'function' , required : false }
1011] ) ;
1112
@@ -14,8 +15,30 @@ describe('defineOperation', () => {
1415 expect ( ( ) => testMethod ( 42 ) ) . to . throw ( / I n v a l i d t y p e f o r p a r a m e t e r / ) ;
1516 } ) ;
1617
18+ it ( 'should support defaults' , function ( done ) {
19+ expect ( ( ) => testMethod ( 'testing' ) ) . to . not . throw ( ) ;
20+ testMethod ( 'testing' , true , err => {
21+ expect ( err ) . to . exist ;
22+ done ( ) ;
23+ } ) ;
24+ } ) ;
25+
1726 it ( 'should return a promise if no callback is provided' , function ( ) {
1827 const promise = testMethod ( 'llamas' , false ) ;
1928 expect ( promise ) . to . be . instanceOf ( Promise ) ;
2029 } ) ;
30+
31+ it ( 'should use a callback if provided' , function ( done ) {
32+ testMethod ( 'testing' , false , 'optional' , ( err , result ) => {
33+ expect ( err ) . to . not . exist ;
34+ expect ( result ) . to . equal ( 'optional' ) ;
35+
36+ testMethod ( 'testing' , true , 'optional' , ( err , result ) => {
37+ expect ( err ) . to . exist ;
38+ expect ( result ) . to . not . exist ;
39+
40+ done ( ) ;
41+ } ) ;
42+ } ) ;
43+ } ) ;
2144} ) ;
0 commit comments