Skip to content

Commit d6eae86

Browse files
Tests for mission ctrl broker cmds
1 parent f546b40 commit d6eae86

File tree

7 files changed

+251
-52
lines changed

7 files changed

+251
-52
lines changed

src/commands/missionctrl/broker/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Token Permissions: [ \`services:delete\` **or** \`services:delete:self\` **or**
1717
static override flags = {
1818
// flag for getting environment by id (-e, --env-id)
1919
'broker-id': Flags.string({
20-
char: 'e',
20+
char: 'b',
2121
description: 'Id of the event broker service.',
2222
exactlyOne: ['broker-id', 'name'],
2323
}),
Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,78 @@
1-
import {runCommand} from '@oclif/test'
2-
import {expect} from 'chai'
1+
import { runCommand } from '@oclif/test'
2+
import { expect } from 'chai'
3+
import * as sinon from 'sinon'
4+
5+
import { ScConnection } from '../../../../src/util/sc-connection.js'
36

47
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) {
16+
return {
17+
bgColor: '#DA162D',
18+
createdBy: 'someuser',
19+
createdTime: '2024-09-05T19:54:42.766',
20+
description: `This is a description for the the environment ${name}`,
21+
fgColor: '#FFFFFF',
22+
icon: 'ROCKET_LAUNCH',
23+
id: `id${name}`,
24+
isDefault,
25+
isProduction: isProd,
26+
name,
27+
updatedBy: 'someuser',
28+
updatedTime: '2024-09-05T19:54:42.766',
29+
}
30+
}
31+
32+
beforeEach(() => {
33+
scConnPostStub = sinon.stub(ScConnection.prototype, <any>'post')
34+
scConnGetStub = sinon.stub(ScConnection.prototype, <any>'get')
35+
});
36+
37+
afterEach(() => {
38+
scConnPostStub.restore()
39+
scConnGetStub.restore()
40+
})
41+
542
it('runs missionctrl:broker:create cmd', async () => {
6-
const {stdout} = await runCommand('missionctrl:broker:create')
7-
expect(stdout).to.contain('hello world')
43+
const { stdout } = await runCommand('missionctrl:broker:create')
44+
expect(stdout).to.contain('')
845
})
946

10-
it('runs missionctrl:broker:create --name oclif', async () => {
11-
const {stdout} = await runCommand('missionctrl:broker:create --name oclif')
12-
expect(stdout).to.contain('hello oclif')
47+
it(`runs missionctrl:broker:create -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`, async () => {
48+
let createOutputMsg = 'Event broker service created successfully.'
49+
scConnPostStub.returns(createOutputMsg)
50+
51+
const { stdout } = await runCommand(`missionctrl:broker:create -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`)
52+
expect(stdout).to.contain(createOutputMsg)
53+
})
54+
55+
it(`runs missionctrl:broker:create -e ${envName} -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`, async () => {
56+
// Arrange
57+
const envName = 'Default'
58+
const envs = {
59+
data: [anEnv(envName, true, false)],
60+
meta: {
61+
pagination: {
62+
count: 1,
63+
nextPage: null,
64+
pageNumber: 1,
65+
pageSize: 10,
66+
totalPages: 1
67+
}
68+
}
69+
}
70+
scConnGetStub.returns(Promise.resolve(envs))
71+
72+
let createOutputMsg = 'Event broker service created successfully.'
73+
scConnPostStub.returns(createOutputMsg)
74+
75+
const { stdout } = await runCommand(`missionctrl:broker:create -e ${envName} -n ${brokerName} -d ${brokerDC} -c ${brokerSvcClassId}`)
76+
expect(stdout).to.contain(createOutputMsg)
1377
})
1478
})
Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1-
import {runCommand} from '@oclif/test'
2-
import {expect} from 'chai'
1+
import { runCommand } from '@oclif/test'
2+
import { expect } from 'chai'
3+
import * as sinon from 'sinon'
4+
5+
import { ScConnection } from '../../../../src/util/sc-connection.js'
36

47
describe('missionctrl:broker:delete', () => {
8+
let scConnDeleteStub: any
9+
let scConnGetStub: any
10+
let brokerId: string = 'MyTestBrokerId'
11+
//let brokerName: string = 'MyTestBrokerName'
12+
13+
beforeEach(() => {
14+
scConnDeleteStub = sinon.stub(ScConnection.prototype, <any>'delete');
15+
scConnGetStub = sinon.stub(ScConnection.prototype, <any>'get');
16+
});
17+
18+
afterEach(() => {
19+
scConnDeleteStub.restore();
20+
scConnGetStub.restore();
21+
})
22+
523
it('runs missionctrl:broker:delete cmd', async () => {
6-
const {stdout} = await runCommand('missionctrl:broker:delete')
7-
expect(stdout).to.contain('hello world')
24+
const { stdout } = await runCommand('missionctrl:broker:delete')
25+
expect(stdout).to.contain('')
826
})
927

10-
it('runs missionctrl:broker:delete --name oclif', async () => {
11-
const {stdout} = await runCommand('missionctrl:broker:delete --name oclif')
12-
expect(stdout).to.contain('hello oclif')
28+
it(`runs missionctrl:broker:delete -b ${brokerId}`, async () => {
29+
let deleteSuccessMsg = `Event broker service with id '${brokerId}' has been deleted successfully.`
30+
scConnDeleteStub.returns(deleteSuccessMsg)
31+
32+
const { stdout } = await runCommand(`missionctrl:broker:delete -b ${brokerId}`)
33+
expect(stdout).to.contain(deleteSuccessMsg)
1334
})
1435
})
Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,70 @@
1-
import {runCommand} from '@oclif/test'
2-
import {expect} from 'chai'
1+
import { runCommand } from '@oclif/test'
2+
import { expect } from 'chai'
3+
import * as sinon from 'sinon'
4+
import { table } from 'table'
5+
6+
import { camelCaseToTitleCase } from '../../../../src/util/internal.js'
7+
import { ScConnection } from '../../../../src/util/sc-connection.js'
8+
9+
function anBroker(brokerName: string, brokerId: string) {
10+
return {
11+
completedTime: '',
12+
createdBy: 'test',
13+
createdTime: '2024-09-05T19:54:42.766',
14+
id: brokerId,
15+
operationType: '',
16+
resourceId: '',
17+
resourceType: '',
18+
status: '',
19+
type: '',
20+
}
21+
}
322

423
describe('missionctrl:broker:display', () => {
24+
let brokerName: string = 'Default'
25+
let brokerId: string = 'MyTestBrokerId'
26+
let scConnStub: any
27+
28+
beforeEach(() => {
29+
scConnStub = sinon.stub(ScConnection.prototype, <any>'get');
30+
});
31+
32+
afterEach(() => {
33+
scConnStub.restore();
34+
})
35+
536
it('runs missionctrl:broker:display cmd', async () => {
6-
const {stdout} = await runCommand('missionctrl:broker:display')
7-
expect(stdout).to.contain('hello world')
37+
const { stdout } = await runCommand('missionctrl:broker:display')
38+
expect(stdout).to.contain('')
839
})
940

10-
it('runs missionctrl:broker:display --name oclif', async () => {
11-
const {stdout} = await runCommand('missionctrl:broker:display --name oclif')
12-
expect(stdout).to.contain('hello oclif')
41+
it(`runs missionctrl:broker:display -b ${brokerId}`, async () => {
42+
// Arrange
43+
const broker = {
44+
data: [anBroker(brokerName, brokerId)],
45+
meta: {
46+
additionalProp: {}
47+
}
48+
}
49+
scConnStub.returns(Promise.resolve(broker))
50+
51+
const tableRows = [
52+
['Key', 'Value'],
53+
...Object.entries(broker).map(([key, value]) => [camelCaseToTitleCase(key), value]),
54+
]
55+
56+
// Table config
57+
const config = {
58+
columns: {
59+
1: { width: 50, wrapWord: true },
60+
},
61+
drawHorizontalLine(lineIndex: number, rowCount: number) {
62+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount
63+
},
64+
}
65+
66+
67+
const { stdout } = await runCommand('missionctrl:broker:display -b ${brokerId}')
68+
expect(stdout).to.contain(table(tableRows, config))
1369
})
1470
})
Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
1-
import {runCommand} from '@oclif/test'
2-
import {expect} from 'chai'
1+
import { runCommand } from '@oclif/test'
2+
import { expect } from 'chai'
3+
import * as sinon from 'sinon'
4+
import { table } from 'table'
5+
6+
import { ScConnection } from '../../../../src/util/sc-connection.js'
7+
8+
function anBroker(brokerName: string, brokerId: string) {
9+
return {
10+
completedTime: '',
11+
createdBy: 'test',
12+
createdTime: '2024-09-05T19:54:42.766',
13+
id: brokerId,
14+
operationType: '',
15+
resourceId: '',
16+
resourceType: '',
17+
status: '',
18+
type: '',
19+
}
20+
}
321

422
describe('missionctrl:broker:list', () => {
5-
it('runs missionctrl:broker:list cmd', async () => {
6-
const {stdout} = await runCommand('missionctrl:broker:list')
7-
expect(stdout).to.contain('hello world')
23+
let scConnStub: any
24+
25+
beforeEach(() => {
26+
scConnStub = sinon.stub(ScConnection.prototype, <any>'get');
27+
});
28+
29+
afterEach(() => {
30+
scConnStub.restore();
831
})
932

10-
it('runs missionctrl:broker:list --name oclif', async () => {
11-
const {stdout} = await runCommand('missionctrl:broker:list --name oclif')
12-
expect(stdout).to.contain('hello oclif')
33+
it('runs missionctrl:broker:list cmd', async () => {
34+
// Arrange
35+
const envs = {
36+
data: [anBroker('Broker1', 'BrokerId1'), anBroker('Broker1', 'BrokerId1'),
37+
anBroker('Broker3', 'BrokerId3')],
38+
meta: {
39+
pagination: {
40+
count: 3,
41+
nextPage: null,
42+
pageNumber: 1,
43+
pageSize: 5,
44+
totalPages: 1
45+
}
46+
}
47+
}
48+
scConnStub.returns(Promise.resolve(envs))
49+
50+
// Expected
51+
const brokerArray = [
52+
['Name', 'Id', 'Type', 'Version', 'Owned By', 'Datacenter Id', 'Service Class Id'],
53+
...envs.data.map((item: any) => [
54+
item.name,
55+
item.id,
56+
item.type,
57+
item.eventBrokerServiceVersion,
58+
item.ownedBy,
59+
item.datacenterId,
60+
item.serviceClassId,
61+
]),
62+
]
63+
64+
const { stdout } = await runCommand('missionctrl:broker:list')
65+
expect(stdout).to.contain(table(brokerArray))
1366
})
1467
})

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { captureOutput } from '@oclif/test'
1+
import { runCommand } from '@oclif/test'
22
import { expect } from 'chai'
33
import * as sinon from 'sinon'
44
import { table } from 'table'
55

6-
import PlatformEnvList from '../../../../src/commands/platform/env/list'
76
import { ScConnection } from '../../../../src/util/sc-connection'
87

98
function anEnv(name: string, isDefault: boolean, isProd: boolean) {
@@ -46,24 +45,26 @@ describe('platform:env:list', () => {
4645
}
4746
}
4847
scConnStub.returns(Promise.resolve(envs))
48+
4949
// Expected
50-
let envArray: any[] = [['Name', 'Id', 'Is Default', 'Is Production', 'Description']]
51-
const jsonArray = envs.data.map((item: any) => [
52-
item.name,
53-
item.id,
54-
item.isDefault,
55-
item.isProduction,
56-
item.description])
57-
envArray = envArray.concat(jsonArray)
50+
const envArray = [
51+
['Name', 'Id', 'Is Default', 'Is Production', 'Description'],
52+
...envs.data.map((item: any) => [
53+
item.name,
54+
item.id,
55+
item.isDefault,
56+
item.isProduction,
57+
item.description]),
58+
]
5859

5960
const config = {
6061
columns: {
6162
4: { width: 50, wrapWord: true }
6263
}
6364
}
6465
// Run command
65-
const { stdout } = await captureOutput(async () => PlatformEnvList.run([]))
66-
expect(stdout).to.contain(`\n${table(envArray, config)}`)
66+
const { stdout } = await runCommand('platform:env:list')
67+
expect(stdout).to.contain(table(envArray, config))
6768
})
6869

6970
it('runs platform:env:list --pageSize=5 --pageNumber=1', async () => {
@@ -83,21 +84,24 @@ describe('platform:env:list', () => {
8384
scConnStub.returns(Promise.resolve(envs))
8485

8586
// Expected
86-
let envArray: any[] = [['Name', 'Id', 'Is Default', 'Is Production', 'Description']]
87-
const jsonArray = envs.data.map((item: any) => [
88-
item.name,
89-
item.id,
90-
item.isDefault,
91-
item.isProduction,
92-
item.description])
93-
envArray = envArray.concat(jsonArray)
87+
const envArray = [
88+
['Name', 'Id', 'Is Default', 'Is Production', 'Description'],
89+
...envs.data.map((item: any) => [
90+
item.name,
91+
item.id,
92+
item.isDefault,
93+
item.isProduction,
94+
item.description]),
95+
]
9496

9597
const config = {
9698
columns: {
9799
4: { width: 50, wrapWord: true }
98100
}
99101
}
100-
const { stdout } = await captureOutput(async () => PlatformEnvList.run(['--pageSize=5', '--pageNumber=1']))
101-
expect(stdout).to.contain(`\n${table(envArray, config)}`)
102+
103+
// Run command
104+
const { stdout } = await runCommand('platform:env:list --pageSize=5', '--pageNumber=1')
105+
expect(stdout).to.contain(table(envArray, config))
102106
})
103107
})

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"target": "es2022",
99
"moduleResolution": "node16",
1010
"esModuleInterop": true,
11+
"composite": true
1112
},
1213
"include": ["./src/**/*"],
1314
"ts-node": {

0 commit comments

Comments
 (0)