@adobe/aio-lib-cloudmanager
Advanced tools
Comparing version 1.2.0 to 1.3.0
# Changelog | ||
# [1.3.0](https://github.com/adobe/aio-lib-cloudmanager/compare/1.2.0...1.3.0) (2021-07-27) | ||
### Features | ||
* **commerce:** add getCommerceCLICommand. fixes [#178](https://github.com/adobe/aio-lib-cloudmanager/issues/178) ([#196](https://github.com/adobe/aio-lib-cloudmanager/issues/196)) ([a0c9b61](https://github.com/adobe/aio-lib-cloudmanager/commit/a0c9b61c58ab8302974f15e7177b40974ade50c3)) | ||
# [1.2.0](https://github.com/adobe/aio-lib-cloudmanager/compare/1.1.1...1.2.0) (2021-07-27) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@adobe/aio-lib-cloudmanager", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Adobe I/O Cloud Manager Library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -177,2 +177,3 @@ <!-- | ||
* [.removeIpAllowlistBinding(programId, ipAllowlistId, environmentId, service)](#CloudManagerAPI+removeIpAllowlistBinding) ⇒ <code>Promise.<object></code> | ||
* [.getCommerceCommandExecution(programId, environmentId, executionId)](#CloudManagerAPI+getCommerceCommandExecution) ⇒ <code>Promise.<object></code> | ||
* [.postCommerceCommandExecution(programId, environmentId, options)](#CloudManagerAPI+postCommerceCommandExecution) ⇒ <code>Promise.<object></code> | ||
@@ -626,2 +627,16 @@ | ||
<a name="CloudManagerAPI+getCommerceCommandExecution"></a> | ||
### cloudManagerAPI.getCommerceCommandExecution(programId, environmentId, executionId) ⇒ <code>Promise.<object></code> | ||
Get status for an existing Commerce execution | ||
**Kind**: instance method of [<code>CloudManagerAPI</code>](#CloudManagerAPI) | ||
**Returns**: <code>Promise.<object></code> - a truthy value of the commerce execution | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| programId | <code>string</code> | the program id | | ||
| environmentId | <code>string</code> | the environment id | | ||
| executionId | <code>string</code> | the execution id | | ||
<a name="CloudManagerAPI+postCommerceCommandExecution"></a> | ||
@@ -628,0 +643,0 @@ |
@@ -33,2 +33,3 @@ /* | ||
commerceCommandExecution: 'http://ns.adobe.com/adobecloud/rel/commerceCommandExecution', | ||
commerceCommandExecutionId: 'http://ns.adobe.com/adobecloud/rel/commerceCommandExecution/id', | ||
}, | ||
@@ -35,0 +36,0 @@ config: { |
@@ -1230,2 +1230,28 @@ /* | ||
/** | ||
* Get status for an existing Commerce execution | ||
* | ||
* @param {string} programId - the program id | ||
* @param {string} environmentId - the environment id | ||
* @param {string} executionId - the execution id | ||
* @returns {Promise<object>} a truthy value of the commerce execution | ||
*/ | ||
async getCommerceCommandExecution (programId, environmentId, executionId) { | ||
const environment = await this._findEnvironment(programId, environmentId) | ||
const environmentLink = environment.link(rels.commerceCommandExecutionId) | ||
if (!environmentLink) { | ||
throw new codes.ERROR_COMMERCE_CLI({ messageValues: environmentId }) | ||
} | ||
const executionTemplate = UriTemplate.parse(environmentLink.href) | ||
const executionLink = executionTemplate.expand({ executionId: executionId }) | ||
return this._get(executionLink, codes.ERROR_GET_COMMERCE_CLI).then(async res => { | ||
return halfred.parse(await res.json()) | ||
}, e => { | ||
throw e | ||
}) | ||
} | ||
/** | ||
* Make a Post to Commerce API | ||
@@ -1232,0 +1258,0 @@ * |
@@ -107,3 +107,4 @@ /* | ||
E('ERROR_STEP_STATE_NOT_RUNNING', 'The %s step in execution %s is not currently running.') | ||
E('ERROR_GET_COMMERCE_CLI', 'Could not get Commerce Command Execution: %s') | ||
E('ERROR_POST_COMMERCE_CLI', 'Could not post to Commerce CLI endpoint: %s') | ||
E('ERROR_COMMERCE_CLI', 'Environment %s does not appear to support Commerce CLI') |
@@ -55,1 +55,71 @@ /* | ||
}) | ||
test('getCommerceCommandExecution - error: failure to find correct environment', async () => { | ||
expect.assertions(2) | ||
const sdkClient = await createSdkClient() | ||
const result = sdkClient.getCommerceCommandExecution('4', '3') | ||
await expect(result instanceof Promise).toBeTruthy() | ||
await expect(result).rejects.toEqual( | ||
new codes.ERROR_GET_COMMERCE_CLI({ messageValues: 'https://cloudmanager.adobe.io/api/program/4/environment/3/runtime/commerce/command-execution/ (403 Forbidden)' }), | ||
) | ||
}) | ||
test('getCommerceCommandExecution - error: failure to retrieve environments', async () => { | ||
expect.assertions(2) | ||
const sdkClient = await createSdkClient() | ||
const result = sdkClient.getCommerceCommandExecution('6', '7', '8') | ||
await expect(result instanceof Promise).toBeTruthy() | ||
await expect(result).rejects.toEqual( | ||
new codes.ERROR_RETRIEVE_ENVIRONMENTS({ messageValues: 'https://cloudmanager.adobe.io/api/program/6/environments (404 Not Found)' }), | ||
) | ||
}) | ||
test('getCommerceCommandExecution - error: no link', async () => { | ||
expect.assertions(2) | ||
const sdkClient = await createSdkClient() | ||
const result = sdkClient.getCommerceCommandExecution('4', '11') | ||
await expect(result instanceof Promise).toBeTruthy() | ||
await expect(result).rejects.toEqual( | ||
new codes.ERROR_COMMERCE_CLI({ messageValues: '11' }), | ||
) | ||
}) | ||
test('getCommerceCommandExecution - success', async () => { | ||
expect.assertions(2) | ||
const sdkClient = await createSdkClient() | ||
const result = sdkClient.getCommerceCommandExecution('4', '10', '1') | ||
await expect(result instanceof Promise).toBeTruthy() | ||
await expect(result).resolves.toMatchObject(halfred.parse({ | ||
id: 1, | ||
status: 'RUNNNG', // PENDING, RUNNING, COMPLETED, FAILED | ||
type: 'bin/magento', // bin/magento, bin/ece-tools | ||
command: 'test command to be executed', | ||
message: 'One line message on the progress of command', | ||
options: ['Optional', 'inputs provided part of the command'], | ||
startedAt: 'timestamp UTC', | ||
completedAt: 'timestamp utc', | ||
startedBy: 'test runner', | ||
_links: { | ||
self: { | ||
href: '/api/program/4/environment/10/runtime/commerce/command-execution/1', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/program': { | ||
href: '/api/program/4', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/environments': { | ||
href: '/api/program/4/environments', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/commerceCommandExecutions': { | ||
href: '/api/program/4/environment/10/runtime/commerce/command-executions', | ||
}, | ||
}, | ||
})) | ||
}) |
@@ -252,2 +252,6 @@ /* | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/commerceCommandExecution/id': { | ||
href: '/api/program/4/environment/3/runtime/commerce/command-execution/{executionId}', | ||
templated: true, | ||
}, | ||
}, | ||
@@ -272,2 +276,6 @@ id: '3', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/commerceCommandExecution/id': { | ||
href: '/api/program/4/environment/10/runtime/commerce/command-execution/{executionId}', | ||
templated: true, | ||
}, | ||
}, | ||
@@ -1650,2 +1658,32 @@ id: '10', | ||
// Commerce command execution mocks | ||
fetchMock.mock('https://cloudmanager.adobe.io/api/program/4/environment/3/runtime/commerce/command-execution/', 403) | ||
fetchMock.mock('https://cloudmanager.adobe.io/api/program/6/environment/7/runtime/commerce/command-execution/8', 404) | ||
mockResponseWithMethod('https://cloudmanager.adobe.io/api/program/4/environment/10/runtime/commerce/command-execution/1', 'GET', { | ||
id: 1, | ||
status: 'RUNNNG', // PENDING, RUNNING, COMPLETED, FAILED | ||
type: 'bin/magento', // bin/magento, bin/ece-tools | ||
command: 'test command to be executed', | ||
message: 'One line message on the progress of command', | ||
options: ['Optional', 'inputs provided part of the command'], | ||
startedAt: 'timestamp UTC', | ||
completedAt: 'timestamp utc', | ||
startedBy: 'test runner', | ||
_links: { | ||
self: { | ||
href: '/api/program/4/environment/10/runtime/commerce/command-execution/1', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/program': { | ||
href: '/api/program/4', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/environments': { | ||
href: '/api/program/4/environments', | ||
}, | ||
'http://ns.adobe.com/adobecloud/rel/commerceCommandExecutions': { | ||
href: '/api/program/4/environment/10/runtime/commerce/command-executions', | ||
}, | ||
}, | ||
}) | ||
mockResponseWithMethod('https://cloudmanager.adobe.io/api/program/4/environment/10/runtime/commerce/cli/', 'POST', { | ||
@@ -1652,0 +1690,0 @@ status: 201, |
@@ -286,2 +286,10 @@ /** | ||
/** | ||
* Get status for an existing Commerce execution | ||
* @param programId - the program id | ||
* @param environmentId - the environment id | ||
* @param executionId - the execution id | ||
* @returns a truthy value of the commerce execution | ||
*/ | ||
getCommerceCommandExecution(programId: string, environmentId: string, executionId: string): Promise<object>; | ||
/** | ||
* Make a Post to Commerce API | ||
@@ -288,0 +296,0 @@ * @param programId - the program id |
1877506
10692
946