From f14fe9e2c84e90eca2c9c9a708556778a4646fe9 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Wed, 12 Feb 2025 17:08:13 +0000 Subject: [PATCH] Fix issue with legacy mode responding with an error when it should pass --- .../API.Tests/Integration/ModifyAssetTests.cs | 40 +++++++++++++++++++ .../API/Converters/LegacyModeConverter.cs | 4 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/protagonist/API.Tests/Integration/ModifyAssetTests.cs b/src/protagonist/API.Tests/Integration/ModifyAssetTests.cs index f88ebc12b..46fa2798d 100644 --- a/src/protagonist/API.Tests/Integration/ModifyAssetTests.cs +++ b/src/protagonist/API.Tests/Integration/ModifyAssetTests.cs @@ -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.That.Matches(r => r.Id == assetId), + A._)) + .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() { diff --git a/src/protagonist/API/Converters/LegacyModeConverter.cs b/src/protagonist/API/Converters/LegacyModeConverter.cs index 4c71e7a74..863b1e170 100644 --- a/src/protagonist/API/Converters/LegacyModeConverter.cs +++ b/src/protagonist/API/Converters/LegacyModeConverter.cs @@ -61,7 +61,7 @@ public static T VerifyAndConvertToModernFormat(T image, ILogger? logger = nul return image; } - private static DeliveryChannel[] GetDeliveryChannelsForLegacyAsset(T image) + private static DeliveryChannel[]? GetDeliveryChannelsForLegacyAsset(T image) where T : Image { // Retrieve the name, if it is a path to a DLCS IOP/TP policy resource @@ -153,7 +153,7 @@ private static DeliveryChannel[] GetDeliveryChannelsForLegacyAsset(T image) }; } - return Array.Empty(); + return null; } private static string? GetPolicyValue(string? policyValue, string pathSlug)