Skip to content

Commit 6fdb241

Browse files
add better console info when no log options are availble. fixes #51 (#52)
* add better console info when no log options are availble. fixes #51 * coverage
1 parent 02810a7 commit 6fdb241

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/commands/cloudmanager/list-available-log-options.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@ class ListAvailableLogOptionsCommand extends Command {
3838
this.error(error.message)
3939
}
4040

41-
cli.table(result, {
42-
id: {
43-
header: "Environment Id",
44-
get: () => args.environmentId
45-
},
46-
service: {},
47-
name: {}
48-
}, {
49-
printLine: this.log
50-
})
41+
if (result.length > 0) {
42+
cli.table(result, {
43+
id: {
44+
header: "Environment Id",
45+
get: () => args.environmentId
46+
},
47+
service: {},
48+
name: {}
49+
}, {
50+
printLine: this.log
51+
})
52+
} else {
53+
cli.info(`No log options are available for environmentId ${args.environmentId}`)
54+
}
5155

5256
return result
5357
}

test/__mocks__/cli-ux.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
action: {
1717
start: jest.fn(),
1818
stop: jest.fn()
19-
}
19+
},
20+
info: jest.fn()
2021
}
2122
};

test/commands/list-available-log-options.test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
1010
governing permissions and limitations under the License.
1111
*/
1212

13+
const { cli } = require('cli-ux')
1314
const { setStore } = require('@adobe/aio-cna-core-config')
1415
const ListAvailableLogOptionsCommand = require('../../src/commands/cloudmanager/list-available-log-options')
1516

@@ -70,11 +71,12 @@ test('list-available-logs - success undefined', async () => {
7071
'cloudmanager_programid': "4"
7172
})
7273

73-
expect.assertions(2)
74+
expect.assertions(3)
7475

7576
let runResult = ListAvailableLogOptionsCommand.run(["3"])
7677
await expect(runResult instanceof Promise).toBeTruthy()
7778
await expect(runResult).resolves.toEqual([])
79+
await expect(cli.info.mock.calls[0][0]).toBe("No log options are available for environmentId 3")
7880
})
7981

8082
test('list-available-logs - success empty', async () => {
@@ -88,11 +90,12 @@ test('list-available-logs - success empty', async () => {
8890
'cloudmanager_programid': "4"
8991
})
9092

91-
expect.assertions(2)
93+
expect.assertions(3)
9294

9395
let runResult = ListAvailableLogOptionsCommand.run(["2"])
9496
await expect(runResult instanceof Promise).toBeTruthy()
9597
await expect(runResult).resolves.toEqual([])
98+
await expect(cli.info.mock.calls[0][0]).toBe("No log options are available for environmentId 2")
9699
})
97100

98101
test('list-available-logs - success', async () => {
@@ -106,7 +109,7 @@ test('list-available-logs - success', async () => {
106109
'cloudmanager_programid': "4"
107110
})
108111

109-
expect.assertions(2)
112+
expect.assertions(3)
110113

111114
let runResult = ListAvailableLogOptionsCommand.run(["1"])
112115
await expect(runResult instanceof Promise).toBeTruthy()
@@ -146,6 +149,8 @@ test('list-available-logs - success', async () => {
146149
"service" : "dispatcher",
147150
"name" : "aemdispatcher"
148151
}])
152+
153+
await expect(cli.table.mock.calls[0][1].id.get({environmentId: 1})).toBe("1")
149154
})
150155

151156

0 commit comments

Comments
 (0)