11import assert from 'assert' ;
22import sinon from 'sinon' ;
3+ import { z } from 'zod' ;
34import auth from '../../../../Auth.js' ;
45import { cli } from '../../../../cli/cli.js' ;
56import { CommandInfo } from '../../../../cli/CommandInfo.js' ;
@@ -33,6 +34,7 @@ describe(commands.MULTITENANT_ADD, () => {
3334 let logger : Logger ;
3435 let loggerLogSpy : sinon . SinonSpy ;
3536 let commandInfo : CommandInfo ;
37+ let commandOptionsSchema : z . ZodTypeAny ;
3638
3739 before ( ( ) => {
3840 sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
@@ -41,6 +43,7 @@ describe(commands.MULTITENANT_ADD, () => {
4143 sinon . stub ( session , 'getId' ) . returns ( '' ) ;
4244 auth . connection . active = true ;
4345 commandInfo = cli . getCommandInfo ( command ) ;
46+ commandOptionsSchema = commandInfo . command . getSchemaToParse ( ) ! ;
4447 } ) ;
4548
4649 beforeEach ( ( ) => {
@@ -80,13 +83,13 @@ describe(commands.MULTITENANT_ADD, () => {
8083 } ) ;
8184
8285 it ( 'passes validation when only displayName is specified' , async ( ) => {
83- const actual = await command . validate ( { options : { displayName : 'Contoso organization' } } , commandInfo ) ;
84- assert . strictEqual ( actual , true ) ;
86+ const parseResult = commandOptionsSchema . safeParse ( { displayName : 'Contoso organization' } ) ;
87+ assert . strictEqual ( parseResult . success , true ) ;
8588 } ) ;
8689
8790 it ( 'passes validation when the displayName and description are specified' , async ( ) => {
88- const actual = await command . validate ( { options : { displayName : 'Contoso organization' , description : 'Contoso and partners' } } , commandInfo ) ;
89- assert . strictEqual ( actual , true ) ;
91+ const parseResult = commandOptionsSchema . safeParse ( { displayName : 'Contoso organization' , description : 'Contoso and partners' } ) ;
92+ assert . strictEqual ( parseResult . success , true ) ;
9093 } ) ;
9194
9295 it ( 'creates a multitenant organization with a displayName only' , async ( ) => {
@@ -98,7 +101,7 @@ describe(commands.MULTITENANT_ADD, () => {
98101 throw 'Invalid request' ;
99102 } ) ;
100103
101- await command . action ( logger , { options : { displayName : 'Contoso organization' , verbose : true } } ) ;
104+ await command . action ( logger , { options : commandOptionsSchema . parse ( { displayName : 'Contoso organization' , verbose : true } ) } ) ;
102105 assert ( loggerLogSpy . calledOnceWithExactly ( multitenantOrganizationShortReponse ) ) ;
103106 } ) ;
104107
@@ -111,7 +114,7 @@ describe(commands.MULTITENANT_ADD, () => {
111114 throw 'Invalid request' ;
112115 } ) ;
113116
114- await command . action ( logger , { options : { displayName : 'Contoso organization' , description : 'Contoso and partners' } } ) ;
117+ await command . action ( logger , { options : commandOptionsSchema . parse ( { displayName : 'Contoso organization' , description : 'Contoso and partners' } ) } ) ;
115118 assert ( loggerLogSpy . calledOnceWithExactly ( multitenantOrganizationReponse ) ) ;
116119 } ) ;
117120
@@ -127,7 +130,7 @@ describe(commands.MULTITENANT_ADD, () => {
127130 }
128131 } ) ;
129132
130- await assert . rejects ( command . action ( logger , { options : { } } as any ) , new CommandError ( 'Invalid request' ) ) ;
133+ await assert . rejects ( command . action ( logger , { options : commandOptionsSchema . parse ( { displayName : 'Contoso organization' } ) } ) , new CommandError ( 'Invalid request' ) ) ;
131134 } ) ;
132135
133136 it ( 'correctly handles API OData error when the multitenant organization already exist' , async ( ) => {
@@ -143,6 +146,6 @@ describe(commands.MULTITENANT_ADD, () => {
143146 }
144147 } ) ;
145148
146- await assert . rejects ( command . action ( logger , { options : { } } as any ) , new CommandError ( 'Method not supported for update operation.' ) ) ;
149+ await assert . rejects ( command . action ( logger , { options : commandOptionsSchema . parse ( { displayName : 'Contoso organization' } ) } ) , new CommandError ( 'Method not supported for update operation.' ) ) ;
147150 } ) ;
148151} ) ;
0 commit comments