Skip to content

Commit a17bf2d

Browse files
Lint fixes for type safety on unit tests.
1 parent d6eae86 commit a17bf2d

File tree

10 files changed

+81
-87
lines changed

10 files changed

+81
-87
lines changed

src/commands/platform/env/update.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export default class PlatformEnvUpdate extends Command {
1414
Token Permissions: [ environments:edit ]
1515
`
1616
static override examples = [
17-
'<%= config.bin %> <%= command.id %> --name=MyEnvName --new-name=MyNewEnvName --desc=\"My description to update" --isDefault',
18-
'<%= config.bin %> <%= command.id %> --env-id=MyEnvId --new-name=MyNewEnvName --desc=\"My description to update" --isDefault'
17+
'<%= config.bin %> <%= command.id %> --name=MyEnvName --new-name=MyNewEnvName --desc="My description to update" --isDefault',
18+
'<%= config.bin %> <%= command.id %> --env-id=MyEnvId --new-name=MyNewEnvName --desc="My description to update" --isDefault'
1919
]
2020
static override flags = {
2121
desc: Flags.string({ char: 'd', description: 'Description of the environment to update.' }),
2222
'env-id': Flags.string({ char: 'e', description: 'Id of the environment.', exactlyOne: ['env-id', 'name'] }),
23-
isDefault: Flags.boolean({ description: 'Indicates this is the organizations default environment. The default value is false.' }),
23+
isDefault: Flags.boolean({ description: `Indicates this is the organization's default environment. The default value is false.` }),
2424
name: Flags.string({ char: 'n', description: 'Current name of the environment.', exactlyOne: ['env-id', 'name'] }),
2525
'new-name': Flags.string({ description: 'New name of the environment.' }),
2626
}
@@ -34,13 +34,10 @@ export default class PlatformEnvUpdate extends Command {
3434
const newName = flags['new-name'] ?? ''
3535

3636
// API body
37-
let body: { [key: string]: any } = {}
38-
body['isDefault'] = flags.isDefault ?? false
39-
if (desc) {
40-
body['description'] = desc
41-
}
42-
if (newName) {
43-
body['name'] = newName
37+
const body = {
38+
...(flags.isDefault && { isDefault: flags.isDefault }),
39+
...(desc && { description: desc}),
40+
...(newName && { name: newName}),
4441
}
4542

4643
const conn = new ScConnection()

test/commands/missionctrl/broker/create.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import * as sinon from 'sinon'
44

55
import { ScConnection } from '../../../../src/util/sc-connection.js'
66

7-
describe('missionctrl:broker:create', () => {
8-
let scConnPostStub: any
9-
let scConnGetStub: any
10-
let envName: string = 'MyTestEnvironment'
11-
let brokerName: string = 'MyEventBrokerName'
12-
let brokerDC: string = 'eks-ca-central-1a'
13-
let brokerSvcClassId: string = 'DEVELOPER'
14-
15-
function anEnv(name: string, isDefault: boolean, isProd: boolean) {
7+
function anEnv(name: string, isDefault: boolean, isProd: boolean) {
168
return {
179
bgColor: '#DA162D',
1810
createdBy: 'someuser',
@@ -29,10 +21,18 @@ describe('missionctrl:broker:create', () => {
2921
}
3022
}
3123

24+
describe('missionctrl:broker:create', () => {
25+
let scConnPostStub: sinon.SinonStub
26+
let scConnGetStub: sinon.SinonStub
27+
const envName: string = 'MyTestEnvironment'
28+
const brokerName: string = 'MyEventBrokerName'
29+
const brokerDC: string = 'eks-ca-central-1a'
30+
const brokerSvcClassId: string = 'DEVELOPER'
31+
3232
beforeEach(() => {
33-
scConnPostStub = sinon.stub(ScConnection.prototype, <any>'post')
34-
scConnGetStub = sinon.stub(ScConnection.prototype, <any>'get')
35-
});
33+
scConnPostStub = sinon.stub(ScConnection.prototype, 'post')
34+
scConnGetStub = sinon.stub(ScConnection.prototype, 'get')
35+
})
3636

3737
afterEach(() => {
3838
scConnPostStub.restore()
@@ -45,7 +45,7 @@ describe('missionctrl:broker:create', () => {
4545
})
4646

4747
it(`runs missionctrl:broker:create -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`, async () => {
48-
let createOutputMsg = 'Event broker service created successfully.'
48+
const createOutputMsg = 'Event broker service created successfully.'
4949
scConnPostStub.returns(createOutputMsg)
5050

5151
const { stdout } = await runCommand(`missionctrl:broker:create -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`)
@@ -68,8 +68,8 @@ describe('missionctrl:broker:create', () => {
6868
}
6969
}
7070
scConnGetStub.returns(Promise.resolve(envs))
71-
72-
let createOutputMsg = 'Event broker service created successfully.'
71+
72+
const createOutputMsg = 'Event broker service created successfully.'
7373
scConnPostStub.returns(createOutputMsg)
7474

7575
const { stdout } = await runCommand(`missionctrl:broker:create -e ${envName} -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`)

test/commands/missionctrl/broker/delete.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import * as sinon from 'sinon'
55
import { ScConnection } from '../../../../src/util/sc-connection.js'
66

77
describe('missionctrl:broker:delete', () => {
8-
let scConnDeleteStub: any
9-
let scConnGetStub: any
10-
let brokerId: string = 'MyTestBrokerId'
11-
//let brokerName: string = 'MyTestBrokerName'
8+
let scConnDeleteStub: sinon.SinonStub
9+
let scConnGetStub: sinon.SinonStub
10+
const brokerId: string = 'MyTestBrokerId'
11+
// let brokerName: string = 'MyTestBrokerName'
1212

1313
beforeEach(() => {
14-
scConnDeleteStub = sinon.stub(ScConnection.prototype, <any>'delete');
15-
scConnGetStub = sinon.stub(ScConnection.prototype, <any>'get');
16-
});
14+
scConnDeleteStub = sinon.stub(ScConnection.prototype, 'delete')
15+
scConnGetStub = sinon.stub(ScConnection.prototype, 'get')
16+
})
1717

1818
afterEach(() => {
19-
scConnDeleteStub.restore();
20-
scConnGetStub.restore();
19+
scConnDeleteStub.restore()
20+
scConnGetStub.restore()
2121
})
2222

2323
it('runs missionctrl:broker:delete cmd', async () => {
@@ -26,7 +26,7 @@ describe('missionctrl:broker:delete', () => {
2626
})
2727

2828
it(`runs missionctrl:broker:delete -b ${brokerId}`, async () => {
29-
let deleteSuccessMsg = `Event broker service with id '${brokerId}' has been deleted successfully.`
29+
const deleteSuccessMsg = `Event broker service with id '${brokerId}' has been deleted successfully.`
3030
scConnDeleteStub.returns(deleteSuccessMsg)
3131

3232
const { stdout } = await runCommand(`missionctrl:broker:delete -b ${brokerId}`)

test/commands/missionctrl/broker/display.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ function anBroker(brokerName: string, brokerId: string) {
2121
}
2222

2323
describe('missionctrl:broker:display', () => {
24-
let brokerName: string = 'Default'
25-
let brokerId: string = 'MyTestBrokerId'
26-
let scConnStub: any
24+
const brokerName: string = 'Default'
25+
const brokerId: string = 'MyTestBrokerId'
26+
let scConnStub: sinon.SinonStub
2727

2828
beforeEach(() => {
29-
scConnStub = sinon.stub(ScConnection.prototype, <any>'get');
30-
});
29+
scConnStub = sinon.stub(ScConnection.prototype, 'get')
30+
})
3131

3232
afterEach(() => {
33-
scConnStub.restore();
33+
scConnStub.restore()
3434
})
3535

3636
it('runs missionctrl:broker:display cmd', async () => {
@@ -63,8 +63,7 @@ describe('missionctrl:broker:display', () => {
6363
},
6464
}
6565

66-
67-
const { stdout } = await runCommand('missionctrl:broker:display -b ${brokerId}')
66+
const { stdout } = await runCommand(`missionctrl:broker:display -b ${brokerId}`)
6867
expect(stdout).to.contain(table(tableRows, config))
6968
})
7069
})

test/commands/missionctrl/broker/list.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function anBroker(brokerName: string, brokerId: string) {
2020
}
2121

2222
describe('missionctrl:broker:list', () => {
23-
let scConnStub: any
23+
let scConnStub: sinon.SinonStub
2424

2525
beforeEach(() => {
26-
scConnStub = sinon.stub(ScConnection.prototype, <any>'get');
27-
});
26+
scConnStub = sinon.stub(ScConnection.prototype, 'get')
27+
})
2828

2929
afterEach(() => {
30-
scConnStub.restore();
30+
scConnStub.restore()
3131
})
3232

3333
it('runs missionctrl:broker:list cmd', async () => {

test/commands/platform/env/create.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import * as sinon from 'sinon'
55
import { ScConnection } from '../../../../src/util/sc-connection.js'
66

77
describe('platform:env:create', () => {
8-
let scConnStub: any
9-
let envName: string = 'MyTestEnvironment'
8+
let scConnStub: sinon.SinonStub
9+
const envName: string = 'MyTestEnvironment'
1010

1111
beforeEach(() => {
12-
scConnStub = sinon.stub(ScConnection.prototype, <any>'post');
13-
});
12+
scConnStub = sinon.stub(ScConnection.prototype, 'post')
13+
})
1414

1515
afterEach(() => {
16-
scConnStub.restore();
16+
scConnStub.restore()
1717
})
1818

1919
it('runs platform:env:create', async () => {
@@ -22,7 +22,7 @@ describe('platform:env:create', () => {
2222
})
2323

2424
it(`runs platform:env:create --name=${envName}`, async () => {
25-
let createOutputMsg = 'Environment created successfully.'
25+
const createOutputMsg = 'Environment created successfully.'
2626
scConnStub.returns(createOutputMsg)
2727

2828
const { stdout } = await runCommand(`platform:env:create --name=${envName}`)

test/commands/platform/env/delete.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ function anEnv(name: string, isDefault: boolean, isProd: boolean) {
2222
}
2323

2424
describe('platform:env:delete', () => {
25-
let scConnDeleteStub: any
26-
let scConnGetStub: any
27-
let envName: string = 'MyTestEnvironment'
25+
let scConnDeleteStub: sinon.SinonStub
26+
let scConnGetStub: sinon.SinonStub
27+
const envName: string = 'MyTestEnvironment'
2828

2929
beforeEach(() => {
30-
scConnDeleteStub = sinon.stub(ScConnection.prototype, <any>'delete');
31-
scConnGetStub = sinon.stub(ScConnection.prototype, <any>'get');
32-
});
30+
scConnDeleteStub = sinon.stub(ScConnection.prototype, 'delete')
31+
scConnGetStub = sinon.stub(ScConnection.prototype, 'get')
32+
})
3333

3434
afterEach(() => {
35-
scConnDeleteStub.restore();
36-
scConnGetStub.restore();
35+
scConnDeleteStub.restore()
36+
scConnGetStub.restore()
3737
})
3838

3939
it('runs platform:env:delete cmd', async () => {
@@ -56,7 +56,7 @@ describe('platform:env:delete', () => {
5656
}
5757
}
5858

59-
let deleteSuccessMsg = `Environment with id 'id${envName}' has been deleted successfully.`
59+
const deleteSuccessMsg = `Environment with id 'id${envName}' has been deleted successfully.`
6060
scConnGetStub.returns(Promise.resolve(envs))
6161
scConnDeleteStub.returns(deleteSuccessMsg)
6262

@@ -65,7 +65,7 @@ describe('platform:env:delete', () => {
6565
})
6666

6767
it(`runs platform:env:delete --env-id id${envName}`, async () => {
68-
let deleteSuccessMsg = `Environment with id 'id${envName}' has been deleted successfully.`
68+
const deleteSuccessMsg = `Environment with id 'id${envName}' has been deleted successfully.`
6969
scConnDeleteStub.returns(deleteSuccessMsg)
7070

7171
const { stdout } = await runCommand(`platform:env:delete --env-id id${envName}`)

test/commands/platform/env/display.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ function anEnv(name: string, isDefault: boolean, isProd: boolean) {
2424
}
2525

2626
describe('platform:env:display', () => {
27-
let scConnStub: any
27+
let scConnStub: sinon.SinonStub
2828

2929
beforeEach(() => {
30-
scConnStub = sinon.stub(ScConnection.prototype, <any>'get');
31-
});
30+
scConnStub = sinon.stub(ScConnection.prototype, 'get')
31+
})
3232

3333
afterEach(() => {
34-
scConnStub.restore();
34+
scConnStub.restore()
3535
})
3636

3737
it('runs platform:env:display', async () => {
@@ -56,12 +56,10 @@ describe('platform:env:display', () => {
5656
}
5757
scConnStub.returns(Promise.resolve(envs))
5858

59-
let tableRows: any[] = [['Key', 'Value']]
60-
tableRows = tableRows.concat(Object.entries(envs.data[0])
61-
.map(([key, value]) => ([
62-
camelCaseToTitleCase(key),
63-
value
64-
])))
59+
const tableRows = [
60+
['Key', 'Value'],
61+
...Object.entries(envs.data[0]).map(([key, value]) => [camelCaseToTitleCase(key), value]),
62+
]
6563

6664
const config = {
6765
columns: {

test/commands/platform/env/list.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function anEnv(name: string, isDefault: boolean, isProd: boolean) {
2020
}
2121

2222
describe('platform:env:list', () => {
23-
let scConnStub: any
23+
let scConnStub: sinon.SinonStub
2424

2525
beforeEach(() => {
26-
scConnStub = sinon.stub(ScConnection.prototype, <any>'get');
27-
});
26+
scConnStub = sinon.stub(ScConnection.prototype, 'get')
27+
})
2828

2929
afterEach(() => {
30-
scConnStub.restore();
30+
scConnStub.restore()
3131
})
3232

3333
it('runs platform:env:list', async () => {

test/commands/platform/env/update.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ function anEnv(name: string, isDefault: boolean, isProd: boolean) {
2222
}
2323

2424
describe('platform:env:update', () => {
25-
let scConnUpdateStub: any
26-
let scConnGetStub: any
27-
let envName: string = 'MyTestEnvironment'
25+
let scConnUpdateStub: sinon.SinonStub
26+
let scConnGetStub: sinon.SinonStub
27+
const envName: string = 'MyTestEnvironment'
2828

2929
beforeEach(() => {
30-
scConnUpdateStub = sinon.stub(ScConnection.prototype, <any>'put');
31-
scConnGetStub = sinon.stub(ScConnection.prototype, <any>'get');
32-
});
30+
scConnUpdateStub = sinon.stub(ScConnection.prototype, 'put')
31+
scConnGetStub = sinon.stub(ScConnection.prototype, 'get')
32+
})
3333

3434
afterEach(() => {
35-
scConnUpdateStub.restore();
36-
scConnGetStub.restore();
35+
scConnUpdateStub.restore()
36+
scConnGetStub.restore()
3737
})
3838

3939
it('runs platform:env:update cmd', async () => {
@@ -56,7 +56,7 @@ describe('platform:env:update', () => {
5656
}
5757
}
5858

59-
let updateSuccessMsg = `Environment with id 'id${envName}' has been updated successfully.`
59+
const updateSuccessMsg = `Environment with id 'id${envName}' has been updated successfully.`
6060
scConnGetStub.returns(Promise.resolve(envs))
6161
scConnUpdateStub.returns(updateSuccessMsg)
6262

@@ -65,7 +65,7 @@ describe('platform:env:update', () => {
6565
})
6666

6767
it(`runs platform:env:update --env-id id${envName} --desc "This is a test description."`, async () => {
68-
let updateSuccessMsg = `Environment with id 'id${envName}' has been updated successfully.`
68+
const updateSuccessMsg = `Environment with id 'id${envName}' has been updated successfully.`
6969
scConnUpdateStub.returns(updateSuccessMsg)
7070

7171
const { stdout } = await runCommand(`platform:env:update --env-id id${envName} --desc "This is a test description."`)

0 commit comments

Comments
 (0)