diff --git a/messages/display.md b/messages/display.md index 7e837200..8ef080a2 100644 --- a/messages/display.md +++ b/messages/display.md @@ -6,21 +6,11 @@ Display details about an environment. Specify an environment with either the username you used when you logged into the environment with "sf login", or the alias you gave the environment when you created it. Run "sf env list" to view all your environments and their aliases. -Output depends on the type of environment. For example, scratch org details include the access token, alias, username of the associated Dev Hub, the creation and expiration date, the generated scratch org username, and more. Compute environment details include the alias, connected orgs, creation date, project name, and more. +Output depends on the type of environment. # examples -- Display details about a scratch org with alias my-scratch-org: - - <%= config.bin %> <%= command.id %> --target-env=my-scratch-org - -- Specify a username instead of an alias: - - <%= config.bin %> <%= command.id %> --target-env=test-123456-abcdefg@example.com - -- Specify JSON format and redirect output into a file: - - <%= config.bin %> <%= command.id %> --target-env=my-scratch-org --json > tmp/MyOrdDesc.json +- <%- config.bin %> <%- command.id %> --target-env myEnv # flags.target-env.summary @@ -34,6 +24,6 @@ No results found. No environment found for %s. -# error.NoDefaultEnv +# warning.orgsNoLongerSupported -No default environment found. Use -e or --target-env to specify an environment to display. +This command only displays functions environments. Use "%s org display" to display an org. diff --git a/messages/list.md b/messages/list.md index 72d90699..e37f0ee6 100644 --- a/messages/list.md +++ b/messages/list.md @@ -4,11 +4,9 @@ List the environments you’ve created or logged into. # description -By default, the command displays active environments. For orgs, active means unexpired scratch orgs and orgs you’re currently logged into. +By default, the command displays active environments. -Output is displayed in multiple tables, one for each environment type. For example, the Salesforce Orgs table lists the non-scratch orgs you’re logged into, such as sandboxes, Dev Hubs, production orgs, and so on. Scratch orgs and compute environments get their own tables. - -The two org tables show similar information, such as aliases, information about the org, and how you authorized (logged into) it, such as with a web browser or JWT. The scratch org table also shows the expiration date. For non-scratch orgs, the Username column refers to the user you logged into the org with. For scratch orgs it refers to the username that was generated for you when you created the scratch org. Your default scratch org or Dev Hub org is indicated with the "target-org" or "target-dev-hub" configuration variable, respectively, in the Config column. +Output is displayed in multiple tables, one for each environment type. The compute environment table shows the alias, information about the connected orgs, the project name, and more. @@ -26,14 +24,6 @@ Run "sf env display" to view details about a specific environment. <%= config.bin %> <%= command.id %> --all -- Filter the output to list only orgs you authorized using a web browser; "Auth Method" is the name of a column: - - <%= config.bin %> <%= command.id %> --filter "Auth Method=web" - -- Display only the Aliases column and sort the aliases in descending order: - - <%= config.bin %> <%= command.id %> --sort "-Aliases" --columns "Aliases" - - Don't truncate the displayed output and instead wrap text that's wider than your terminal: <%= config.bin %> <%= command.id %> --no-truncate @@ -74,10 +64,6 @@ Format in which to display the output. Column to sort by (prepend '-' for descending). -# error.NoAuthsAvailable - -No authenticated environments found. Log in or create an environment, and then try again. - # error.NoResultsFound No results found. @@ -85,3 +71,7 @@ No results found. # warning.RequestedColumnsNotPresentInEnvironment The columns you specified (%s) aren't available in the table for environment "%s". + +# warning.orgsNoLongerSupported + +This command only lists functions environments. Use "%s org list" to list orgs. diff --git a/messages/open.md b/messages/open.md index ca145060..e966e1db 100644 --- a/messages/open.md +++ b/messages/open.md @@ -4,23 +4,21 @@ Open an environment in a web browser. # description -You can open the following types of environments in a web browser: scratch orgs, sandboxes, Dev Hubs, and production orgs. Run "sf env list" to view your environments and their aliases and login usernames. - -Each of your environments is associated with an instance URL, such as https://login.salesforce.com. To open a specific web page, specify the portion of the URL after "/" with the --path flag, such as /apex/YourPage to open a Visualforce page. +Each of your environments is associated with an instance URL, such as https://login.salesforce.com. To open a specific web page, specify the portion of the URL after "/" with the --path flag. # examples -- Open the Visualforce page /apex/StartHere in a scratch org with alias test-org: +- Open the compute environment with alias "test-compute": - <%= config.bin %> <%= command.id %> --target-env test-org --path /apex/StartHere + <%= config.bin %> <%= command.id %> --target-env test-compute - View the URL but don't launch it in a browser: - <%= config.bin %> <%= command.id %> --target-env test-org --path /apex/StartHere --url-only + <%= config.bin %> <%= command.id %> --target-env test-compute --url-only - Open the environment in the Google Chrome browser: - <%= config.bin %> <%= command.id %> --target-env test-org --path /apex/StartHere --browser chrome + <%= config.bin %> <%= command.id %> --target-env test-compute --url-only --browser chrome # flags.path.summary @@ -34,12 +32,6 @@ Display the URL, but don’t launch it in a browser. Login user or alias of the environment to open. -# flags.target-env.description - -Specify the login user or alias that’s associated with the environment. For scratch orgs, the login user is generated by the command that created the scratch org. You can also set an alias for the scratch org when you create it. - -For Dev Hubs, sandboxes, and production orgs, specify the alias you set when you logged into the org with "sf login". - # flags.browser.summary Browser in which to open the environment. @@ -63,3 +55,7 @@ The environment %s doesn't support being opened. # error.ApplicationNotFound Can't find application named %s. + +# warning.orgsNoLongerSupported + +This command only opens a function's environment. Use "%s org open" to open an org. diff --git a/package.json b/package.json index 7a773c2f..285de73e 100644 --- a/package.json +++ b/package.json @@ -71,10 +71,6 @@ "commands": "./lib/commands", "bin": "sf", "topicSeparator": " ", - "hooks": { - "sf:env:display": "./lib/hooks/envDisplay", - "sf:env:list": "./lib/hooks/envList" - }, "devPlugins": [ "@oclif/plugin-help", "@oclif/plugin-command-snapshot", @@ -114,4 +110,4 @@ "access": "public" }, "main": "lib/index.js" -} \ No newline at end of file +} diff --git a/schemas/hooks/sf-env-display.json b/schemas/hooks/sf-env-display.json deleted file mode 100644 index a668c1a0..00000000 --- a/schemas/hooks/sf-env-display.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/OrgAuthorization", - "definitions": { - "OrgAuthorization": { - "type": "object", - "properties": { - "orgId": { - "type": "string" - }, - "username": { - "type": "string" - }, - "oauthMethod": { - "type": "string", - "enum": [ - "jwt", - "web", - "token", - "unknown" - ] - }, - "aliases": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "null" - } - ] - }, - "configs": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "null" - } - ] - }, - "isScratchOrg": { - "type": "boolean" - }, - "isDevHub": { - "type": "boolean" - }, - "isSandbox": { - "type": "boolean" - }, - "instanceUrl": { - "type": "string" - }, - "accessToken": { - "type": "string" - }, - "error": { - "type": "string" - }, - "isExpired": { - "anyOf": [ - { - "type": "boolean" - }, - { - "type": "string", - "const": "unknown" - } - ] - } - }, - "required": [ - "orgId", - "username", - "oauthMethod", - "isExpired" - ], - "additionalProperties": false - } - } -} \ No newline at end of file diff --git a/schemas/hooks/sf-env-list.json b/schemas/hooks/sf-env-list.json deleted file mode 100644 index 099bba59..00000000 --- a/schemas/hooks/sf-env-list.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/SalesforceOrg", - "definitions": { - "SalesforceOrg": { - "type": "object", - "properties": { - "aliases": { - "type": "array", - "items": { - "type": "string" - } - }, - "username": { - "type": "string" - }, - "orgId": { - "type": "string" - }, - "instanceUrl": { - "type": "string" - }, - "oauthMethod": { - "type": "string" - }, - "configs": { - "type": "array", - "items": { - "type": "string" - } - }, - "error": { - "type": "string" - } - }, - "required": [ - "aliases", - "username", - "orgId", - "instanceUrl", - "oauthMethod", - "configs" - ], - "additionalProperties": false - } - } -} \ No newline at end of file diff --git a/src/commands/env/display.ts b/src/commands/env/display.ts index f62a75db..54b86234 100644 --- a/src/commands/env/display.ts +++ b/src/commands/env/display.ts @@ -24,20 +24,16 @@ export default class EnvDisplay extends SfCommand { }; public async run(): Promise { + this.warn(messages.getMessage('warning.orgsNoLongerSupported', [this.config.bin])); const { flags } = await this.parse(EnvDisplay); - // TODO: access this from ConfigAggregator once target-env config var is supported. - const targetEnv = flags['target-env']; - - if (!targetEnv) throw messages.createError('error.NoDefaultEnv'); - let data: JsonObject = {}; try { - const results = await SfHook.run(this.config, 'sf:env:display', { targetEnv }); + const results = await SfHook.run(this.config, 'sf:env:display', { targetEnv: flags['target-env'] }); const result = results.successes.find((s) => !!s.result?.data)?.result || null; if (!result) { - throw messages.createError('error.NoEnvFound', [targetEnv]); + throw messages.createError('error.NoEnvFound', [flags['target-env']]); } data = result.data; diff --git a/src/commands/env/list.ts b/src/commands/env/list.ts index e514531f..03827ff9 100644 --- a/src/commands/env/list.ts +++ b/src/commands/env/list.ts @@ -15,13 +15,6 @@ const messages = Messages.loadMessages('@salesforce/plugin-env', 'list'); const envTypeValues = Object.keys(Env.EnvType); const envOrderBy = (a: Env.Table, b: Env.Table): number => { - // both a && b are well known - if (envTypeValues.includes(a.type) && envTypeValues.includes(a.type)) { - if (a.type === Env.EnvType.salesforceOrgs && b.type !== Env.EnvType.salesforceOrgs) return -1; - if (a.type !== Env.EnvType.salesforceOrgs && b.type === Env.EnvType.salesforceOrgs) return 1; - if (a.type === Env.EnvType.scratchOrgs && b.type !== Env.EnvType.scratchOrgs) return -1; - return 1; - } // both a && b are user defined - use natural sort if (!envTypeValues.includes(a.type) && !envTypeValues.includes(a.type)) { return a.type.localeCompare(b.type); @@ -82,6 +75,7 @@ export default class EnvList extends SfCommand { private flags!: Interfaces.InferredFlags; public async run(): Promise { + this.warn(messages.getMessage('warning.orgsNoLongerSupported', [this.config.bin])); this.flags = (await this.parse(EnvList)).flags; const tableOpts = { columns: this.flags.columns?.join(','), diff --git a/src/commands/env/open.ts b/src/commands/env/open.ts index 494c69be..e2a60ba3 100644 --- a/src/commands/env/open.ts +++ b/src/commands/env/open.ts @@ -33,7 +33,6 @@ export default class EnvOpen extends SfCommand { 'target-env': Flags.string({ char: 'e', summary: messages.getMessage('flags.target-env.summary'), - description: messages.getMessage('flags.target-env.description'), }), browser: Flags.string({ summary: messages.getMessage('flags.browser.summary'), @@ -42,6 +41,7 @@ export default class EnvOpen extends SfCommand { }; public async run(): Promise { + this.warn(messages.getMessage('warning.orgsNoLongerSupported', [this.config.bin])); const { flags } = await this.parse(EnvOpen); const nameOrAlias = flags['target-env']; let url: string; @@ -53,6 +53,7 @@ export default class EnvOpen extends SfCommand { try { const org = await Org.create({ aliasOrUsername: nameOrAlias }); + // eslint-disable-next-line sf-plugin/get-connection-with-version const conn = org.getConnection(); await org.refreshAuth(); const authInfo = conn.getAuthInfo(); diff --git a/src/hooks/envDisplay.ts b/src/hooks/envDisplay.ts deleted file mode 100644 index 2cbd8acc..00000000 --- a/src/hooks/envDisplay.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2021, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { AuthInfo, OrgAuthorization } from '@salesforce/core'; -import { SfHook } from '@salesforce/sf-plugins-core'; - -const hook: SfHook.EnvDisplay = async function (opts) { - const orgs = await AuthInfo.listAllAuthorizations(); - const data = - orgs.find((org) => org.username === opts.targetEnv) ?? orgs.find((org) => org.aliases?.includes(opts.targetEnv)); - if (data) delete data['timestamp']; - return { - data, - keys: { orgId: 'Org ID', oauthMethod: 'Auth Method' }, - }; -}; - -export default hook; diff --git a/src/hooks/envList.ts b/src/hooks/envList.ts deleted file mode 100644 index dbdf733c..00000000 --- a/src/hooks/envList.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2021, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { AuthInfo, Messages, OrgAuthorization } from '@salesforce/core'; -import { SfHook, EnvList } from '@salesforce/sf-plugins-core'; - -Messages.importMessagesDirectory(__dirname); -const messages = Messages.loadMessages('@salesforce/plugin-env', 'list'); - -export type SalesforceOrg = { - aliases: string[]; - username: string; - orgId: string; - instanceUrl: string; - oauthMethod: string; - configs: string[]; - error?: string; -}; - -function extractData(orgs: OrgAuthorization[]): SalesforceOrg[] { - return orgs.map((org) => { - const base: SalesforceOrg = { - aliases: org.aliases, - username: org.username, - orgId: org.orgId, - instanceUrl: org.instanceUrl, - oauthMethod: org.oauthMethod, - configs: org.configs, - }; - if (org.error) base.error = org.error || ''; - return base; - }); -} - -export const KEYS = { - orgId: 'Org ID', - oauthMethod: 'Auth Method', - configs: 'Config', -}; - -const hook: SfHook.EnvList = async function (opts) { - if (!(await AuthInfo.hasAuthentications())) throw messages.createError('error.NoAuthsAvailable'); - - const orgs = opts.all - ? await AuthInfo.listAllAuthorizations() - : await AuthInfo.listAllAuthorizations((org) => org.isExpired !== true); - - const grouped = { - nonScratchOrgs: [] as OrgAuthorization[], - scratchOrgs: [] as OrgAuthorization[], - }; - for (const org of orgs) { - if (org.isScratchOrg) grouped.scratchOrgs.push(org); - else grouped.nonScratchOrgs.push(org); - } - - const salesforceOrgs = { - type: EnvList.EnvType.salesforceOrgs, - title: 'Salesforce Orgs', - data: extractData(grouped.nonScratchOrgs), - keys: KEYS, - }; - - const scratchOrgs = { - type: EnvList.EnvType.scratchOrgs, - title: 'Scratch Orgs', - data: extractData(grouped.scratchOrgs), - keys: KEYS, - }; - - return [salesforceOrgs, scratchOrgs]; -}; - -export default hook; diff --git a/test/commands/env/display.nut.ts b/test/commands/env/display.nut.ts deleted file mode 100644 index 04f2f258..00000000 --- a/test/commands/env/display.nut.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; -import { expect } from 'chai'; - -describe('env display NUTs', () => { - let session: TestSession; - - before(async () => { - session = await TestSession.create({ devhubAuthStrategy: 'AUTO' }); - }); - - after(async () => { - await session?.clean(); - }); - - it('should display dev hub', () => { - const command = `env display --target-env ${session.hubOrg.username}`; - const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; - expect(output).to.contain(session.hubOrg.username); - }); -}); diff --git a/test/commands/env/display.test.ts b/test/commands/env/display.test.ts deleted file mode 100644 index 4f6f984e..00000000 --- a/test/commands/env/display.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2020, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { expect, test } from '@oclif/test'; -import { OrgAuthorization } from '@salesforce/core'; -import { SfHook } from '@salesforce/sf-plugins-core'; - -const ORG = { - orgId: '00Dxx12345678912345', - accessToken: '00Dxx12345678912345!fdkjlfsakjlsafdjldijafsjklsdfjklafdsjkl', - instanceUrl: 'https://some.salesforce.com', - oauthMethod: 'jwt', - username: 'some-user@some.salesforce.com', - aliases: ['MyOrg'], - config: ['target-org'], -}; - -describe('display unit tests', () => { - test - .stub(SfHook, 'run', async () => ({ successes: [{ result: { data: ORG } }], failures: [] })) - .stdout() - .command(['env:display', '--target-env', ORG.username, '--json']) - .it('should display requested username with json output', (ctx) => { - const actual = JSON.parse(ctx.stdout) as { result: OrgAuthorization }; - expect(actual.result).to.be.deep.equal(ORG); - }); - - test - .stub(SfHook, 'run', async () => ({ successes: [{ result: { data: ORG } }], failures: [] })) - .stdout() - .command(['env:display', '--target-env', ORG.username, '--json']) - .it('should display requested username with human output', (ctx) => { - expect(ctx.stdout).to.include(ORG.orgId); - expect(ctx.stdout).to.include(ORG.username); - expect(ctx.stdout).to.include(ORG.oauthMethod); - expect(ctx.stdout).to.include(ORG.instanceUrl); - expect(ctx.stdout).to.not.include('timestamp'); - }); - - test - .stub(SfHook, 'run', async () => ({ successes: [{ result: { data: ORG } }], failures: [] })) - .stdout() - .command(['env:display', '--target-env', ORG.aliases[0], '--json']) - .it('should display requested alias with json output', (ctx) => { - const actual = JSON.parse(ctx.stdout) as { result: OrgAuthorization }; - expect(actual.result).to.be.deep.equal(ORG); - }); - - test - .stub(SfHook, 'run', async () => ({ successes: [{ result: { data: ORG } }], failures: [] })) - .stdout() - .command(['env:display', '--target-env', ORG.aliases[0], '--json']) - .it('should display requested alias with human output', (ctx) => { - expect(ctx.stdout).to.include(ORG.orgId); - expect(ctx.stdout).to.include(ORG.username); - expect(ctx.stdout).to.include(ORG.oauthMethod); - expect(ctx.stdout).to.include(ORG.instanceUrl); - expect(ctx.stdout).to.not.include('timestamp'); - }); - - test - .stdout() - .stderr() - .command(['env:display']) - .it('should throw error if --target-env is not specified', (ctx) => { - expect(ctx.stderr).to.to.include( - 'No default environment found. Use -e or --target-env to specify an environment to display.' - ); - }); -}); diff --git a/test/commands/env/list.nut.ts b/test/commands/env/list.nut.ts deleted file mode 100644 index 9f9a5700..00000000 --- a/test/commands/env/list.nut.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; -import { expect } from 'chai'; - -describe('env list NUTs', () => { - let session: TestSession; - before(async () => { - session = await TestSession.create({ devhubAuthStrategy: 'AUTO' }); - }); - - after(async () => { - await session?.clean(); - }); - - it('should list dev hub', () => { - const command = 'env list'; - const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; - expect(output).to.contain(session.hubOrg.username); - }); -}); diff --git a/test/commands/env/list.test.ts b/test/commands/env/list.test.ts deleted file mode 100644 index 471cab22..00000000 --- a/test/commands/env/list.test.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2020, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ -import { expect, test } from '@oclif/test'; -import { SfHook } from '@salesforce/sf-plugins-core'; -import { KEYS, SalesforceOrg } from '../../../src/hooks/envList'; -import { Environments } from '../../../lib/commands/env/list'; - -const expectedSfOrgs: SalesforceOrg[] = [ - { - orgId: '00Dxx12345678912345', - instanceUrl: 'https://some.salesforce.com', - aliases: ['someAlias'], - oauthMethod: 'jwt', - username: 'some-user@some.salesforce.com', - configs: [], - }, - { - orgId: '00Dxx54321987654321', - instanceUrl: 'https://some.other.salesforce.com', - aliases: ['someOtherAlias'], - oauthMethod: 'web', - username: 'some-other-user@some.other.salesforce.com', - error: 'some auth error', - configs: [], - }, -]; - -const expectedEnvironments: Environments = { - salesforceOrgs: expectedSfOrgs, -}; -const makeTableObj = (title: string, data: SalesforceOrg[]) => ({ type: 'salesforceOrgs', title, data, keys: KEYS }); - -describe('list unit tests', () => { - test - .stub(SfHook, 'run', async () => ({ - successes: [{ result: makeTableObj('Salesforce Orgs', expectedSfOrgs) }], - failures: [], - })) - .stdout() - .command(['env:list', '--json']) - .it('should list active orgs with json output', (ctx) => { - const sfOrgs = JSON.parse(ctx.stdout) as { result: Environments }; - expect(sfOrgs.result).to.be.deep.equal(expectedEnvironments); - }); - - test - .stub(SfHook, 'run', async () => ({ - successes: [{ result: makeTableObj('Salesforce Orgs', expectedSfOrgs) }], - failures: [], - })) - .stdout() - .command(['env:list']) - .it('should list active orgs with human output', (ctx) => { - const stdout = ctx.stdout; - expect(stdout).to.be.ok; - expectedSfOrgs.forEach((sfOrg) => { - expect(stdout).to.include(sfOrg.aliases[0]); - expect(stdout).to.include(sfOrg.orgId); - expect(stdout).to.include(sfOrg.username); - expect(stdout).to.include(sfOrg.oauthMethod); - expect(stdout).to.include(sfOrg.instanceUrl); - }); - }); - - test - .stub(SfHook, 'run', async () => ({ - successes: [{ result: makeTableObj('Salesforce Orgs', expectedSfOrgs) }], - failures: [], - })) - .stdout() - .command(['env:list', '--columns', 'Org Id', '--columns', 'Username']) - .it('should list active orgs with human output and display selected columns', (ctx) => { - const stdout = ctx.stdout; - expect(stdout).to.be.ok; - ['Org ID', 'Username'].forEach((columnName) => expect(stdout).to.include(columnName)); - ['Aliases', 'Instance URL', 'Auth Method', 'Config'].forEach((columnName) => - expect(stdout).to.not.include(columnName) - ); - expectedSfOrgs.forEach((sfOrg) => { - expect(stdout).to.not.include(sfOrg.aliases[0]); - expect(stdout).to.include(sfOrg.orgId); - expect(stdout).to.include(sfOrg.username); - expect(stdout).to.not.include(sfOrg.oauthMethod); - expect(stdout).to.not.include(sfOrg.instanceUrl); - }); - }); - - test - .stub(SfHook, 'run', async () => ({ - successes: [{ result: makeTableObj('Salesforce Orgs', expectedSfOrgs) }], - failures: [], - })) - .stdout() - .command(['env:list', '--filter', 'aliases=someAlias']) - .it('should fetch active orgs with human output and filtered data', (ctx) => { - const stdout = ctx.stdout; - expect(stdout).to.be.ok; - expect(stdout).to.include('someAlias'); - expect(stdout).to.not.include('someOtherAlias'); - }); - - test - .stub(SfHook, 'run', async () => ({ - successes: [{ result: makeTableObj('Salesforce Orgs', expectedSfOrgs) }], - failures: [], - })) - .stdout() - .command(['env:list', '--sort', '-aliases']) - .it('should fetch active orgs with human output and sorted results', (ctx) => { - const stdout = ctx.stdout.replace(/\n/g, ''); - expect(stdout).to.be.ok; - expect(stdout).to.match(/.*?someOtherAlias.*?someAlias.*/g); - }); -}); diff --git a/test/hooks/envDisplay.test.ts b/test/hooks/envDisplay.test.ts deleted file mode 100644 index 38be60bd..00000000 --- a/test/hooks/envDisplay.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2020, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { expect } from 'chai'; -import { AuthInfo, OrgAuthorization } from '@salesforce/core'; -import * as sinon from 'sinon'; -import hook from '../../src/hooks/envDisplay'; - -const ORGS = [ - { - orgId: '00Dxx12345678912345', - accessToken: '00Dxx12345678912345!fdkjlfsakjlsafdjldijafsjklsdfjklafdsjkl', - instanceUrl: 'https://some.salesforce.com', - oauthMethod: 'jwt', - username: 'some-user@some.salesforce.com', - aliases: [], - }, - { - orgId: '00Dxx54321987654321', - accessToken: '00Dxx54321987654321!lasfdlkjasfdljkerwklj;afsdlkjdhk;f', - instanceUrl: 'https://some.other.salesforce.com', - aliases: ['someOtherAlias'], - oauthMethod: 'web', - username: 'some-other-user@some.other.salesforce.com', - error: 'some auth error', - }, -]; - -describe('envDisplay hook', () => { - let sandbox: sinon.SinonSandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should return a salesforce org by username', async () => { - sandbox.stub(AuthInfo, 'listAllAuthorizations').resolves(ORGS as OrgAuthorization[]); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = await hook({ targetEnv: 'some-user@some.salesforce.com' }); - expect(result.data).to.deep.equal(ORGS[0]); - }); - - it('should return a salesforce org by alias', async () => { - sandbox.stub(AuthInfo, 'listAllAuthorizations').resolves(ORGS as OrgAuthorization[]); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = await hook({ targetEnv: 'someOtherAlias' }); - expect(result.data).to.deep.equal(ORGS[1]); - }); -}); diff --git a/test/hooks/envList.test.ts b/test/hooks/envList.test.ts deleted file mode 100644 index 4da69673..00000000 --- a/test/hooks/envList.test.ts +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2020, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { expect } from 'chai'; -import { AuthInfo, OrgAuthorization } from '@salesforce/core'; -import * as sinon from 'sinon'; -import hook, { KEYS } from '../../src/hooks/envList'; - -const ORGS = [ - { - orgId: '00Dxx12345678912345', - accessToken: '00Dxx12345678912345!fdkjlfsakjlsafdjldijafsjklsdfjklafdsjkl', - instanceUrl: 'https://some.salesforce.com', - oauthMethod: 'jwt', - username: 'some-user@some.salesforce.com', - aliases: [], - configs: [], - }, - { - orgId: '00Dxx54321987654321', - accessToken: '00Dxx54321987654321!lasfdlkjasfdljkerwklj;afsdlkjdhk;f', - instanceUrl: 'https://some.other.salesforce.com', - aliases: ['someOtherAlias'], - oauthMethod: 'web', - username: 'some-other-user@some.other.salesforce.com', - error: 'some auth error', - configs: [], - }, - { - orgId: '00Dxx54321987654327', - accessToken: '00Dxx54321987654321!lasfdlkjasfdljkerwklj;afsdlkjdhk;f', - instanceUrl: 'https://some.other.scratch.salesforce.com', - aliases: ['MyScratch'], - oauthMethod: 'web', - username: 'some-other-scratch@some.other.salesforce.com', - isScratchOrg: true, - configs: [], - }, - { - orgId: '00Dxx54321987654327', - accessToken: '00Dxx54321987654321!lasfdlkjasfdljkerwklj;afsdlkjdhk;f', - instanceUrl: 'https://some.other.scratch.salesforce.com', - oauthMethod: 'web', - username: 'some-other-scratch@some.other.salesforce.com', - isScratchOrg: true, - isExpired: true, - configs: [], - aliases: [], - }, -]; - -const EXPECTED_ORGS = [ - { - orgId: '00Dxx12345678912345', - instanceUrl: 'https://some.salesforce.com', - oauthMethod: 'jwt', - username: 'some-user@some.salesforce.com', - aliases: [], - configs: [], - }, - { - orgId: '00Dxx54321987654321', - instanceUrl: 'https://some.other.salesforce.com', - aliases: ['someOtherAlias'], - oauthMethod: 'web', - username: 'some-other-user@some.other.salesforce.com', - error: 'some auth error', - configs: [], - }, - { - orgId: '00Dxx54321987654327', - instanceUrl: 'https://some.other.scratch.salesforce.com', - aliases: ['MyScratch'], - oauthMethod: 'web', - username: 'some-other-scratch@some.other.salesforce.com', - configs: [], - }, - { - orgId: '00Dxx54321987654327', - instanceUrl: 'https://some.other.scratch.salesforce.com', - aliases: [], - oauthMethod: 'web', - username: 'some-other-scratch@some.other.salesforce.com', - configs: [], - }, -]; - -describe('envList hook', () => { - let sandbox: sinon.SinonSandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should return non-expired salesforce orgs', async () => { - sandbox.stub(AuthInfo, 'hasAuthentications').resolves(true); - sandbox.stub(AuthInfo, 'listAllAuthorizations').resolves(ORGS.slice(0, 3) as OrgAuthorization[]); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = await hook({ all: false }); - expect(result).to.deep.equal([ - { - type: 'salesforceOrgs', - title: 'Salesforce Orgs', - data: EXPECTED_ORGS.slice(0, 2), - keys: KEYS, - }, - { - type: 'scratchOrgs', - title: 'Scratch Orgs', - data: [EXPECTED_ORGS[2]], - keys: KEYS, - }, - ]); - }); - - it('should return all salesforce orgs', async () => { - sandbox.stub(AuthInfo, 'hasAuthentications').resolves(true); - sandbox.stub(AuthInfo, 'listAllAuthorizations').resolves(ORGS as OrgAuthorization[]); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const result = await hook({ all: true }); - expect(result).to.deep.equal([ - { - type: 'salesforceOrgs', - title: 'Salesforce Orgs', - data: EXPECTED_ORGS.slice(0, 2), - keys: KEYS, - }, - { - type: 'scratchOrgs', - title: 'Scratch Orgs', - data: EXPECTED_ORGS.slice(2), - keys: KEYS, - }, - ]); - }); -});