Skip to content

Commit

Permalink
Merge pull request #864 from dlcs/develop
Browse files Browse the repository at this point in the history
Merge `develop` into `main`
  • Loading branch information
donaldgray authored Jun 12, 2024
2 parents 5e46840 + 9e07cd0 commit a639017
Show file tree
Hide file tree
Showing 30 changed files with 1,407 additions and 1,946 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ WHERE i."Family" = 'I'
AND i."NotForDelivery" = false;

-- convert timebased
INSERT INTO "ImageDeliveryChannels" ("ImageId", "Channel", "DeliveryChannelPolicyId")
SELECT i."Id",
'iiif-av',
CASE
Expand Down
78 changes: 1 addition & 77 deletions src/protagonist/API.Tests/Converters/AssetConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using API.Converters;
using API.Exceptions;
using DLCS.Core.Types;
using DLCS.HydraModel;
using DLCS.Model.Assets;
using AssetFamily = DLCS.HydraModel.AssetFamily;
using DeliveryChannelPolicy = DLCS.Model.Policies.DeliveryChannelPolicy;

namespace API.Tests.Converters;

Expand Down Expand Up @@ -106,7 +103,6 @@ public void ToDlcsModel_All_Fields_Should_Convert()
var origin = "https://example.org/origin";
var roles = new[] { "role1", "role2" };
var tags = new[] { "tag1", "tag2" };
var deliveryChannel = new[] { "iiif-av", "iiif-img" };
var mediaType = "image/jpeg";
var thumbnailPolicy = "https://dlcs.io/thumbnailPolicies/thumb100";

Expand Down Expand Up @@ -135,7 +131,6 @@ public void ToDlcsModel_All_Fields_Should_Convert()
MaxUnauthorised = 400,
MediaType = mediaType,
ThumbnailPolicy = thumbnailPolicy,
WcDeliveryChannels = deliveryChannel
};

var asset = hydraImage.ToDlcsModel(1);
Expand All @@ -159,80 +154,9 @@ public void ToDlcsModel_All_Fields_Should_Convert()
asset.Reference3.Should().Be("3");
asset.Roles.Split(',').Should().BeEquivalentTo(roles);
asset.Tags.Split(',').Should().BeEquivalentTo(tags);
asset.DeliveryChannels.Should().BeEquivalentTo(deliveryChannel);
asset.DeliveryChannels.Should().BeEmpty();
asset.MaxUnauthorised.Should().Be(400);
asset.MediaType.Should().Be(mediaType);
asset.ThumbnailPolicy.Should().Be("thumb100");
}

[Fact]
public void ToDlcsModel_ReordersDeliveryChannel()
{
// Arrange
var deliveryChannel = new[] { "iiif-img", "file", "iiif-av" };

var hydraImage = new Image
{
Id = AssetApiId,
Space = 99,
WcDeliveryChannels = deliveryChannel
};

// Act
var asset = hydraImage.ToDlcsModel(1);

// Assert
asset.DeliveryChannels.Should().BeInAscendingOrder();
}

[Fact]
public void ToHydraModel_Converts_ImageDeliveryChannels_To_WcDeliveryChannels()
{
// Arrange
var dlcsAssetId = new AssetId(0, 1, "test-asset");
var dlcsAssetUrlRoot = new UrlRoots()
{
BaseUrl = "https://api.example.com/",
ResourceRoot = "https://resource.example.com/"
};
var dlcsAsset = new Asset(dlcsAssetId)
{
Origin = "https://example-origin.com/my-image.jpeg",
ImageDeliveryChannels = new List<ImageDeliveryChannel>()
{
new()
{
Channel = "iiif-img",
DeliveryChannelPolicy = new DeliveryChannelPolicy()
{
Name = "img-policy"
}
},
new()
{
Channel = "thumbs",
DeliveryChannelPolicy = new DeliveryChannelPolicy()
{
Name = "thumbs-policy"
}
},
new()
{
Channel = "file",
DeliveryChannelPolicy = new DeliveryChannelPolicy()
{
Name = "none",
}
}
}
};
var assetPreparationResult = AssetPreparer.PrepareAssetForUpsert(null, dlcsAsset, false,
false, new []{' '});

// Act
var hydraAsset = assetPreparationResult.UpdatedAsset!.ToHydra(dlcsAssetUrlRoot, true);

// Assert
hydraAsset.WcDeliveryChannels.Should().BeEquivalentTo("iiif-img", "file");
}
}
Loading

0 comments on commit a639017

Please sign in to comment.