@@ -374,3 +374,113 @@ Describe "Set-VersionInSettingsFile tests" {
374
374
Remove-Item $settingsFile - Force - ErrorAction Ignore
375
375
}
376
376
}
377
+
378
+ Describe ' Set-VersionInAppManifests tests' {
379
+ BeforeAll {
380
+ . (Join-Path - Path $PSScriptRoot - ChildPath " ..\Actions\AL-Go-Helper.ps1" - Resolve)
381
+ Import-Module (Join-Path - Path $PSScriptRoot - ChildPath " ..\Actions\IncrementVersionNumber\IncrementVersionNumber.psm1" - Resolve) - Force
382
+ }
383
+
384
+ BeforeEach {
385
+ $testProjectPath = Join-Path ([System.IO.Path ]::GetTempPath()) " TestProject"
386
+ New-Item - ItemType Directory - Path $testProjectPath - Force | Out-Null
387
+
388
+ # Create mock app folders for TestProject
389
+ $appFolders = @ (' App1' , ' App2' , ' Test1' , ' BCPTTest1' )
390
+ foreach ($folder in $appFolders ) {
391
+ New-Item - ItemType Directory - Path (Join-Path $testProjectPath $folder ) - Force | Out-Null
392
+ New-Item - ItemType File - Path (Join-Path $testProjectPath $folder ' app.json' ) - Force | Out-Null
393
+ $appJsonContent = @ {
394
+ " version" = " 0.1"
395
+ " name" = $folder
396
+ }
397
+ $appJsonContent | ConvertTo-Json | Set-Content (Join-Path $testProjectPath $folder ' app.json' ) - Encoding UTF8
398
+ }
399
+
400
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUseDeclaredVarsMoreThanAssignments' , ' testProjectSettings' , Justification = ' False positive.' )]
401
+ $testProjectSettings = @ {
402
+ appFolders = @ ($appFolders [0 .. 1 ]) # App1, App2
403
+ testFolders = @ ($appFolders [2 ]) # Test1
404
+ bcptTestFolders = @ ($appFolders [3 ]) # BCPTTest1
405
+ }
406
+
407
+ # Create another project folder that points to the same app folders
408
+ $anotherTestProjectPath = Join-Path ([System.IO.Path ]::GetTempPath()) " AnotherTestProject"
409
+ New-Item - ItemType Directory - Path $anotherTestProjectPath - Force | Out-Null
410
+
411
+ Push-Location $anotherTestProjectPath
412
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUseDeclaredVarsMoreThanAssignments' , ' anotherTestProjectSettings' , Justification = ' False positive.' )]
413
+ $anotherTestProjectSettings = @ {
414
+ appFolders = @ ($appFolders [0 .. 1 ]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_ ) - Relative } # App1, App2
415
+ testFolders = @ ($appFolders [2 ]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_ ) - Relative } # Test1
416
+ bcptTestFolders = @ ($appFolders [3 ]) | ForEach-Object { Resolve-Path (Join-Path $testProjectPath $_ ) - Relative } # BCPTTest1
417
+ }
418
+
419
+ $anotherTestProjectAppFolder = ' Another TestProjectApp'
420
+ New-Item - ItemType Directory - Path (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder ) - Force | Out-Null
421
+ New-Item - ItemType File - Path (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder ' app.json' ) - Force | Out-Null
422
+ $anotherTestProjectAppJsonContent = @ {
423
+ " version" = " 0.2"
424
+ " name" = $anotherTestProjectAppFolder
425
+ }
426
+ $anotherTestProjectAppJsonContent | ConvertTo-Json | Set-Content (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder ' app.json' ) - Encoding UTF8
427
+
428
+ Pop-Location
429
+ }
430
+
431
+ It ' Set-VersionInAppManifests updates all app.json files once and increments the version' {
432
+ $updatedAppFolders = @ ()
433
+ $testProjectSettings = @ {
434
+ versioningStrategy = 0
435
+ appFolders = @ (' App1' , ' App2' )
436
+ testFolders = @ (' Test1' )
437
+ bcptTestFolders = @ (' BCPTTest1' )
438
+ }
439
+
440
+ Set-VersionInAppManifests - projectPath $testProjectPath - projectSettings $testProjectSettings - newValue ' +0.1' - updatedAppFolders ([ref ] $updatedAppFolders )
441
+
442
+ $updatedAppFolders.Count | Should - Be 4
443
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' App1' - Resolve)
444
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' App2' - Resolve)
445
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' Test1' - Resolve)
446
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' BCPTTest1' - Resolve)
447
+
448
+ Set-VersionInAppManifests - projectPath $anotherTestProjectPath - projectSettings $anotherTestProjectSettings - newValue ' +0.1' - updatedAppFolders ([ref ] $updatedAppFolders )
449
+
450
+ $updatedAppFolders.Count | Should - Be 4
451
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' App1' - Resolve)
452
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' App2' - Resolve)
453
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' Test1' - Resolve)
454
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' BCPTTest1' - Resolve)
455
+
456
+ # Add the new app folder to the settings for anotherTestProject
457
+ $anotherTestProjectSettings.appFolders += @ ($anotherTestProjectAppFolder )
458
+
459
+ Set-VersionInAppManifests - projectPath $anotherTestProjectPath - projectSettings $anotherTestProjectSettings - newValue ' +0.1' - updatedAppFolders ([ref ] $updatedAppFolders )
460
+ $updatedAppFolders.Count | Should - Be 5
461
+ $updatedAppFolders | Should - Contain (Join-Path $anotherTestProjectPath $anotherTestProjectAppFolder - Resolve)
462
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' App1' - Resolve)
463
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' App2' - Resolve)
464
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' Test1' - Resolve)
465
+ $updatedAppFolders | Should - Contain (Join-Path $testProjectPath ' BCPTTest1' - Resolve)
466
+
467
+ # Verify the app.json files have been updated only once and the version is incremented
468
+ $appJsonFiles = Get-ChildItem - Path $testProjectPath - Recurse - Filter ' app.json'
469
+ $appJsonFiles | ForEach-Object {
470
+ $appJsonContent = Get-Content $_.FullName - Encoding UTF8 | ConvertFrom-Json
471
+ $appJsonContent.version | Should - Be " 0.2" # 0.1 + 0.1
472
+ }
473
+
474
+ $anotherAppJsonFiles = Get-ChildItem - Path $anotherTestProjectPath - Recurse - Filter ' app.json'
475
+ $anotherAppJsonFiles | ForEach-Object {
476
+ $appJsonContent = Get-Content $_.FullName - Encoding UTF8 | ConvertFrom-Json
477
+ $appJsonContent.version | Should - Be " 0.3" # 0.2 + 0.1
478
+ }
479
+ }
480
+
481
+ AfterEach {
482
+ # Clean up the projects directory
483
+ Remove-Item - Path $testProjectPath - Recurse - Force - ErrorAction Ignore
484
+ Remove-Item - Path $anotherTestProjectPath - Recurse - Force - ErrorAction Ignore
485
+ }
486
+ }
0 commit comments