-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor/replace-designsystemet-components-w…
…ith-studio
- Loading branch information
Showing
41 changed files
with
619 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
backend/src/Designer/Helpers/Preview/NugetVersionHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Diagnostics.Contracts; | ||
using System.Linq; | ||
|
||
namespace Altinn.Studio.Designer.Helpers.Preview | ||
{ | ||
public static class NugetVersionHelper | ||
{ | ||
private const string MINIMUM_NUGET_VERSION = "8.0.0.0"; | ||
private const int MINIMUM_PREVIEW_NUGET_VERSION = 15; | ||
|
||
/// <summary> | ||
/// Method to get the mocked altinn nuget build from the version | ||
/// We are returnning the minimum BUILD version of the nuget package that is required for app frontend to work | ||
/// from v4 and above. | ||
/// </summary> | ||
/// <param name="version">The version of the nuget package</param> | ||
/// <returns>The minimum build version of the nuget package</returns> | ||
public static string GetMockedAltinnNugetBuildFromVersion(string version) | ||
{ | ||
|
||
string[] versionParts = version.Split('.'); | ||
if (!IsValidSemVerVersion(versionParts)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
string normalVersion = version.Split('-').First(); | ||
int[] numberVersion = [.. normalVersion.Split('.').Take(3).Select((split) => Convert.ToInt32(split))]; | ||
if (IsVersionOrBelow(numberVersion, [8, 0, 0]) && IsPreviewVersion(versionParts) && GetPreviewVersion(versionParts) < MINIMUM_PREVIEW_NUGET_VERSION) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
return MINIMUM_NUGET_VERSION; | ||
} | ||
|
||
private static bool IsValidSemVerVersion(string[] versionParts) | ||
{ | ||
return versionParts.Length >= 3 && Convert.ToInt32(versionParts[0]) >= 8; | ||
} | ||
|
||
// <exception cref="FormatException"></exception> | ||
// <exception cref="OverflowException"></exception> | ||
private static bool IsVersionOrBelow(int[] versionParts, int[] breakpoint) | ||
{ | ||
Contract.Requires(versionParts.Length == 3); | ||
Contract.Requires(breakpoint.Length == 3); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
if (versionParts[i] > breakpoint[i]) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static bool IsPreviewVersion(string[] versionParts) | ||
{ | ||
return versionParts[2].Contains("-preview") && versionParts.Length == 4; | ||
} | ||
|
||
private static int GetPreviewVersion(string[] versionParts) | ||
{ | ||
return Convert.ToInt32(versionParts[3]); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/tests/Designer.Tests/Helpers/Preview/NugetVersionHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Altinn.Studio.Designer.Helpers.Preview; | ||
using Xunit; | ||
|
||
namespace Designer.Tests.Helpers.Preview | ||
{ | ||
|
||
public class NugetVersionHelperTests | ||
{ | ||
[Fact] | ||
public void GetMockedAltinnNugetBuildFromVersion_ShouldReturnEmptyStringForVersionsBelowBreakpoint() | ||
{ | ||
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("1.1.1")); | ||
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("1.1.1-preview.150")); | ||
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("1.1.1-preview.0")); | ||
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.1.1-preview.14")); | ||
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.8.8-preview.0")); | ||
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.18.1238")); | ||
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.18.1238")); | ||
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.8.8-preview.342")); | ||
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.0.0-preview.15")); | ||
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.0.0-preview.14")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.