Skip to content

Commit 1da578d

Browse files
authored
fix: logout confirmation messages (#923)
* fix: correct logout confirmation message for single-org * test: ut for single-org prompt message
1 parent dd31ba0 commit 1da578d

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/commands/org/logout.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ const promptForOrgsToRemove = async (orgAuths: OrgAuthorization[], all: boolean)
134134
loop: true,
135135
});
136136

137-
const getOrgConfirmationMessage = (selectedOrgs: OrgAuthorization[], originalOrgCount: number): string =>
138-
selectedOrgs.length === originalOrgCount
137+
const getOrgConfirmationMessage = (selectedOrgs: OrgAuthorization[], originalOrgCount: number): string => {
138+
if (selectedOrgs.length === 1) {
139+
return messages.getMessage('prompt.confirm.single', [selectedOrgs[0].username]);
140+
}
141+
return selectedOrgs.length === originalOrgCount
139142
? messages.getMessage('prompt.confirm-all')
140143
: messages.getMessage('prompt.confirm', [selectedOrgs.length, selectedOrgs.length > 1 ? 's' : '']);
144+
};
141145

142146
/** A whole bunch of custom formatting to make the list look nicer */
143147
const buildChoices = (orgAuths: OrgAuthorization[], all: boolean): Array<Choice | Separator> => {

test/commands/org/logout.test.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

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

15+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
16+
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'logout');
17+
1518
interface Options {
1619
authFiles?: string[];
1720
'target-org'?: string;
@@ -28,12 +31,12 @@ describe('org:logout', () => {
2831
const testOrg1 = new MockTestOrgData();
2932
const testOrg2 = new MockTestOrgData();
3033
const testOrg3 = new MockTestOrgData();
31-
34+
let promptStub: ReturnType<typeof stubPrompter>;
3235
let authRemoverSpy: sinon.SinonSpy;
3336

3437
async function prepareStubs(options: Options = {}): Promise<ConfigContents> {
3538
const authInfo = await testOrg1.getConfig();
36-
39+
promptStub = stubPrompter($$.SANDBOX);
3740
authRemoverSpy = $$.SANDBOX.spy(AuthRemover.prototype, 'removeAuth');
3841

3942
if (!options.authInfoConfigDoesNotExist) {
@@ -110,12 +113,23 @@ describe('org:logout', () => {
110113
}
111114
});
112115

113-
it('should do nothing when prompt is answered with no', async () => {
114-
await prepareStubs();
115-
$$.SANDBOX.stub(SfCommand.prototype, 'confirm').resolves(false);
116-
const logout = new Logout(['-o', testOrg1.username], {} as Config);
117-
const response = await logout.run();
118-
expect(response).to.deep.equal([]);
116+
describe('prompts', () => {
117+
it('shows correct prompt for single org', async () => {
118+
await prepareStubs();
119+
promptStub.confirm.resolves(false);
120+
const logout = new Logout(['-o', testOrg1.username], {} as Config);
121+
await logout.run();
122+
expect(promptStub.confirm.args[0][0].message).to.equal(
123+
messages.getMessage('prompt.confirm.single', [testOrg1.username])
124+
);
125+
});
126+
it('should do nothing when prompt is answered with no', async () => {
127+
await prepareStubs();
128+
promptStub.confirm.resolves(false);
129+
const logout = new Logout(['-o', testOrg1.username], {} as Config);
130+
const response = await logout.run();
131+
expect(response).to.deep.equal([]);
132+
});
119133
});
120134

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

0 commit comments

Comments
 (0)