Skip to content

Commit

Permalink
fix(deps): bump @oclif/core from 3.25.2 to 3.26.0 (#994)
Browse files Browse the repository at this point in the history
* fix(deps): bump @oclif/core from 3.25.2 to 3.26.0

Bumps [@oclif/core](https://github.com/oclif/core) from 3.25.2 to 3.26.0.
- [Release notes](https://github.com/oclif/core/releases)
- [Changelog](https://github.com/oclif/core/blob/main/CHANGELOG.md)
- [Commits](oclif/core@3.25.2...3.26.0)

---
updated-dependencies:
- dependency-name: "@oclif/core"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* test: use static run for unit tests

* chore: code review

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mike Donnalley <[email protected]>
  • Loading branch information
dependabot[bot] and mdonnalley authored Apr 8, 2024
1 parent 909e257 commit f90be44
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 170 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@inquirer/checkbox": "^1.5.2",
"@inquirer/select": "^1.3.3",
"@oclif/core": "^3.25.2",
"@oclif/core": "^3.26.0",
"@salesforce/core": "^6.7.6",
"@salesforce/plugin-info": "^3.0.28",
"@salesforce/kit": "^3.1.0",
Expand Down
9 changes: 4 additions & 5 deletions test/commands/org/list/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js';
import { Config } from '@oclif/core';
import { expect } from 'chai';
import { AuthInfo } from '@salesforce/core';
import { stubUx } from '@salesforce/sf-plugins-core';
import ListAuth from '../../../../src/commands/org/list/auth.js';

describe('org:list:auth', () => {
Expand All @@ -22,12 +22,12 @@ describe('org:list:auth', () => {
if (forceFailure) {
$$.SANDBOX.stub(AuthInfo, 'create').throws(new Error('decrypt error'));
}
stubUx($$.SANDBOX);
}

it('should show auth files', async () => {
await prepareStubs();
const list = new ListAuth(['--json'], {} as Config);
const [auths] = await list.run();
const [auths] = await ListAuth.run(['--json']);
expect(auths.alias).to.deep.equal(testData.aliases?.join(',') ?? '');
expect(auths.username).to.equal(testData.username);
expect(auths.instanceUrl).to.equal(testData.instanceUrl);
Expand All @@ -37,8 +37,7 @@ describe('org:list:auth', () => {

it('should show files with auth errors', async () => {
await prepareStubs(true);
const list = new ListAuth(['--json'], {} as Config);
const [auths] = await list.run();
const [auths] = await ListAuth.run(['--json']);
expect(auths.alias).to.deep.equal(testData.aliases?.join(',') ?? '');
expect(auths.username).to.equal(testData.username);
expect(auths.instanceUrl).to.equal(testData.instanceUrl);
Expand Down
32 changes: 12 additions & 20 deletions test/commands/org/login/login.device.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js'
import { StubbedType, stubInterface, stubMethod } from '@salesforce/ts-sinon';
import { DeviceCodeResponse } from '@salesforce/core/lib/deviceOauthService.js';
import { expect } from 'chai';
import { Config } from '@oclif/core';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { SfCommand, stubUx } from '@salesforce/sf-plugins-core';
import Login from '../../../../src/commands/org/login/device.js';
interface Options {
approvalTimesout?: boolean;
Expand Down Expand Up @@ -65,42 +64,39 @@ describe('org:login:device', () => {

stubMethod($$.SANDBOX, AuthInfo, 'create').resolves(authInfoStub);
await $$.stubAuths(testData);
stubUx($$.SANDBOX);
stubMethod($$.SANDBOX, SfCommand.prototype, 'logSuccess');
}

it('should return auth fields', async () => {
await prepareStubs();
const login = new Login(['--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['--json']);
expect(response.username).to.equal(testData.username);
});

it('should return auth fields with instance url', async () => {
await prepareStubs();
const login = new Login(['-r', 'https://login.salesforce.com', '--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['-r', 'https://login.salesforce.com', '--json']);
expect(response.username).to.equal(testData.username);
});

it('should set alias when -a is provided', async () => {
await prepareStubs();
const login = new Login(['-a', 'MyAlias', '--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['-a', 'MyAlias', '--json']);
expect(response.username).to.equal(testData.username);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
});

it('should set target-org when -s is provided', async () => {
await prepareStubs();
const login = new Login(['-s', '--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['-s', '--json']);
expect(response.username).to.equal(testData.username);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
});

it('should set target-dev-hub when -d is provided', async () => {
await prepareStubs();
const login = new Login(['-d', '--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['-d', '--json']);
expect(response.username).to.equal(testData.username);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
});
Expand All @@ -109,17 +105,15 @@ describe('org:login:device', () => {
await prepareStubs();
const styledHeaderSpy = $$.SANDBOX.spy(SfCommand.prototype, 'styledHeader');
const logSpy = $$.SANDBOX.spy(SfCommand.prototype, 'log');
const login = new Login([], {} as Config);
await login.run();
await Login.run([]);
expect(styledHeaderSpy.calledOnce).to.be.true;
expect(logSpy.callCount).to.be.greaterThan(0);
});

it('should gracefully handle approval timeout', async () => {
await prepareStubs({ approvalTimesout: true });
const login = new Login(['--json'], {} as Config);
try {
const response = await login.run();
const response = await Login.run(['--json']);
expect.fail(`should have thrown: ${JSON.stringify(response)}`);
} catch (e) {
expect((e as Error).name).to.equal('polling timeout');
Expand All @@ -128,16 +122,14 @@ describe('org:login:device', () => {

it('should gracefully handle failed approval', async () => {
await prepareStubs({ approvalFails: true });
const login = new Login(['--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['--json']);
expect(response).to.deep.equal({});
});

it('should prompt for client secret if client id is provided', async () => {
await prepareStubs();
$$.SANDBOX.stub(SfCommand.prototype, 'secretPrompt').resolves('1234');
const login = new Login(['-i', 'CoffeeBeans', '--json'], {} as Config);
const response = await login.run();
const response = await Login.run(['-i', 'CoffeeBeans', '--json']);
expect(response.username).to.equal(testData.username);
});
});
98 changes: 47 additions & 51 deletions test/commands/org/login/login.jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AuthFields, AuthInfo, SfError } from '@salesforce/core';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js';
import { StubbedType, stubInterface } from '@salesforce/ts-sinon';
import { expect } from 'chai';
import { Config } from '@oclif/core';
import { stubUx } from '@salesforce/sf-plugins-core';
import LoginJwt from '../../../../src/commands/org/login/jwt.js';

interface Options {
Expand Down Expand Up @@ -49,35 +49,36 @@ describe('org:login:jwt', () => {
// @ts-ignore
$$.SANDBOX.stub(AuthInfo, 'create').resolves(authInfoStub);
}

stubUx($$.SANDBOX);
}

it('should return auth fields', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '--json'],
{} as Config
);
const response = await grant.run();
const response = await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '--json']);
expect(response.username).to.equal(testData.username);
});

it('should set alias when -a is provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-a', 'MyAlias', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-a', 'MyAlias', '--json']);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
});

it('should set target-org to alias when -s and -a are provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-a', 'MyAlias', '-s', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run([
'-u',
testData.username,
'-f',
'path/to/key.json',
'-i',
'123456',
'-a',
'MyAlias',
'-s',
'--json',
]);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
expect(authInfoStub.handleAliasAndDefaultSettings.args[0]).to.deep.equal([
{
Expand All @@ -90,11 +91,7 @@ describe('org:login:jwt', () => {

it('should set target-org to username when -s is provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-s', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-s', '--json']);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
expect(authInfoStub.handleAliasAndDefaultSettings.args[0]).to.deep.equal([
{
Expand All @@ -107,11 +104,18 @@ describe('org:login:jwt', () => {

it('should set target-dev-hub to alias when -d and -a are provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-a', 'MyAlias', '-d', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run([
'-u',
testData.username,
'-f',
'path/to/key.json',
'-i',
'123456',
'-a',
'MyAlias',
'-d',
'--json',
]);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
expect(authInfoStub.handleAliasAndDefaultSettings.args[0]).to.deep.equal([
{
Expand All @@ -124,11 +128,7 @@ describe('org:login:jwt', () => {

it('should set target-dev-hub to username when -d is provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-d', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-d', '--json']);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
expect(authInfoStub.handleAliasAndDefaultSettings.args[0]).to.deep.equal([
{
Expand All @@ -141,11 +141,7 @@ describe('org:login:jwt', () => {

it('should set target-org and target-dev-hub to username when -d and -s are provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-d', '-s', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-d', '-s', '--json']);
expect(authInfoStub.setAlias.callCount).to.equal(0);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
expect(authInfoStub.handleAliasAndDefaultSettings.args[0]).to.deep.equal([
Expand All @@ -159,11 +155,19 @@ describe('org:login:jwt', () => {

it('should set target-org and target-dev-hub to alias when -a, -d, and -s are provided', async () => {
await prepareStubs();
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '-d', '-s', '-a', 'MyAlias', '--json'],
{} as Config
);
await grant.run();
await LoginJwt.run([
'-u',
testData.username,
'-f',
'path/to/key.json',
'-i',
'123456',
'-d',
'-s',
'-a',
'MyAlias',
'--json',
]);
expect(authInfoStub.handleAliasAndDefaultSettings.callCount).to.equal(1);
expect(authInfoStub.handleAliasAndDefaultSettings.args[0]).to.deep.equal([
{
Expand All @@ -176,12 +180,8 @@ describe('org:login:jwt', () => {

it('should throw an error when client id is invalid', async () => {
await prepareStubs({ authInfoCreateFails: true });
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456INVALID', '--json'],
{} as Config
);
try {
await grant.run();
await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456INVALID', '--json']);
expect.fail('Should have thrown an error');
} catch (e) {
expect((e as Error).message).to.include('We encountered a JSON web token error');
Expand All @@ -190,12 +190,8 @@ describe('org:login:jwt', () => {

it('should not throw an error when the authorization already exists', async () => {
await prepareStubs({ existingAuth: true });
const grant = new LoginJwt(
['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '--json'],
{} as Config
);
try {
await grant.run();
await LoginJwt.run(['-u', testData.username, '-f', 'path/to/key.json', '-i', '123456', '--json']);
} catch (e) {
expect.fail('Should not have thrown an error');
}
Expand Down
Loading

0 comments on commit f90be44

Please sign in to comment.