1- import { runCommand } from '@oclif/test'
2- import { expect } from 'chai'
1+ import { runCommand } from '@oclif/test'
2+ import { expect } from 'chai'
33import * as sinon from 'sinon'
44
5- import { ScConnection } from '../../../../src/util/sc-connection.js'
6- import { anEnv , setEnvVariables } from '../../../util/test-utils'
5+ import { EventBrokerCreateApiResponse , EventBrokerCreateDetail } from '../../../../src/types/broker.js'
6+ import { camelCaseToTitleCase , renderKeyValueTable } from '../../../../src/util/internal.js'
7+ import { ScConnection } from '../../../../src/util/sc-connection.js'
8+ import { aBroker , anEnv , setEnvVariables } from '../../../util/test-utils'
79
810describe ( 'missionctrl:broker:create' , ( ) => {
911 setEnvVariables ( )
@@ -25,39 +27,121 @@ describe('missionctrl:broker:create', () => {
2527 } )
2628
2729 it ( 'runs missionctrl:broker:create cmd' , async ( ) => {
28- const { stdout } = await runCommand ( 'missionctrl:broker:create' )
30+ const { stdout} = await runCommand ( 'missionctrl:broker:create' )
2931 expect ( stdout ) . to . contain ( '' )
3032 } )
3133
3234 it ( `runs missionctrl:broker:create -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } ` , async ( ) => {
33- const createOutputMsg = 'Event broker service created successfully.'
34- scConnPostStub . returns ( createOutputMsg )
35+ // Arrange
36+ const expectBody = {
37+ datacenterId : brokerDC ,
38+ locked : false ,
39+ name : brokerName ,
40+ redundancyGroupSslEnabled : false ,
41+ serviceClassId : brokerSvcClassId ,
42+ }
43+ const expectBroker : EventBrokerCreateDetail = aBroker ( brokerName , brokerDC )
44+ const expectResponse : EventBrokerCreateApiResponse = {
45+ data : expectBroker ,
46+ meta : { } ,
47+ }
48+
49+ scConnPostStub . returns ( expectResponse )
50+
51+ const tableRows = [
52+ [ 'Key' , 'Value' ] ,
53+ ...Object . entries ( expectResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
54+ ]
3555
36- const { stdout } = await runCommand ( `missionctrl:broker:create -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } ` )
37- expect ( stdout ) . to . contain ( createOutputMsg )
56+ // Act
57+ const { stdout} = await runCommand (
58+ `missionctrl:broker:create -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } ` ,
59+ )
60+
61+ // Assert
62+ expect ( scConnPostStub . getCall ( 0 ) . calledWith ( '/missionControl/eventBrokerServices' , expectBody ) ) . to . be . true
63+ expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
64+ } )
65+
66+ it ( `runs missionctrl:broker:create -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } -l -s 10 -m MyTestMsgVpn -r -v 10.0.0.1` , async ( ) => {
67+ // Arrange
68+ const expectBody = {
69+ datacenterId : brokerDC ,
70+ eventBrokerVersion : '10.0.0.1' ,
71+ locked : true ,
72+ maxSpoolUsage : '10' ,
73+ msgVpnName : 'MyTestMsgVpn' ,
74+ name : brokerName ,
75+ redundancyGroupSslEnabled : true ,
76+ serviceClassId : brokerSvcClassId ,
77+ }
78+ const expectBroker : EventBrokerCreateDetail = aBroker ( brokerName , brokerDC )
79+ const expectResponse : EventBrokerCreateApiResponse = {
80+ data : expectBroker ,
81+ meta : { } ,
82+ }
83+
84+ scConnPostStub . returns ( expectResponse )
85+
86+ const tableRows = [
87+ [ 'Key' , 'Value' ] ,
88+ ...Object . entries ( expectResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
89+ ]
90+
91+ // Act
92+ const { stdout} = await runCommand (
93+ `missionctrl:broker:create -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } -l -s 10 -m MyTestMsgVpn -r -v 10.0.0.1` ,
94+ )
95+
96+ // Assert
97+ expect ( scConnPostStub . getCall ( 0 ) . calledWith ( '/missionControl/eventBrokerServices' , expectBody ) ) . to . be . true
98+ expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
3899 } )
39100
40101 it ( `runs missionctrl:broker:create -e ${ envName } -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } ` , async ( ) => {
41102 // Arrange
42- const envName = 'Default'
43103 const envs = {
44- data : [ anEnv ( envName , true , false ) ] ,
104+ data : [ anEnv ( envName , false , false ) ] ,
45105 meta : {
46106 pagination : {
47107 count : 1 ,
48108 nextPage : null ,
49109 pageNumber : 1 ,
50110 pageSize : 10 ,
51- totalPages : 1
52- }
53- }
111+ totalPages : 1 ,
112+ } ,
113+ } ,
54114 }
115+ const expectBody = {
116+ datacenterId : brokerDC ,
117+ environmentId : envs . data [ 0 ] . id ,
118+ locked : false ,
119+ name : brokerName ,
120+ redundancyGroupSslEnabled : false ,
121+ serviceClassId : brokerSvcClassId ,
122+ }
123+ const expectBroker : EventBrokerCreateDetail = aBroker ( brokerName , brokerDC )
124+ const expectResponse : EventBrokerCreateApiResponse = {
125+ data : expectBroker ,
126+ meta : { } ,
127+ }
128+
55129 scConnGetStub . returns ( Promise . resolve ( envs ) )
130+ scConnPostStub . returns ( expectResponse )
131+
132+ const tableRows = [
133+ [ 'Key' , 'Value' ] ,
134+ ...Object . entries ( expectResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
135+ ]
56136
57- const createOutputMsg = 'Event broker service created successfully.'
58- scConnPostStub . returns ( createOutputMsg )
137+ // Act
138+ const { stdout} = await runCommand (
139+ `missionctrl:broker:create -e ${ envName } -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } ` ,
140+ )
59141
60- const { stdout } = await runCommand ( `missionctrl:broker:create -e ${ envName } -n ${ brokerName } -d ${ brokerDC } -c ${ brokerSvcClassId } ` )
61- expect ( stdout ) . to . contain ( createOutputMsg )
142+ // Assert
143+ expect ( scConnGetStub . getCall ( 0 ) . args [ 0 ] ) . to . contain ( `?name=${ envName } ` )
144+ expect ( scConnPostStub . getCall ( 0 ) . calledWith ( '/missionControl/eventBrokerServices' , expectBody ) ) . to . be . true
145+ expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
62146 } )
63147} )
0 commit comments