Skip to content

Commit

Permalink
Add Fails_WhenOriginNotSpecified test
Browse files Browse the repository at this point in the history
  • Loading branch information
griffri committed Jun 4, 2024
1 parent 5807d3b commit 1afb383
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions src/protagonist/API.Tests/Converters/LegacyModeConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class LegacyModeConverterTests
public void VerifyAndConvertToModernFormat_ChangesNothing_WithNewFormat()
{
// Arrange
var hydraImage = new Image{ MediaType = "type", MaxUnauthorised = 5, Family = AssetFamily.File};
var hydraImage = new Image{ MediaType = "type", Origin = "https://example.org/my-asset",
MaxUnauthorised = 5, Family = AssetFamily.File };

// Act
var convertedImage = LegacyModeConverter.VerifyAndConvertToModernFormat(hydraImage);
Expand All @@ -24,11 +25,31 @@ public void VerifyAndConvertToModernFormat_ChangesNothing_WithNewFormat()
convertedImage.Family.Should().Be(hydraImage.Family);
}

[Fact]
public void VerifyAndConvertToModernFormat_Fails_WhenOriginNotSpecified()
{
// Arrange
var hydraImage = new Image()
{
Family = AssetFamily.Timebased
};

// Act
Action action = () =>
LegacyModeConverter.VerifyAndConvertToModernFormat(hydraImage);

// Assert
action.Should()
.ThrowExactly<APIException>()
.WithMessage("An origin is required when legacy mode is enabled");
}

[Fact]
public void VerifyAndConvertToModernFormat_SetsMediaType_WithNotSet()
{
// Arrange
var hydraImage = new Image{ MaxUnauthorised = 5, Family = AssetFamily.File};
var hydraImage = new Image{ MaxUnauthorised = 5, Family = AssetFamily.File,
Origin = "https://example.org/my-asset"};

// Act
var convertedImage = LegacyModeConverter.VerifyAndConvertToModernFormat(hydraImage);
Expand Down Expand Up @@ -103,7 +124,8 @@ public void VerifyAndConvertToModernFormat_MaxUnauthorisedUnchanged_WhenRolesSet
public void VerifyAndConvertToModernFormat_ModelIdSet_WhenNoModelId()
{
// Arrange
var hydraImage = new Image{ Id = "https://test/someId", MediaType = "something"};
var hydraImage = new Image{ Id = "https://test/someId", MediaType = "something",
Origin = "https://example.org/my-asset" };

// Act
var convertedImage = LegacyModeConverter.VerifyAndConvertToModernFormat(hydraImage);
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/API/Converters/LegacyModeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static T VerifyAndConvertToModernFormat<T>(T image)
{
if (image.Origin is null)
{
throw new APIException($"An origin is required when legacy mode is enabled")
throw new APIException("An origin is required when legacy mode is enabled")
{
StatusCode = 400
};
Expand Down

0 comments on commit 1afb383

Please sign in to comment.