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 { unlinkSync , existsSync } from 'node:fs' ;
9+ import { join , resolve } from 'node:path' ;
810import { SourceTestkit } from '@salesforce/source-testkit' ;
911import { assert , expect } from 'chai' ;
12+ import { RequestStatus } from '@salesforce/source-deploy-retrieve' ;
1013import { DeployResultJson } from '../../../../src/utils/types' ;
1114
12- describe ( 'deploy metadata report NUTs with source -dir' , ( ) => {
15+ describe ( '[project deploy report] NUTs with metadata -dir' , ( ) => {
1316 let testkit : SourceTestkit ;
17+ const mdSourceDir = 'mdapiOut' ;
18+ const orgAlias = 'reportMdTestOrg2' ;
1419
1520 before ( async ( ) => {
1621 testkit = await SourceTestkit . create ( {
1722 repository : 'https://github.com/salesforcecli/sample-project-multiple-packages.git' ,
1823 nut : __filename ,
24+ scratchOrgs : [ { duration : 1 , alias : orgAlias , config : join ( 'config' , 'project-scratch-def.json' ) } ] ,
1925 } ) ;
2026 await testkit . convert ( {
21- args : ' --source-dir force-app --output-dir mdapiOut' ,
27+ args : ` --source-dir force-app --output-dir ${ mdSourceDir } ` ,
2228 json : true ,
2329 exitCode : 0 ,
2430 } ) ;
@@ -31,7 +37,7 @@ describe('deploy metadata report NUTs with source-dir', () => {
3137 describe ( '--use-most-recent' , ( ) => {
3238 it ( 'should report most recently started deployment' , async ( ) => {
3339 await testkit . execute < DeployResultJson > ( 'project deploy start' , {
34- args : ' --metadata-dir mdapiOut --async' ,
40+ args : ` --metadata-dir ${ mdSourceDir } --async` ,
3541 json : true ,
3642 exitCode : 0 ,
3743 } ) ;
@@ -42,40 +48,49 @@ describe('deploy metadata report NUTs with source-dir', () => {
4248 exitCode : 0 ,
4349 } ) ;
4450 assert ( deploy ?. result ) ;
45- expect ( deploy . result . success ) . to . equal ( true ) ;
51+ expect ( [ RequestStatus . Pending , RequestStatus . Succeeded , RequestStatus . InProgress ] ) . includes ( deploy . result . status ) ;
4652 } ) ;
53+ } ) ;
4754
48- it . skip ( 'should report most recently started deployment without specifying the flag' , async ( ) => {
49- await testkit . execute < DeployResultJson > ( 'project deploy start' , {
50- args : '--metadata-dir mdapiOut --async' ,
55+ describe ( '--job-id' , ( ) => {
56+ it ( 'should report the provided job id' , async ( ) => {
57+ const first = await testkit . execute < DeployResultJson > ( 'project deploy start' , {
58+ args : `--metadata-dir ${ mdSourceDir } --async` ,
5159 json : true ,
5260 exitCode : 0 ,
5361 } ) ;
54-
5562 const deploy = await testkit . execute < DeployResultJson > ( 'project deploy report' , {
63+ args : `--job-id ${ first ?. result . id } ` ,
5664 json : true ,
5765 exitCode : 0 ,
5866 } ) ;
5967 assert ( deploy ?. result ) ;
60- expect ( deploy . result . success ) . to . equal ( true ) ;
68+ expect ( [ RequestStatus . Pending , RequestStatus . Succeeded , RequestStatus . InProgress ] ) . includes ( deploy . result . status ) ;
69+ expect ( deploy . result . id ) . to . equal ( first ?. result . id ) ;
6170 } ) ;
62- } ) ;
6371
64- describe ( '--job-id' , ( ) => {
65- it ( 'should report the provided job id' , async ( ) => {
72+ it ( 'should report from specified target-org and job-id without deploy cache' , async ( ) => {
6673 const first = await testkit . execute < DeployResultJson > ( 'project deploy start' , {
67- args : ' --metadata-dir mdapiOut --async' ,
74+ args : ` --metadata-dir ${ mdSourceDir } --async --target-org ${ orgAlias } ` ,
6875 json : true ,
6976 exitCode : 0 ,
7077 } ) ;
78+
79+ // delete the cache file so we can verify that reporting just with job-id and org works
80+ const deployCacheFilePath = resolve ( testkit . projectDir , join ( '..' , '.sf' , 'deploy-cache.json' ) ) ;
81+ unlinkSync ( deployCacheFilePath ) ;
82+ assert ( ! existsSync ( deployCacheFilePath ) ) ;
83+
7184 const deploy = await testkit . execute < DeployResultJson > ( 'project deploy report' , {
72- args : `--job-id ${ first ?. result . id } ` ,
85+ args : `--job-id ${ first ?. result . id } --target-org ${ orgAlias } --wait 9 ` ,
7386 json : true ,
7487 exitCode : 0 ,
7588 } ) ;
7689 assert ( deploy ?. result ) ;
7790 expect ( deploy . result . success ) . to . equal ( true ) ;
91+ expect ( deploy . result . status ) . to . equal ( RequestStatus . Succeeded ) ;
7892 expect ( deploy . result . id ) . to . equal ( first ?. result . id ) ;
93+ await testkit . expect . filesToBeDeployed ( [ 'force-app/**/*' ] , [ 'force-app/test/**/*' ] ) ;
7994 } ) ;
8095 } ) ;
8196} ) ;
0 commit comments