Skip to content

Commit 214f656

Browse files
feat(commerce): add commerce:tail-command-execution-log fixes #447
1 parent 7c1a756 commit 214f656

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Adobe Inc.",
66
"bugs": "https://github.com/adobe/aio-cli-plugin-cloudmanager/issues",
77
"dependencies": {
8-
"@adobe/aio-lib-cloudmanager": "^1.5.0",
8+
"@adobe/aio-lib-cloudmanager": "^1.6.0",
99
"@adobe/aio-lib-core-config": "^2.0.0",
1010
"@adobe/aio-lib-core-errors": "^3.0.1",
1111
"@adobe/aio-lib-core-logging": "^1.2.0",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2021 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
const BaseCommand = require('../../../base-command')
14+
const { initSdk, getProgramId, sanitizeEnvironmentId } = require('../../../cloudmanager-helpers')
15+
const commonFlags = require('../../../common-flags')
16+
17+
class TailCommerceCommandExecutionLog extends BaseCommand {
18+
async run () {
19+
const { args, flags } = this.parse(TailCommerceCommandExecutionLog)
20+
21+
const programId = getProgramId(flags)
22+
23+
const environmentId = sanitizeEnvironmentId(args.environmentId)
24+
25+
const result = await this.tailLog(programId, environmentId, args.commandExecutionId, flags.imsContextName)
26+
27+
this.log()
28+
29+
return result
30+
}
31+
32+
async tailLog (programId, environmentId, commandExecutionId, imsContextName = null) {
33+
const sdk = await initSdk(imsContextName)
34+
return sdk.tailCommerceCommandExecutionLog(programId, environmentId, commandExecutionId, process.stdout)
35+
}
36+
}
37+
38+
TailCommerceCommandExecutionLog.description = 'outputs a stream of log data for the specified environment and commerce execution id'
39+
40+
TailCommerceCommandExecutionLog.args = [
41+
{ name: 'environmentId', required: true, description: 'the environment id' },
42+
{ name: 'commandExecutionId', required: true, description: 'the commerece command execution id' },
43+
]
44+
45+
TailCommerceCommandExecutionLog.flags = {
46+
...commonFlags.global,
47+
...commonFlags.programId,
48+
}
49+
50+
module.exports = TailCommerceCommandExecutionLog

test/__mocks__/@adobe/aio-lib-cloudmanager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ function createDefaultMock () {
112112
tailLog: jest.fn(() => Promise.resolve()),
113113
tailExecutionStepLog: jest.fn(() => Promise.resolve()),
114114
invalidatePipelineCache: jest.fn(() => Promise.resolve()),
115+
tailCommerceCommandExecutionLog: jest.fn(() => Promise.resolve()),
115116
}
116117
}
117118

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2021 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
const { resetCurrentOrgId, setCurrentOrgId } = require('@adobe/aio-lib-ims')
14+
const { init, mockSdk } = require('@adobe/aio-lib-cloudmanager')
15+
const TailCommandExecutionLog = require('../../../src/commands/cloudmanager/commerce/tail-command-execution-log')
16+
17+
beforeEach(() => {
18+
resetCurrentOrgId()
19+
})
20+
21+
test('commerce-tail-log - missing arg', async () => {
22+
expect.assertions(2)
23+
24+
const runResult = TailCommandExecutionLog.run([])
25+
await expect(runResult instanceof Promise).toBeTruthy()
26+
await expect(runResult).rejects.toThrow(/^Missing 2 required arg/)
27+
})
28+
29+
test('commerce-tail-log - missing config', async () => {
30+
expect.assertions(2)
31+
32+
const runResult = TailCommandExecutionLog.run(['5', '123', '--programId', '5'])
33+
await expect(runResult instanceof Promise).toBeTruthy()
34+
await expect(runResult).rejects.toThrow('[CloudManagerCLI:NO_IMS_CONTEXT] Unable to find IMS context aio-cli-plugin-cloudmanager.')
35+
})
36+
37+
test('commerce-tail-log - config', async () => {
38+
setCurrentOrgId('good')
39+
40+
expect.assertions(5)
41+
42+
const runResult = TailCommandExecutionLog.run(['17', '123', '--programId', '5'])
43+
await expect(runResult instanceof Promise).toBeTruthy()
44+
await runResult
45+
await expect(init.mock.calls.length).toEqual(1)
46+
await expect(init).toHaveBeenCalledWith('good', 'test-client-id', 'fake-token', 'https://cloudmanager.adobe.io')
47+
await expect(mockSdk.tailCommerceCommandExecutionLog.mock.calls.length).toEqual(1)
48+
await expect(mockSdk.tailCommerceCommandExecutionLog).toHaveBeenCalledWith('5', '17', '123', process.stdout)
49+
})

0 commit comments

Comments
 (0)