Skip to content

Commit

Permalink
Returned Manifest.Parent is always flat id
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldgray committed Oct 24, 2024
1 parent 489fe79 commit e77646f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void SetGeneratedFields_SetsParentAndSlug_FromSingleHierarchyByDefault()

// Assert
result.Slug.Should().Be("hierarchy-slug");
result.Parent.Should().Be("hierarchy-parent");
result.Parent.Should().Be("/0/collections/hierarchy-parent", "Always use FlatId");
}

[Fact]
Expand Down Expand Up @@ -137,6 +137,6 @@ public void SetGeneratedFields_SetsParentAndSlug_FromHierarchyUsingFactory()

// Assert
result.Slug.Should().Be("other-slug");
result.Parent.Should().Be("other-parent");
result.Parent.Should().Be("/0/collections/other-parent", "Always use FlatId");
}
}
21 changes: 2 additions & 19 deletions src/IIIFPresentation/API.Tests/Helpers/CollectionHelperXTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public void GenerateFlatId_Correct_Manifest()
[Theory]
[InlineData(ResourceType.StorageCollection)]
[InlineData(ResourceType.IIIFCollection)]
public void GenerateFlatParentId_Correct_Collection(ResourceType resourceType)
[InlineData(ResourceType.IIIFManifest)]
public void GenerateFlatParentId_Correct(ResourceType resourceType)
{
// Arrange
var hierarchy = new Hierarchy
Expand All @@ -156,24 +157,6 @@ public void GenerateFlatParentId_Correct_Collection(ResourceType resourceType)
id.Should().Be("http://base/0/collections/parent");
}

[Fact]
public void GenerateFlatParentId_Correct_Manifest()
{
// Arrange
var hierarchy = new Hierarchy
{
Slug = "slug",
Parent = "parent",
Type = ResourceType.IIIFManifest
};

// Act
var id = hierarchy.GenerateFlatParentId(urlRoots);

// Assert
id.Should().Be("http://base/0/manifests/parent");
}

[Fact]
public void GenerateFlatCollectionViewId_CreatesViewId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public async Task CreateManifest_CreatesManifest_ParentIsValidHierarchicalUrl()
responseManifest.Modified.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(2));
responseManifest.CreatedBy.Should().Be("Admin");
responseManifest.Slug.Should().Be(slug);
responseManifest.Parent.Should().Be(RootCollection.Id);
responseManifest.Parent.Should().Be($"http://localhost/1/collections/{RootCollection.Id}");
}

[Fact]
Expand Down Expand Up @@ -343,7 +343,7 @@ public async Task CreateManifest_ReturnsManifest()
responseManifest.Modified.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(2));
responseManifest.CreatedBy.Should().Be("Admin");
responseManifest.Slug.Should().Be(slug);
responseManifest.Parent.Should().Be(RootCollection.Id);
responseManifest.Parent.Should().Be($"http://localhost/1/collections/{RootCollection.Id}");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/IIIFPresentation/API/Converters/ManifestConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static PresentationManifest SetGeneratedFields(this PresentationManifest
iiifManifest.Modified = dbManifest.Modified.Floor(DateTimeX.Precision.Second);
iiifManifest.CreatedBy = dbManifest.CreatedBy;
iiifManifest.ModifiedBy = dbManifest.ModifiedBy;
iiifManifest.Parent = hierarchy.Parent;
iiifManifest.Parent = hierarchy.GenerateFlatParentId(urlRoots);
iiifManifest.Slug = hierarchy.Slug;
iiifManifest.EnsurePresentation3Context();
iiifManifest.EnsureContext(PresentationJsonLdContext.Context);
Expand Down
4 changes: 2 additions & 2 deletions src/IIIFPresentation/API/Helpers/CollectionHelperX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public static string GenerateFlatId(this Hierarchy hierarchy, UrlRoots urlRoots)
$"{urlRoots.BaseUrl}/{hierarchy.CustomerId}/{hierarchy.Type.GetSlug()}/{hierarchy.ResourceId}";

/// <summary>
/// Get flat id for hierarchy parent
/// Get flat id for parent of <see cref="Hierarchy"/>
/// </summary>
public static string GenerateFlatParentId(this Hierarchy hierarchy, UrlRoots urlRoots) =>
$"{urlRoots.BaseUrl}/{hierarchy.CustomerId}/{hierarchy.Type.GetSlug()}/{hierarchy.Parent}";
$"{urlRoots.BaseUrl}/{hierarchy.CustomerId}/{CollectionsSlug}/{hierarchy.Parent}";

public static string GenerateFlatCollectionViewId(this Collection collection, UrlRoots urlRoots,
int currentPage, int pageSize, string? orderQueryParam) =>
Expand Down

0 comments on commit e77646f

Please sign in to comment.