-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add open command to reference project in console ui * added tests * allow optional?.chaining * linting - 100%
- Loading branch information
1 parent
71ef88b
commit 06cd602
Showing
8 changed files
with
191 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:open', { provider: 'debug' }) | ||
const { getCliEnv } = require('@adobe/aio-lib-env') | ||
const { CliUx } = require('@oclif/core') | ||
const { OPEN_URLS } = require('../../config') | ||
|
||
const ConsoleCommand = require('./index') | ||
class OpenCommand extends ConsoleCommand { | ||
async run () { | ||
// TODO: we could support --orgId and --projectId flags to open the console for a specific org/project | ||
// currently we open the console for the local config org/project | ||
// const { flags } = await this.parse(OpenCommand) | ||
|
||
aioLogger.debug('Inquiring currently selected Org, Project and Workspace') | ||
const cliEnv = getCliEnv() | ||
const config = this.getConfig() | ||
let url = OPEN_URLS[cliEnv] | ||
if (config?.project?.id && config?.project?.org_id) { | ||
url += `/${config.project.org_id}/${config.project.id}/` | ||
if (config.workspace && config.workspace.id) { | ||
url += `workspaces/${config.workspace.id}/details` | ||
} else { | ||
url += 'overview' | ||
} | ||
} | ||
aioLogger.debug(`opening url ${url}`) | ||
CliUx.ux.open(url) | ||
} | ||
} | ||
|
||
OpenCommand.description = 'Open the developer console for the selected Organization, Project and Workspace' | ||
|
||
OpenCommand.flags = { | ||
...ConsoleCommand.flags | ||
} | ||
|
||
OpenCommand.aliases = [ | ||
'open' | ||
] | ||
|
||
module.exports = OpenCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const TestCommand = require('../../../src/commands/console/open') | ||
const config = require('@adobe/aio-lib-core-config') | ||
const { STAGE_ENV } = require('@adobe/aio-lib-env') | ||
|
||
jest.mock('@oclif/core', () => { | ||
return { | ||
...jest.requireActual('@oclif/core'), | ||
CliUx: { | ||
ux: { | ||
open: jest.fn() | ||
} | ||
} | ||
} | ||
}) | ||
const { Command, CliUx: { ux: cli } } = require('@oclif/core') | ||
|
||
let command | ||
let ORIGINAL_AIO_CLI_ENV | ||
beforeAll(() => { | ||
ORIGINAL_AIO_CLI_ENV = process.env.AIO_CLI_ENV | ||
}) | ||
beforeEach(() => { | ||
config.get.mockReset() | ||
command = new TestCommand([]) | ||
}) | ||
afterEach(() => { | ||
process.env.AIO_CLI_ENV = ORIGINAL_AIO_CLI_ENV | ||
}) | ||
|
||
test('exports', async () => { | ||
expect(typeof TestCommand).toEqual('function') | ||
expect(TestCommand.prototype instanceof Command).toBeTruthy() | ||
}) | ||
|
||
test('description', async () => { | ||
expect(TestCommand.description).toBeDefined() | ||
}) | ||
|
||
test('aliases', async () => { | ||
expect(TestCommand.aliases).toBeDefined() | ||
expect(TestCommand.aliases).toBeInstanceOf(Array) | ||
expect(TestCommand.aliases.length).toBeGreaterThan(0) | ||
}) | ||
|
||
test('flags', async () => { | ||
expect(TestCommand.flags.help.type).toBe('boolean') | ||
}) | ||
|
||
describe('console:open', () => { | ||
test('exists', async () => { | ||
expect(command.run).toBeInstanceOf(Function) | ||
}) | ||
|
||
test('should open a browser', async () => { | ||
await expect(command.run()).resolves.not.toThrowError() | ||
expect(cli.open).toHaveBeenCalledWith('https://developer.adobe.com/console/projects') | ||
}) | ||
|
||
test('should open a browser (stage_env)', async () => { | ||
process.env.AIO_CLI_ENV = STAGE_ENV | ||
await expect(command.run()).resolves.not.toThrowError() | ||
expect(cli.open).toHaveBeenCalledWith('https://developer-stage.adobe.com/console/projects') | ||
}) | ||
|
||
test('should open a browser with default view if no project/workspace selected', async () => { | ||
config.get.mockReturnValue(null) | ||
await expect(command.run()).resolves.not.toThrowError() | ||
expect(cli.open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects') | ||
}) | ||
|
||
test('should open a browser with project overview', async () => { | ||
config.get.mockReturnValue({ | ||
project: { | ||
name: 'ghActionDeploy', | ||
id: '4566206088344853970', | ||
title: 'Deploy with Github actions', | ||
description: 'see title ...', | ||
org_id: '53444' | ||
} | ||
}) | ||
await expect(command.run()).resolves.not.toThrowError() | ||
expect(cli.open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/overview') | ||
}) | ||
|
||
test('should open a browser with project workspace', async () => { | ||
config.get.mockReturnValue({ | ||
project: { | ||
name: 'ghActionDeploy', | ||
id: '4566206088344853970', | ||
title: 'Deploy with Github actions', | ||
description: 'see title ...', | ||
org_id: '53444' | ||
}, | ||
workspace: { id: '4566206088344859372', name: 'Stage' } | ||
}) | ||
await expect(command.run()).resolves.not.toThrowError() | ||
expect(cli.open).toHaveBeenLastCalledWith('https://developer.adobe.com/console/projects/53444/4566206088344853970/workspaces/4566206088344859372/details') | ||
}) | ||
}) |