@@ -14,6 +14,15 @@ import { PackageBundleVersion } from '../../src/package/packageBundleVersion';
1414import { PackageBundleVersionCreate } from '../../src/package/packageBundleVersionCreate' ;
1515import { BundleVersionCreateOptions , BundleSObjects } from '../../src/interfaces' ;
1616
17+ // Type for accessing private methods in tests
18+ interface PackageBundleVersionCreateWithPrivates {
19+ getPackageVersion (
20+ options : BundleVersionCreateOptions ,
21+ project : SfProject ,
22+ connection : Connection
23+ ) : Promise < { MajorVersion : string ; MinorVersion : string } > ;
24+ }
25+
1726async function setupProject ( setup : ( project : SfProject ) => void = ( ) => { } ) {
1827 const project = await SfProject . resolve ( ) ;
1928
@@ -543,4 +552,210 @@ describe('PackageBundleVersion.create', () => {
543552 fs . unlinkSync ( componentsPath ) ;
544553 } ) ;
545554 } ) ;
555+
556+ describe ( 'getPackageVersion NEXT functionality' , ( ) => {
557+ it ( 'should resolve 0.NEXT to 0.2 when existing version 0.1 exists' , async ( ) => {
558+ const testBundleName = 'testBundle' ;
559+ const testBundleId = '0Ho000000000000' ;
560+
561+ // Restore the getPackageVersion stub so we can test the real method
562+ testContext . SANDBOX . restore ( ) ;
563+
564+ // Re-stub parsePackageBundleId since we still need it
565+ testContext . SANDBOX . stub (
566+ PackageBundleVersionCreate ,
567+ 'parsePackageBundleId' as keyof typeof PackageBundleVersionCreate
568+ ) . returns ( testBundleId ) ;
569+
570+ // Mock project's getSfProjectJson().getPackageBundles() to return a bundle with version "0.NEXT"
571+ testContext . SANDBOX . stub ( project . getSfProjectJson ( ) , 'getPackageBundles' ) . returns ( [
572+ {
573+ name : testBundleName ,
574+ versionName : 'ver 0.NEXT' ,
575+ versionNumber : '0.NEXT' ,
576+ } ,
577+ ] ) ;
578+
579+ // Mock connection tooling queries
580+ const queryStub = testContext . SANDBOX . stub ( connection . tooling , 'query' ) ;
581+
582+ // First query: Get bundle name from bundle ID
583+ queryStub . onFirstCall ( ) . resolves ( {
584+ totalSize : 1 ,
585+ done : true ,
586+ records : [ { BundleName : testBundleName } ] ,
587+ } ) ;
588+
589+ // Second query: Get existing bundle versions (returns version 0.1)
590+ queryStub . onSecondCall ( ) . resolves ( {
591+ totalSize : 1 ,
592+ done : true ,
593+ records : [
594+ {
595+ Id : '0Ho000000000001' ,
596+ PackageBundle : { Id : testBundleId , BundleName : testBundleName } ,
597+ VersionName : 'testBundle@0.1' ,
598+ MajorVersion : '0' ,
599+ MinorVersion : '1' ,
600+ IsReleased : true ,
601+ } ,
602+ ] ,
603+ } ) ;
604+
605+ const options : BundleVersionCreateOptions = {
606+ connection,
607+ project,
608+ PackageBundle : testBundleName ,
609+ MajorVersion : '0' ,
610+ MinorVersion : 'NEXT' ,
611+ Ancestor : null ,
612+ BundleVersionComponentsPath : '' ,
613+ } ;
614+
615+ // Call the private method through reflection for testing
616+ const result = await (
617+ PackageBundleVersionCreate as unknown as PackageBundleVersionCreateWithPrivates
618+ ) . getPackageVersion ( options , project , connection ) ;
619+
620+ expect ( result ) . to . deep . equal ( {
621+ MajorVersion : '0' ,
622+ MinorVersion : '2' ,
623+ } ) ;
624+
625+ // Verify the queries were called correctly
626+ expect ( queryStub . firstCall . args [ 0 ] ) . to . include (
627+ `SELECT BundleName FROM PackageBundle WHERE Id = '${ testBundleId } '`
628+ ) ;
629+ expect ( queryStub . secondCall . args [ 0 ] ) . to . include (
630+ `SELECT Id, PackageBundle.Id, PackageBundle.BundleName, VersionName, MajorVersion, MinorVersion, IsReleased FROM PackageBundleVersion WHERE PackageBundle.BundleName = '${ testBundleName } ' AND MajorVersion = 0 ORDER BY MinorVersion DESC LIMIT 1`
631+ ) ;
632+ } ) ;
633+
634+ it ( 'should resolve 0.NEXT to 0.0 when no existing versions exist' , async ( ) => {
635+ const testBundleName = 'newBundle' ;
636+ const testBundleId = '0Ho000000000000' ;
637+
638+ // Restore the getPackageVersion stub so we can test the real method
639+ testContext . SANDBOX . restore ( ) ;
640+
641+ // Re-stub parsePackageBundleId since we still need it
642+ testContext . SANDBOX . stub (
643+ PackageBundleVersionCreate ,
644+ 'parsePackageBundleId' as keyof typeof PackageBundleVersionCreate
645+ ) . returns ( testBundleId ) ;
646+
647+ // Mock project's getSfProjectJson().getPackageBundles() to return a bundle with version "0.NEXT"
648+ testContext . SANDBOX . stub ( project . getSfProjectJson ( ) , 'getPackageBundles' ) . returns ( [
649+ {
650+ name : testBundleName ,
651+ versionName : 'ver 0.NEXT' ,
652+ versionNumber : '0.NEXT' ,
653+ } ,
654+ ] ) ;
655+
656+ // Mock connection tooling queries
657+ const queryStub = testContext . SANDBOX . stub ( connection . tooling , 'query' ) ;
658+
659+ // First query: Get bundle name from bundle ID
660+ queryStub . onFirstCall ( ) . resolves ( {
661+ totalSize : 1 ,
662+ done : true ,
663+ records : [ { BundleName : testBundleName } ] ,
664+ } ) ;
665+
666+ // Second query: Get existing bundle versions (returns empty - no existing versions)
667+ queryStub . onSecondCall ( ) . resolves ( {
668+ totalSize : 0 ,
669+ done : true ,
670+ records : [ ] ,
671+ } ) ;
672+
673+ const options : BundleVersionCreateOptions = {
674+ connection,
675+ project,
676+ PackageBundle : testBundleName ,
677+ MajorVersion : '0' ,
678+ MinorVersion : 'NEXT' ,
679+ Ancestor : null ,
680+ BundleVersionComponentsPath : '' ,
681+ } ;
682+
683+ // Call the private method through reflection for testing
684+ const result = await (
685+ PackageBundleVersionCreate as unknown as PackageBundleVersionCreateWithPrivates
686+ ) . getPackageVersion ( options , project , connection ) ;
687+
688+ expect ( result ) . to . deep . equal ( {
689+ MajorVersion : '0' ,
690+ MinorVersion : '0' ,
691+ } ) ;
692+
693+ // Verify the queries were called correctly
694+ expect ( queryStub . firstCall . args [ 0 ] ) . to . include (
695+ `SELECT BundleName FROM PackageBundle WHERE Id = '${ testBundleId } '`
696+ ) ;
697+ expect ( queryStub . secondCall . args [ 0 ] ) . to . include (
698+ `SELECT Id, PackageBundle.Id, PackageBundle.BundleName, VersionName, MajorVersion, MinorVersion, IsReleased FROM PackageBundleVersion WHERE PackageBundle.BundleName = '${ testBundleName } ' AND MajorVersion = 0 ORDER BY MinorVersion DESC LIMIT 1`
699+ ) ;
700+ } ) ;
701+
702+ it ( 'should handle numeric minor versions without NEXT' , async ( ) => {
703+ const testBundleName = 'simpleBundle' ;
704+ const testBundleId = '0Ho000000000000' ;
705+
706+ // Restore the getPackageVersion stub so we can test the real method
707+ testContext . SANDBOX . restore ( ) ;
708+
709+ // Re-stub parsePackageBundleId since we still need it
710+ testContext . SANDBOX . stub (
711+ PackageBundleVersionCreate ,
712+ 'parsePackageBundleId' as keyof typeof PackageBundleVersionCreate
713+ ) . returns ( testBundleId ) ;
714+
715+ // Mock project's getSfProjectJson().getPackageBundles() to return a bundle with version "1.5"
716+ testContext . SANDBOX . stub ( project . getSfProjectJson ( ) , 'getPackageBundles' ) . returns ( [
717+ {
718+ name : testBundleName ,
719+ versionName : 'ver 1.5' ,
720+ versionNumber : '1.5' ,
721+ } ,
722+ ] ) ;
723+
724+ // Mock connection tooling queries
725+ const queryStub = testContext . SANDBOX . stub ( connection . tooling , 'query' ) ;
726+
727+ // First query: Get bundle name from bundle ID
728+ queryStub . onFirstCall ( ) . resolves ( {
729+ totalSize : 1 ,
730+ done : true ,
731+ records : [ { BundleName : testBundleName } ] ,
732+ } ) ;
733+
734+ const options : BundleVersionCreateOptions = {
735+ connection,
736+ project,
737+ PackageBundle : testBundleName ,
738+ MajorVersion : '1' ,
739+ MinorVersion : '5' ,
740+ Ancestor : null ,
741+ BundleVersionComponentsPath : '' ,
742+ } ;
743+
744+ // Call the private method through reflection for testing
745+ const result = await (
746+ PackageBundleVersionCreate as unknown as PackageBundleVersionCreateWithPrivates
747+ ) . getPackageVersion ( options , project , connection ) ;
748+
749+ expect ( result ) . to . deep . equal ( {
750+ MajorVersion : '1' ,
751+ MinorVersion : '5' ,
752+ } ) ;
753+
754+ // Verify only the first query was called (no need to query existing versions for numeric minor)
755+ expect ( queryStub . calledOnce ) . to . be . true ;
756+ expect ( queryStub . firstCall . args [ 0 ] ) . to . include (
757+ `SELECT BundleName FROM PackageBundle WHERE Id = '${ testBundleId } '`
758+ ) ;
759+ } ) ;
760+ } ) ;
546761} ) ;
0 commit comments