5
5
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
6
*/
7
7
8
- import { AuthRemover , ConfigContents , Global , Mode } from '@salesforce/core' ;
8
+ import { AuthRemover , ConfigContents , Global , Mode , Messages } from '@salesforce/core' ;
9
9
import { MockTestOrgData , TestContext } from '@salesforce/core/lib/testSetup.js' ;
10
10
import { expect } from 'chai' ;
11
11
import { Config } from '@oclif/core' ;
12
- import { SfCommand } from '@salesforce/sf-plugins-core' ;
12
+ import { stubPrompter } from '@salesforce/sf-plugins-core' ;
13
13
import Logout from '../../../src/commands/org/logout.js' ;
14
14
15
+ Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
16
+ const messages = Messages . loadMessages ( '@salesforce/plugin-auth' , 'logout' ) ;
17
+
15
18
interface Options {
16
19
authFiles ?: string [ ] ;
17
20
'target-org' ?: string ;
@@ -28,12 +31,12 @@ describe('org:logout', () => {
28
31
const testOrg1 = new MockTestOrgData ( ) ;
29
32
const testOrg2 = new MockTestOrgData ( ) ;
30
33
const testOrg3 = new MockTestOrgData ( ) ;
31
-
34
+ let promptStub : ReturnType < typeof stubPrompter > ;
32
35
let authRemoverSpy : sinon . SinonSpy ;
33
36
34
37
async function prepareStubs ( options : Options = { } ) : Promise < ConfigContents > {
35
38
const authInfo = await testOrg1 . getConfig ( ) ;
36
-
39
+ promptStub = stubPrompter ( $$ . SANDBOX ) ;
37
40
authRemoverSpy = $$ . SANDBOX . spy ( AuthRemover . prototype , 'removeAuth' ) ;
38
41
39
42
if ( ! options . authInfoConfigDoesNotExist ) {
@@ -110,12 +113,23 @@ describe('org:logout', () => {
110
113
}
111
114
} ) ;
112
115
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
+ } ) ;
119
133
} ) ;
120
134
121
135
it ( 'should remove auth when alias is specified' , async ( ) => {
0 commit comments