Skip to content

Commit

Permalink
fix: iot package changing html config.json with wrong version
Browse files Browse the repository at this point in the history
fixes #202
  • Loading branch information
joaoopereira authored and m-s- committed Sep 23, 2022
1 parent a1c0a2a commit 74fe8e8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PresentationPackageTypeHandler : PackageTypeHandler
/// Generates the presentation configuration file.
/// </summary>
/// <param name="packageOutputDir">The package output dir.</param>
private void GeneratePresentationConfigFile(IDirectoryInfo packageOutputDir)
public void GeneratePresentationConfigFile(IDirectoryInfo packageOutputDir)
{
Log.Debug("Generating Presentation config.json");
string path = $"{packageOutputDir.FullName}/{CliConstants.CmfPackagePresentationConfig}";
Expand Down Expand Up @@ -124,7 +124,7 @@ private void GeneratePresentationConfigFile(IDirectoryInfo packageOutputDir)
}
}

#endregion
#endregion Private Methods

#region Public Methods

Expand Down Expand Up @@ -223,6 +223,6 @@ public override void Pack(IDirectoryInfo packageOutputDir, IDirectoryInfo output
base.Pack(packageOutputDir, outputDir);
}

#endregion
#endregion Public Methods
}
}
3 changes: 1 addition & 2 deletions cmf-cli/resources/templateFiles/IoT/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"@jdt.value": [ $(packagesToAdd) ]
}
],
"cacheId": "$(Product.Presentation.CacheToken)",
"customizationVersion": "$(version)"
"cacheId": "$(Product.Presentation.CacheToken)"
}
95 changes: 86 additions & 9 deletions tests/Specs/Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
using Cmf.Common.Cli.TestUtilities;
using FluentAssertions;
using tests.Objects;
using Cmf.CLI.Constants;
using Cmf.CLI.Factories;
using Newtonsoft.Json;

namespace tests.Specs
{
Expand Down Expand Up @@ -178,7 +181,7 @@ public void HTML()
}
}
}

[Fact(Skip = "No System.IO.Abstractions support for searching outside the current directory")]
public void HTML_OnlyLBOs()
{
Expand Down Expand Up @@ -217,30 +220,31 @@ public void HTML_OnlyLBOs()
public void CheckThatContentWasPacked_FailBecauseNoContentFound()
{
var fileSystem = MockPackage.Html_MissingDeclaredContent;

var packCommand = new PackCommand(fileSystem);
var exception = Assert.Throws<CliException>(() => packCommand.Execute(fileSystem.DirectoryInfo.FromDirectoryName(MockUnixSupport.Path("c:\\ui")), fileSystem.DirectoryInfo.FromDirectoryName("output"), false));
exception.Message.Should().Contain("Nothing was found on ContentToPack Sources");
}

[Fact]
public void DontCheckThatContentWasPacked_IfMeta()
{
var fileSystem = MockPackage.Root_Empty;

var packCommand = new PackCommand(fileSystem);
packCommand.Execute(fileSystem.DirectoryInfo.FromDirectoryName(MockUnixSupport.Path("c:\\repo")), fileSystem.DirectoryInfo.FromDirectoryName("output"), false);
}

[Fact]
public void DontCheckThatContentWasPacked_IfContentToPackIsEmpty()
{
var fileSystem = MockPackage.Html_EmptyContentToPack;

var packCommand = new PackCommand(fileSystem);
var exception = Assert.Throws<CliException>(() => packCommand.Execute(fileSystem.DirectoryInfo.FromDirectoryName(MockUnixSupport.Path("c:\\ui")), fileSystem.DirectoryInfo.FromDirectoryName("output"), false));
exception.Message.Should().Contain("Missing mandatory property ContentToPack in file");
}

[Fact]
public void Pack_SecurityPortal()
{
Expand Down Expand Up @@ -275,8 +279,8 @@ public void Pack_SecurityPortal()
}

[Theory]
[InlineData("8.1.0", new [] { StepType.DeployRepositoryFiles, StepType.GenerateRepositoryIndex })]
[InlineData("9.1.0", new StepType[0] )]
[InlineData("8.1.0", new[] { StepType.DeployRepositoryFiles, StepType.GenerateRepositoryIndex })]
[InlineData("9.1.0", new StepType[0])]
public void IoTDFStepsForVersion(string version, StepType[] forbiddenStepTypes)
{
var mockFS = new MockFileSystem(new Dictionary<string, MockFileData>
Expand All @@ -293,13 +297,86 @@ public void IoTDFStepsForVersion(string version, StepType[] forbiddenStepTypes)
""contentToPack"": [{{}}]
}}")
}});

var pkg = CmfPackage.Load(mockFS.FileSystem.FileInfo.FromFileName(MockUnixSupport.Path(@"c:\.pkg.json")), true,
mockFS);
var _ = new IoTPackageTypeHandler(pkg);

pkg.Steps.Any(step => forbiddenStepTypes.ToList().Contains(step.Type ?? StepType.Generic)).Should()
.BeFalse();
}

[Theory]
[InlineData("Html", "1.1.0")]
[InlineData("IoT", null)]
public void GeneratePresentationConfigFile(string packageType, string version)
{
KeyValuePair<string, string> packageRoot = new("Cmf.Custom.Package", "1.1.0");

var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
// project config file
{ ".project-config.json", new MockFileData(
@$"{{
""MESVersion"": ""9.0.0""
}}")},

// root cmfpackage file
{ $"cmfpackage.json", new MockFileData(
@$"{{
""packageId"": ""{packageRoot.Key}"",
""version"": ""{packageRoot.Value}"",
""description"": ""This package deploys Critical Manufacturing Customization"",
""packageType"": ""Root"",
""isInstallable"": true,
""isUniqueInstall"": false,
""dependencies"": [
{{ ""id"": ""Cmf.Environment"", ""version"": ""0.0.0"" }}
]
}}")},

// cmfpackage file
{ $"Cmf.Custom.{packageType}/cmfpackage.json", new MockFileData(
$@"{{
""packageId"": ""Cmf.Custom.{packageType}"",
""version"": ""{version}"",
""description"": ""Cmf Custom {packageType} Package"",
""packageType"": ""{packageType}"",
""isInstallable"": true,
""isUniqueInstall"": false,
""contentToPack"": [
{{
""source"": ""{MockUnixSupport.Path("src\\packages\\*").Replace("\\", "\\\\")}"",
""target"": ""node_modules"",
""ignoreFiles"": [
"".npmignore""
]
}}
]
}}")},

// js package
{ $"Cmf.Custom.{packageType}/src/packages/customization.common/package.json", new MockFileData(@"{""name"": ""customization.package""}")},
{ $"Cmf.Custom.{packageType}/src/packages/customization.common/customization.common.js", new MockFileData("")},
{ $"Cmf.Custom.{packageType}/package.json", new MockFileData(@"{""name"": ""customization.package""}")},

// output dir
{ $"output", new MockDirectoryData() },
});

ExecutionContext.Initialize(fileSystem);

IFileInfo cmfpackageFile = fileSystem.FileInfo.FromFileName($"Cmf.Custom.{packageType}/cmfpackage.json");
PresentationPackageTypeHandler packageTypeHandler = PackageTypeFactory.GetPackageTypeHandler(cmfpackageFile, true) as PresentationPackageTypeHandler;

packageTypeHandler.GeneratePresentationConfigFile(fileSystem.DirectoryInfo.FromDirectoryName("output"));

IFileInfo configJsonFile = fileSystem.FileInfo.FromFileName(MockUnixSupport.Path(@"output\\config.json").Replace("\\", "\\\\"));
dynamic configJsonFileContent = JsonConvert.DeserializeObject(fileSystem.File.ReadAllText(configJsonFile.FullName));

string customizationVersion = configJsonFileContent.customizationVersion?.ToString();

customizationVersion.Should().Be(version);
}
}
}

0 comments on commit 74fe8e8

Please sign in to comment.