55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
77import * as os from 'node:os' ;
8- import * as path from 'path' ;
98import { isString , AnyJson } from '@salesforce/ts-types' ;
10- import { TestContext , MockTestOrgData } from '@salesforce/core/lib/testSetup' ;
11- import { Config } from '@oclif/core ' ;
12- import { expect } from 'chai ' ;
13- import stripAnsi = require ( 'strip-ansi' ) ;
9+ import { TestContext , MockTestOrgData , shouldThrow } from '@salesforce/core/lib/testSetup' ;
10+ import { expect , assert } from 'chai ' ;
11+ import { stubSfCommandUx } from '@salesforce/sf-plugins-core ' ;
12+ import { SfError } from '@salesforce/core' ;
1413import { SObjectList } from '../../../src/commands/sobject/list' ;
1514
1615describe ( 'force:schema:sobject:list' , ( ) => {
1716 const $$ = new TestContext ( ) ;
1817 const testOrg = new MockTestOrgData ( ) ;
19- let config : Config ;
20-
21- let stdoutSpy : sinon . SinonSpy ;
22-
23- before ( async ( ) => {
24- config = new Config ( { root : path . resolve ( __dirname , '../../..' ) } ) ;
25- await config . load ( ) ;
26- } ) ;
18+ let sfCommandUxStubs : ReturnType < typeof stubSfCommandUx > ;
2719
2820 beforeEach ( async ( ) => {
2921 await $$ . stubAuths ( testOrg ) ;
30- stdoutSpy = $$ . SANDBOX . stub ( process . stdout , 'write' ) ;
3122 $$ . SANDBOX . stub ( process . stderr , 'write' ) ;
32- } ) ;
33-
34- afterEach ( async ( ) => {
35- $$ . SANDBOX . restore ( ) ;
23+ sfCommandUxStubs = stubSfCommandUx ( $$ . SANDBOX ) ;
3624 } ) ;
3725
3826 it ( 'should log metadata types correctly' , async ( ) => {
@@ -47,14 +35,11 @@ describe('force:schema:sobject:list', () => {
4735 }
4836 return Promise . resolve ( { } ) ;
4937 } ;
50- const cmd = new SObjectList ( [ '--sobjecttypecategory' , 'all' , '-u' , 'testUser@test.com' ] , config ) ;
5138
52- // eslint-disable-next-line no-underscore-dangle
53- await cmd . _run ( ) ;
54-
55- const stdout = stdoutSpy . args . flat ( ) . join ( '' ) ;
56-
57- expect ( stdout ) . includes ( `customMDT${ os . EOL } defaultMDT` ) ;
39+ await SObjectList . run ( [ '--sobjecttypecategory' , 'all' , '-u' , 'testUser@test.com' ] ) ;
40+ expect ( sfCommandUxStubs . log . getCalls ( ) . flatMap ( ( call ) => call . args ) ) . to . deep . include (
41+ `customMDT${ os . EOL } defaultMDT`
42+ ) ;
5843 } ) ;
5944
6045 it ( 'should print the error when describeGlobal method fails' , async ( ) => {
@@ -64,15 +49,13 @@ describe('force:schema:sobject:list', () => {
6449 }
6550 return Promise . resolve ( { } ) ;
6651 } ;
67- const cmd = new SObjectList ( [ '--sobjecttypecategory' , 'all' , '-u' , 'testUser@test.com' , '--json' ] , config ) ;
68-
69- // eslint-disable-next-line no-underscore-dangle
70- await cmd . _run ( ) ;
71-
72- const jsonOutput = JSON . parse ( stripAnsi ( stdoutSpy . args . flat ( ) . join ( '' ) ) ) ;
7352
74- expect ( jsonOutput . status ) . to . equal ( 1 ) ;
75- expect ( jsonOutput . message ) . to . equal ( 'describeGlobal query failed' ) ;
53+ try {
54+ await shouldThrow ( SObjectList . run ( [ '--sobjecttypecategory' , 'all' , '-u' , 'testUser@test.com' , '--json' ] ) ) ;
55+ } catch ( e ) {
56+ assert ( e instanceof SfError ) ;
57+ expect ( e . message ) . to . equal ( 'describeGlobal query failed' ) ;
58+ }
7659 } ) ;
7760
7861 it ( 'should print the "noTypeFound" msg when no sobjects are found' , async ( ) => {
@@ -84,11 +67,8 @@ describe('force:schema:sobject:list', () => {
8467 }
8568 throw new Error ( 'Unexpected request' ) ;
8669 } ;
87- const cmd = new SObjectList ( [ '-u' , 'testUser@test.com' ] , config ) ;
70+ await SObjectList . run ( [ '-u' , 'testUser@test.com' ] ) ;
8871
89- // eslint-disable-next-line no-underscore-dangle
90- await cmd . _run ( ) ;
91- const stdout = stdoutSpy . args . flat ( ) . join ( '' ) ;
92- expect ( stdout ) . to . include ( 'No ALL objects found.\n' ) ;
72+ expect ( sfCommandUxStubs . log . getCalls ( ) . flatMap ( ( call ) => call . args ) ) . to . deep . include ( 'No ALL objects found.' ) ;
9373 } ) ;
9474} ) ;
0 commit comments