@@ -3,13 +3,14 @@ import {expect} from 'chai'
33import * as sinon from 'sinon'
44
55import { EventBrokerListApiResponse , EventBrokerOperationApiResponse } from '../../../../src/types/broker.js'
6- import { camelCaseToTitleCase , renderKeyValueTable } from '../../../../src/util/internal.js'
6+ import { printObjectAsKeyValueTable } from '../../../../src/util/internal.js'
77import { ScConnection } from '../../../../src/util/sc-connection.js'
88import { aBroker , createTestOperationResponse , setEnvVariables } from '../../../util/test-utils.js'
99
1010describe ( 'missionctrl:broker:update' , ( ) => {
1111 setEnvVariables ( )
12- const brokerName : string = 'Default'
12+ const brokerName : string = 'MyTestBrokerName'
13+ const newBrokerName : string = 'MyNewTestBrokerName'
1314 const brokerId : string = 'MyTestBrokerId'
1415 let scGetConnStub : sinon . SinonStub
1516 let scPatchConnStub : sinon . SinonStub
@@ -42,24 +43,22 @@ describe('missionctrl:broker:update', () => {
4243 )
4344 scPatchConnStub . returns ( Promise . resolve ( updatedBrokerOpResponse ) )
4445
45- const tableRows = [
46- [ 'Key' , 'Value' ] ,
47- ...Object . entries ( updatedBrokerOpResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
48- ]
49-
5046 // Act
5147 const { stdout} = await runCommand ( `missionctrl:broker:update -b ${ brokerId } -l true` )
5248
5349 // Assert
5450 expect ( scPatchConnStub . getCall ( 0 ) . calledWith ( `/missionControl/eventBrokerServices/${ brokerId } ` , expectBody ) ) . to . be
5551 . true
56- expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
52+ expect ( stdout ) . to . contain (
53+ printObjectAsKeyValueTable ( updatedBrokerOpResponse . data as unknown as Record < string , unknown > ) ,
54+ )
5755 } )
5856
59- it ( `runs missionctrl:broker:update -n ${ brokerName } -l true` , async ( ) => {
57+ it ( `runs missionctrl:broker:update -n ${ brokerName } -l true --new-name ${ newBrokerName } ` , async ( ) => {
6058 // Arrange
6159 const expectBody = {
6260 locked : true ,
61+ name : newBrokerName ,
6362 }
6463 const expectBrokerResponse : EventBrokerListApiResponse = {
6564 data : [ aBroker ( brokerId , brokerName ) ] ,
@@ -73,18 +72,15 @@ describe('missionctrl:broker:update', () => {
7372 scGetConnStub . returns ( Promise . resolve ( expectBrokerResponse ) )
7473 scPatchConnStub . returns ( Promise . resolve ( updatedBrokerOpResponse ) )
7574
76- const tableRows = [
77- [ 'Key' , 'Value' ] ,
78- ...Object . entries ( updatedBrokerOpResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
79- ]
80-
8175 // Act
82- const { stdout} = await runCommand ( `missionctrl:broker:update -n ${ brokerName } -l true` )
76+ const { stdout} = await runCommand ( `missionctrl:broker:update -n ${ brokerName } -l true --new-name ${ newBrokerName } ` )
8377
8478 // Assert
8579 expect ( scGetConnStub . getCall ( 0 ) . args [ 0 ] ) . to . contain ( `?customAttributes=name=="${ brokerName } "` )
8680 expect ( scPatchConnStub . getCall ( 0 ) . calledWith ( `/missionControl/eventBrokerServices/${ brokerId } ` , expectBody ) ) . to . be
8781 . true
88- expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
82+ expect ( stdout ) . to . contain (
83+ printObjectAsKeyValueTable ( updatedBrokerOpResponse . data as unknown as Record < string , unknown > ) ,
84+ )
8985 } )
9086} )
0 commit comments