Skip to content

Commit 61bce1f

Browse files
authored
feat(commerce): add app:config:dump command fixes #474 (#477)
1 parent 479ce45 commit 61bce1f

File tree

2 files changed

+203
-0
lines changed
  • src/commands/cloudmanager/commerce/bin-magento/app/config
  • test/commands/commerce/bin-magento/app/config

2 files changed

+203
-0
lines changed
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 BaseCommerceCliCommand = require('../../../../../../base-commerce-cli-command')
14+
const { getProgramId } = require('../../../../../../cloudmanager-helpers')
15+
const commonFlags = require('../../../../../../common-flags')
16+
const commonArgs = require('../../../../../../common-args')
17+
18+
class AppConfigDumpCommand extends BaseCommerceCliCommand {
19+
async run () {
20+
const { args, flags, argv } = this.parse(AppConfigDumpCommand)
21+
22+
const programId = getProgramId(flags)
23+
const configTypes = argv.slice(1)
24+
25+
const result = await this.runSync(programId, args.environmentId,
26+
{
27+
type: 'bin/magento',
28+
command: 'app:config:dump',
29+
options: ['-n', ...configTypes],
30+
},
31+
1000, 'app:config:dump')
32+
33+
return result
34+
}
35+
}
36+
37+
AppConfigDumpCommand.strict = false
38+
39+
AppConfigDumpCommand.description = 'commerce config dump'
40+
41+
AppConfigDumpCommand.flags = {
42+
...commonFlags.global,
43+
...commonFlags.programId,
44+
}
45+
46+
AppConfigDumpCommand.args = [
47+
commonArgs.environmentId,
48+
]
49+
50+
module.exports = AppConfigDumpCommand
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 { cli } = require('cli-ux')
14+
const { init, mockSdk } = require('@adobe/aio-lib-cloudmanager')
15+
const { resetCurrentOrgId, setCurrentOrgId } = require('@adobe/aio-lib-ims')
16+
const AppConfigDumpCommand = require('../../../../../../src/commands/cloudmanager/commerce/bin-magento/app/config/dump')
17+
18+
beforeEach(() => {
19+
resetCurrentOrgId()
20+
})
21+
22+
test('app:config:dump - missing environmentId', async () => {
23+
expect.assertions(2)
24+
25+
const runResult = AppConfigDumpCommand.run([])
26+
await expect(runResult instanceof Promise).toBeTruthy()
27+
await expect(runResult).rejects.toThrow(/^Missing 1 required arg/)
28+
})
29+
30+
test('app:config:dump - missing IMS Context', async () => {
31+
expect.assertions(2)
32+
33+
const runResult = AppConfigDumpCommand.run(['--programId', '3', '60'])
34+
await expect(runResult instanceof Promise).toBeTruthy()
35+
await expect(runResult).rejects.toThrow('[CloudManagerCLI:NO_IMS_CONTEXT] Unable to find IMS context aio-cli-plugin-cloudmanager.')
36+
})
37+
38+
test('app:config:dump - api error', async () => {
39+
setCurrentOrgId('valid-org-id')
40+
mockSdk.postCommerceCommandExecution = jest.fn(() =>
41+
Promise.reject(new Error('Command failed.')),
42+
)
43+
mockSdk.getCommerceCommandExecution = jest.fn()
44+
const runResult = AppConfigDumpCommand.run(['--programId', '3', '60'])
45+
await expect(runResult instanceof Promise).toBeTruthy()
46+
await expect(runResult).rejects.toEqual(new Error('Command failed.'))
47+
})
48+
49+
test('app:config:dump - success with config types', async () => {
50+
let counter = 0
51+
setCurrentOrgId('valid-org-id')
52+
mockSdk.postCommerceCommandExecution = jest.fn(() =>
53+
Promise.resolve({
54+
id: '6000',
55+
}),
56+
)
57+
mockSdk.getCommerceCommandExecution = jest.fn(() => {
58+
counter++
59+
if (counter === 1) {
60+
return Promise.resolve({
61+
status: 'PENDING',
62+
message: 'running config dump',
63+
})
64+
} else if (counter < 3) {
65+
return Promise.resolve({
66+
status: 'RUNNING',
67+
message: 'running config dump',
68+
})
69+
}
70+
return Promise.resolve({
71+
status: 'COMPLETE',
72+
message: 'done',
73+
})
74+
})
75+
76+
expect.assertions(11)
77+
78+
const runResult = AppConfigDumpCommand.run(['--programId', '3', '60', 'i18n', 'scopes'])
79+
await expect(runResult instanceof Promise).toBeTruthy()
80+
await runResult
81+
await expect(init.mock.calls.length).toEqual(1)
82+
await expect(init).toHaveBeenCalledWith(
83+
'valid-org-id',
84+
'test-client-id',
85+
'fake-token',
86+
'https://cloudmanager.adobe.io',
87+
)
88+
await expect(mockSdk.postCommerceCommandExecution.mock.calls.length).toEqual(1)
89+
await expect(mockSdk.postCommerceCommandExecution).toHaveBeenCalledWith('3', '60', {
90+
type: 'bin/magento',
91+
command: 'app:config:dump',
92+
options: ['-n', 'i18n', 'scopes'],
93+
})
94+
await expect(mockSdk.getCommerceCommandExecution).toHaveBeenCalledWith('3', '60', '6000')
95+
await expect(mockSdk.getCommerceCommandExecution).toHaveBeenCalledTimes(3)
96+
await expect(cli.action.start.mock.calls[0][0]).toEqual('Starting app:config:dump')
97+
await expect(cli.action.start.mock.calls[1][0]).toEqual('Starting app:config:dump')
98+
await expect(cli.action.start.mock.calls[2][0]).toEqual('Running app:config:dump')
99+
await expect(cli.action.stop.mock.calls[0][0]).toEqual('done')
100+
})
101+
102+
test('app:config:dump - success without config types', async () => {
103+
let counter = 0
104+
setCurrentOrgId('valid-org-id')
105+
mockSdk.postCommerceCommandExecution = jest.fn(() =>
106+
Promise.resolve({
107+
id: '6000',
108+
}),
109+
)
110+
mockSdk.getCommerceCommandExecution = jest.fn(() => {
111+
counter++
112+
if (counter === 1) {
113+
return Promise.resolve({
114+
status: 'PENDING',
115+
message: 'running config dump',
116+
})
117+
} else if (counter < 3) {
118+
return Promise.resolve({
119+
status: 'RUNNING',
120+
message: 'running config dump',
121+
})
122+
}
123+
return Promise.resolve({
124+
status: 'COMPLETE',
125+
message: 'done',
126+
})
127+
})
128+
129+
expect.assertions(11)
130+
131+
const runResult = AppConfigDumpCommand.run(['--programId', '3', '60'])
132+
await expect(runResult instanceof Promise).toBeTruthy()
133+
await runResult
134+
await expect(init.mock.calls.length).toEqual(1)
135+
await expect(init).toHaveBeenCalledWith(
136+
'valid-org-id',
137+
'test-client-id',
138+
'fake-token',
139+
'https://cloudmanager.adobe.io',
140+
)
141+
await expect(mockSdk.postCommerceCommandExecution.mock.calls.length).toEqual(1)
142+
await expect(mockSdk.postCommerceCommandExecution).toHaveBeenCalledWith('3', '60', {
143+
type: 'bin/magento',
144+
command: 'app:config:dump',
145+
options: ['-n'],
146+
})
147+
await expect(mockSdk.getCommerceCommandExecution).toHaveBeenCalledWith('3', '60', '6000')
148+
await expect(mockSdk.getCommerceCommandExecution).toHaveBeenCalledTimes(3)
149+
await expect(cli.action.start.mock.calls[0][0]).toEqual('Starting app:config:dump')
150+
await expect(cli.action.start.mock.calls[1][0]).toEqual('Starting app:config:dump')
151+
await expect(cli.action.start.mock.calls[2][0]).toEqual('Running app:config:dump')
152+
await expect(cli.action.stop.mock.calls[0][0]).toEqual('done')
153+
})

0 commit comments

Comments
 (0)