Skip to content

Commit

Permalink
Merge pull request #958 from dlcs/fix/legacyModeWithMediaType
Browse files Browse the repository at this point in the history
Fix issue with legacy mode responding with an error when it should pass
  • Loading branch information
JackLewis-digirati authored Feb 13, 2025
2 parents 136175c + f14fe9e commit 6b4dcbe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/protagonist/API.Tests/Integration/ModifyAssetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,46 @@ public async Task Put_NewVideoAsset_WithImageOptimisationPolicy_Creates_Asset_Wh
asset.BatchAssets[0].Status.Should().Be(BatchAssetStatus.Waiting);
}

[Theory]
[InlineData("video-max")]
[InlineData("https://api.dlc.services/imageOptimisationPolicies/video-max")]
public async Task Put_NewVideoAsset_WithImageOptimisationPolicy_Creates_Asset_WhenLegacyEnabledAndUsingMediaType(string imageOptimisationPolicy)
{
var assetId = AssetIdGenerator.GetAssetId(LegacyModeHelpers.LegacyCustomer, LegacyModeHelpers.LegacySpace);

var hydraImageBody = $@"{{
""mediaType"": ""video/mp4"",
""origin"": ""https://example.org/{assetId.Asset}.mp4"",
""imageOptimisationPolicy"" : ""{imageOptimisationPolicy}""
}}";

A.CallTo(() =>
EngineClient.AsynchronousIngest(
A<Asset>.That.Matches(r => r.Id == assetId),
A<CancellationToken>._))
.Returns(true);

// act
var content = new StringContent(hydraImageBody, Encoding.UTF8, "application/json");
var response = await httpClient.AsCustomer(LegacyModeHelpers.LegacyCustomer).PutAsync(assetId.ToApiResourcePath(), content);

// assert
response.StatusCode.Should().Be(HttpStatusCode.Created);

var asset = dbContext.Images.Include(a => a.BatchAssets).Include(i => i.ImageDeliveryChannels)
.ThenInclude(i => i.DeliveryChannelPolicy).Single(i => i.Id == assetId);
asset.Id.Should().Be(assetId);
asset.MediaType.Should().Be("video/mp4");
asset.Family.Should().Be(AssetFamily.Timebased);
asset.ImageOptimisationPolicy.Should().BeEmpty();
asset.ThumbnailPolicy.Should().BeEmpty();
asset.ImageDeliveryChannels.Count.Should().Be(1);
asset.ImageDeliveryChannels.Should().ContainSingle(dc => dc.Channel == AssetDeliveryChannels.Timebased &&
dc.DeliveryChannelPolicy.Name == "default-video");
asset.BatchAssets.Count.Should().Be(1);
asset.BatchAssets[0].Status.Should().Be(BatchAssetStatus.Waiting);
}

[Fact]
public async Task Put_NewVideoAsset_WithImageOptimisationPolicy_Returns400_IfInvalid_AndLegacyEnabled()
{
Expand Down
4 changes: 2 additions & 2 deletions src/protagonist/API/Converters/LegacyModeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static T VerifyAndConvertToModernFormat<T>(T image, ILogger? logger = nul
return image;
}

private static DeliveryChannel[] GetDeliveryChannelsForLegacyAsset<T>(T image)
private static DeliveryChannel[]? GetDeliveryChannelsForLegacyAsset<T>(T image)
where T : Image
{
// Retrieve the name, if it is a path to a DLCS IOP/TP policy resource
Expand Down Expand Up @@ -153,7 +153,7 @@ private static DeliveryChannel[] GetDeliveryChannelsForLegacyAsset<T>(T image)
};
}

return Array.Empty<DeliveryChannel>();
return null;
}

private static string? GetPolicyValue(string? policyValue, string pathSlug)
Expand Down

0 comments on commit 6b4dcbe

Please sign in to comment.