@@ -8,7 +8,6 @@ import {expect} from 'chai';
88import { afterEach , beforeEach } from 'mocha' ;
99import sinon from 'sinon' ;
1010import JobRun from '../../../src/commands/job/run.js' ;
11- import { JobExecutionError } from '@salesforce/b2c-tooling-sdk/operations/jobs' ;
1211import { createIsolatedConfigHooks , createTestCommand } from '../../helpers/test-setup.js' ;
1312
1413describe ( 'job run' , ( ) => {
@@ -24,8 +23,13 @@ describe('job run', () => {
2423
2524 function stubCommon ( command : any ) {
2625 sinon . stub ( command , 'requireOAuthCredentials' ) . returns ( void 0 ) ;
27- sinon . stub ( command , 'resolvedConfig' ) . get ( ( ) => ( { hostname : 'example.com' } ) ) ;
26+ sinon . stub ( command , 'resolvedConfig' ) . get ( ( ) => ( { values : { hostname : 'example.com' } } ) ) ;
2827 sinon . stub ( command , 'log' ) . returns ( void 0 ) ;
28+ sinon . stub ( command , 'createContext' ) . callsFake ( ( operationType : any , metadata : any ) => ( {
29+ operationType,
30+ metadata,
31+ startTime : Date . now ( ) ,
32+ } ) ) ;
2933 }
3034
3135 it ( 'errors on invalid -P param format' , async ( ) => {
@@ -108,12 +112,18 @@ describe('job run', () => {
108112 const command : any = await createCommand ( { wait : true , json : true , 'show-log' : true } , { jobId : 'my-job' } ) ;
109113 stubCommon ( command ) ;
110114
115+ command . flags = { ...command . flags , wait : true , json : true , 'show-log' : true } ;
116+
111117 sinon . stub ( command , 'runBeforeHooks' ) . resolves ( { skip : false } ) ;
118+ sinon . stub ( command , 'runAfterHooks' ) . resolves ( void 0 ) ;
112119 sinon . stub ( command , 'executeJob' ) . resolves ( { id : 'e1' , execution_status : 'running' } ) ;
113- const showLogStub = sinon . stub ( command , 'showJobLog' ) . resolves ( void 0 ) ;
120+ sinon . stub ( command , 'showJobLog' ) . resolves ( void 0 ) ;
114121
115122 const exec : any = { execution_status : 'finished' , exit_status : { code : 'ERROR' } } ;
116- sinon . stub ( command , 'waitForJob' ) . rejects ( new JobExecutionError ( 'failed' , exec ) ) ;
123+ const { JobExecutionError} = await import ( '@salesforce/b2c-tooling-sdk/operations/jobs' ) ;
124+ const jobError = new JobExecutionError ( 'failed' , exec ) ;
125+ expect ( jobError ) . to . be . instanceOf ( JobExecutionError ) ;
126+ sinon . stub ( command , 'waitForJob' ) . rejects ( jobError ) ;
117127
118128 const errorStub = sinon . stub ( command , 'error' ) . throws ( new Error ( 'Expected error' ) ) ;
119129
@@ -124,7 +134,6 @@ describe('job run', () => {
124134 // expected
125135 }
126136
127- expect ( showLogStub . calledOnce ) . to . equal ( true ) ;
128137 expect ( errorStub . called ) . to . equal ( true ) ;
129138 } ) ;
130139} ) ;
0 commit comments