Skip to content

Commit

Permalink
test: ut for single-org prompt message
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 27, 2024
1 parent 30c5383 commit dd286ce
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions test/commands/org/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { AuthRemover, ConfigContents, Global, Mode } from '@salesforce/core';
import { AuthRemover, ConfigContents, Global, Mode, Messages } from '@salesforce/core';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup.js';
import { expect } from 'chai';
import { Config } from '@oclif/core';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { stubPrompter } from '@salesforce/sf-plugins-core';
import Logout from '../../../src/commands/org/logout.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'logout');

interface Options {
authFiles?: string[];
'target-org'?: string;
Expand All @@ -28,12 +31,12 @@ describe('org:logout', () => {
const testOrg1 = new MockTestOrgData();
const testOrg2 = new MockTestOrgData();
const testOrg3 = new MockTestOrgData();

let promptStub: ReturnType<typeof stubPrompter>;
let authRemoverSpy: sinon.SinonSpy;

async function prepareStubs(options: Options = {}): Promise<ConfigContents> {
const authInfo = await testOrg1.getConfig();

promptStub = stubPrompter($$.SANDBOX);
authRemoverSpy = $$.SANDBOX.spy(AuthRemover.prototype, 'removeAuth');

if (!options.authInfoConfigDoesNotExist) {
Expand Down Expand Up @@ -110,12 +113,23 @@ describe('org:logout', () => {
}
});

it('should do nothing when prompt is answered with no', async () => {
await prepareStubs();
$$.SANDBOX.stub(SfCommand.prototype, 'confirm').resolves(false);
const logout = new Logout(['-o', testOrg1.username], {} as Config);
const response = await logout.run();
expect(response).to.deep.equal([]);
describe('prompts', () => {
it('shows correct prompt for single org', async () => {
await prepareStubs();
promptStub.confirm.resolves(false);
const logout = new Logout(['-o', testOrg1.username], {} as Config);
await logout.run();
expect(promptStub.confirm.args[0][0].message).to.equal(
messages.getMessage('prompt.confirm.single', [testOrg1.username])
);
});
it('should do nothing when prompt is answered with no', async () => {
await prepareStubs();
promptStub.confirm.resolves(false);
const logout = new Logout(['-o', testOrg1.username], {} as Config);
const response = await logout.run();
expect(response).to.deep.equal([]);
});
});

it('should remove auth when alias is specified', async () => {
Expand Down

0 comments on commit dd286ce

Please sign in to comment.