Skip to content

Commit f2a5768

Browse files
fix(hook): check-ims-config is not correctly throwing errors. fixes #295 (#297)
1 parent aa14ecf commit f2a5768

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/hooks/prerun/prerun-all.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ governing permissions and limitations under the License.
1414
*/
1515

1616
module.exports = function (hookOptions) {
17-
require('./environment-id-from-config')(hookOptions)
18-
require('./check-ims-context-config')(hookOptions)
17+
require('./environment-id-from-config').apply(this, [hookOptions])
18+
require('./check-ims-context-config').apply(this, [hookOptions])
1919
}

test/hooks/prerun/prerun-all.test.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ beforeEach(() => {
99
parse = jest.fn()
1010
})
1111

12+
const invoke = (options) => {
13+
return () => hook.apply({ error: (msg) => { throw new Error(msg) } }, [{
14+
...options,
15+
}])
16+
}
17+
1218
test('hook -- environmentId args with config', async () => {
1319
setStore({
1420
cloudmanager_environmentid: '4321',
@@ -32,15 +38,41 @@ test('hook -- environmentId args with config', async () => {
3238

3339
expect.assertions(2)
3440

35-
await hook({
41+
invoke({
3642
Command: FixtureWithEnvironmentIdArg,
3743
argv: [],
38-
})
44+
})()
3945
new FixtureWithEnvironmentIdArg().parse(FixtureWithEnvironmentIdArg, [])
4046
expect(parse.mock.calls.length).toEqual(2)
4147
expect(parse.mock.calls[1][1]).toEqual(['4321'])
4248
})
4349

50+
test('hook -- bad configuration', async () => {
51+
setStore({
52+
cloudmanager_environmentid: '4321',
53+
'ims.contexts.aio-cli-plugin-cloudmanager': {
54+
client_id: 'test-client-id',
55+
client_secret: '5678',
56+
ims_org_id: 'someorg@AdobeOrg',
57+
technical_account_id: '[email protected]',
58+
technical_account_email: 'unused',
59+
meta_scopes: [
60+
'ent_adobeio_sdk',
61+
'ent_cloudmgr_sdk',
62+
],
63+
},
64+
})
65+
66+
parse = jest.fn().mockImplementationOnce(() => true)
67+
68+
expect.assertions(1)
69+
70+
expect(invoke({
71+
Command: FixtureWithEnvironmentIdArg,
72+
argv: [],
73+
})).toThrowError('One or more of the required fields in ims.contexts.aio-cli-plugin-cloudmanager were not set. Missing keys were private_key.')
74+
})
75+
4476
const thisPlugin = {
4577
name: '@adobe/aio-cli-plugin-cloudmanager',
4678
}

0 commit comments

Comments
 (0)