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'
6- import { setEnvVariables } from '../../../util/test-utils'
5+ import { Environment , EnvironmentDetail } from '../../../../src/types/environment.js'
6+ import { camelCaseToTitleCase , renderKeyValueTable } from '../../../../src/util/internal'
7+ import { ScConnection } from '../../../../src/util/sc-connection'
8+ import { anEnv , setEnvVariables } from '../../../util/test-utils'
79
810describe ( 'platform:env:create' , ( ) => {
911 setEnvVariables ( )
@@ -19,15 +21,63 @@ describe('platform:env:create', () => {
1921 } )
2022
2123 it ( 'runs platform:env:create' , async ( ) => {
22- const { stdout } = await runCommand ( 'platform:env:create' )
24+ const { stdout} = await runCommand ( 'platform:env:create' )
2325 expect ( stdout ) . to . contain ( '' )
2426 } )
2527
26- it ( `runs platform:env:create --name=${ envName } ` , async ( ) => {
27- const createOutputMsg = 'Environment created successfully.'
28- scConnStub . returns ( createOutputMsg )
28+ it ( `runs platform:env:create --name=${ envName } ` , async ( ) => {
29+ // Arrange
30+ const expectBody = {
31+ isDefault : false ,
32+ isProduction : false ,
33+ name : envName ,
34+ }
35+ const expectEnv : Environment = anEnv ( envName , false , false )
36+ const expectResponse : EnvironmentDetail = {
37+ data : expectEnv ,
38+ }
39+ scConnStub . returns ( expectResponse )
2940
30- const { stdout } = await runCommand ( `platform:env:create --name=${ envName } ` )
31- expect ( stdout ) . to . contain ( createOutputMsg )
41+ const tableRows = [
42+ [ 'Key' , 'Value' ] ,
43+ ...Object . entries ( expectResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
44+ ]
45+
46+ // Act
47+ const { stdout} = await runCommand ( `platform:env:create --name=${ envName } ` )
48+
49+ // Assert
50+ expect ( scConnStub . getCall ( 0 ) . calledWith ( '/platform/environments' , expectBody ) ) . to . be . true
51+ expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
52+ } )
53+
54+ it ( `runs platform:env:create --name=${ envName } --description="This is an environment description."` , async ( ) => {
55+ // Arrange
56+ const expectBody = {
57+ description : 'This is an environment description.' ,
58+ isDefault : false ,
59+ isProduction : false ,
60+ name : envName ,
61+ }
62+ const expectEnv : Environment = anEnv ( envName , false , false )
63+ const expectResponse : EnvironmentDetail = {
64+ data : expectEnv ,
65+ }
66+ expectResponse . data . description = expectBody . description
67+ scConnStub . returns ( expectResponse )
68+
69+ const tableRows = [
70+ [ 'Key' , 'Value' ] ,
71+ ...Object . entries ( expectResponse . data ) . map ( ( [ key , value ] ) => [ camelCaseToTitleCase ( key ) , value ] ) ,
72+ ]
73+
74+ // Act
75+ const { stdout} = await runCommand (
76+ `platform:env:create --name=${ envName } --description="This is an environment description."` ,
77+ )
78+
79+ // Assert
80+ expect ( scConnStub . getCall ( 0 ) . calledWith ( '/platform/environments' , expectBody ) ) . to . be . true
81+ expect ( stdout ) . to . contain ( renderKeyValueTable ( tableRows ) )
3282 } )
3383} )
0 commit comments