Skip to content

Commit d665597

Browse files
Update description flag in create env command
1 parent 24a38a8 commit d665597

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

src/commands/platform/env/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreat
1212
Token Permissions: [ environments:edit ]`
1313
static override examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvironment --desc="My environment description" --isDefault --isProduction']
1414
static override flags = {
15-
desc: Flags.string({
15+
description: Flags.string({
1616
char: 'd',
1717
description: 'Description of the environment to create.'
1818
}),
@@ -36,7 +36,7 @@ export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreat
3636
const { flags } = await this.parse(PlatformEnvCreate)
3737

3838
const name = flags.name ?? ''
39-
const desc = flags.desc ?? ''
39+
const desc = flags.description ?? ''
4040
const isDefault = flags.isDefault ?? false
4141
const isProduction = flags.isProduction ?? false
4242

@@ -46,7 +46,7 @@ export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreat
4646
const apiUrl: string = `/platform/environments`
4747
// API body
4848
const body = {
49-
description: desc,
49+
...(desc && { description: desc }),
5050
isDefault,
5151
isProduction,
5252
name,
Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { runCommand } from '@oclif/test'
2-
import { expect } from 'chai'
1+
import {runCommand} from '@oclif/test'
2+
import {expect} from 'chai'
33
import * 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

810
describe('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

Comments
 (0)