Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and implement new hierarchy table #96

Merged
merged 11 commits into from
Oct 18, 2024
122 changes: 89 additions & 33 deletions src/IIIFPresentation/API.Tests/Converters/CollectionConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using API.Converters;
using API.Features.Storage.Models;
using FluentAssertions;
using IIIF.Presentation.V3.Strings;
using Models.Database.Collections;
using Models.Database.General;

#nullable disable

Expand All @@ -20,7 +23,23 @@ public class CollectionConverterTests
public void ToHierarchicalCollection_ConvertsStorageCollection()
{
// Arrange
var storageRoot = CreateTestStorageRoot();
var storageRoot = new Collection
{
Id = "some-id",
CustomerId = 1,
Label = new LanguageMap
{
{ "en", new List<string> { "repository root" } }
},
Created = DateTime.MinValue,
Modified = DateTime.MinValue,
Hierarchy = [
new Hierarchy()
{
Slug = "root"
}
]
};

// Act
var hierarchicalCollection =
Expand Down Expand Up @@ -54,11 +73,32 @@ public void ToHierarchicalCollection_ConvertsStorageCollectionWithFullPath()
public void ToFlatCollection_ConvertsStorageCollection()
{
// Arrange
var storageRoot = CreateTestStorageRoot();
var collection = new Collection
{
Id = "some-id",
CustomerId = 1,
Label = new LanguageMap
{
{ "en", new List<string> { "repository root" } }
},
Created = DateTime.MinValue,
Modified = DateTime.MinValue,
Hierarchy = [
new Hierarchy()
{
CollectionId = "some-id",
Slug = "root",
CustomerId = 1,
Type = ResourceType.StorageCollection,
Canonical = true
}
]

};

// Act
var flatCollection =
storageRoot.ToFlatCollection(urlRoots, pageSize, 1, 1, new List<Collection>(CreateTestItems()));
collection.ToFlatCollection(urlRoots, pageSize, 1, 1, [..CreateTestItems()]);

// Assert
flatCollection.Id.Should().Be("http://base/1/collections/some-id");
Expand All @@ -83,7 +123,7 @@ public void ToFlatCollection_ConvertsStorageCollection()
public void ToFlatCollection_ConvertsStorageCollection_WithFullPath()
{
// Arrange
var storageRoot = CreateTestCollection();
var storageRoot = CreateTestHierarchicalCollection();

// Act
var flatCollection =
Expand All @@ -109,17 +149,17 @@ public void ToFlatCollection_ConvertsStorageCollection_WithFullPath()
flatCollection.View.First.Should().BeNull();
flatCollection.View.Next.Should().BeNull();
}

[Fact]
public void ToFlatCollection_ConvertsStorageCollection_WithCorrectPaging()
{
// Arrange
var storageRoot = CreateTestCollection();
var storageRoot = CreateTestHierarchicalCollection();

// Act
var flatCollection =
storageRoot.ToFlatCollection(urlRoots, 1, 2, 3,
new List<Collection>(CreateTestItems()), "orderBy=created");
storageRoot.ToFlatCollection(urlRoots, 1, 2, 3,
[..CreateTestItems()], "orderBy=created");

// Assert
flatCollection.Id.Should().Be("http://base/1/collections/some-id");
Expand All @@ -143,24 +183,6 @@ public void ToFlatCollection_ConvertsStorageCollection_WithCorrectPaging()
flatCollection.TotalItems.Should().Be(3);
}

private static Collection CreateTestStorageRoot()
{
var storageRoot = new Collection()
{
Id = "some-id",
CustomerId = 1,
Slug = "root",
Label = new LanguageMap
{
{ "en", new List<string> { "repository root" } }
},
Created = DateTime.MinValue,
Modified = DateTime.MinValue
};

return storageRoot;
}

private static List<Collection> CreateTestItems()
{
var items = new List<Collection>()
Expand All @@ -169,38 +191,72 @@ private static List<Collection> CreateTestItems()
{
Id = "some-child",
CustomerId = 1,
Slug = "some-child",
Label = new LanguageMap
{
{ "en", new List<string> { "repository root" } }
},
Created = DateTime.MinValue,
Modified = DateTime.MinValue,
Parent = "some-id",
FullPath = "top/some-child"
FullPath = "top/some-child",
Hierarchy = [
new Hierarchy()
{
CollectionId = "some-child",
Slug = "root",
CustomerId = 1,
Type = ResourceType.StorageCollection
}
]
}
};

return items;
}

private static Collection CreateTestHierarchicalCollection()
{
var collection = new Collection
{
Id = "some-id",
CustomerId = 1,
Label = new LanguageMap
{
{ "en", new List<string> { "repository root" } }
},
Created = DateTime.MinValue,
Modified = DateTime.MinValue,
FullPath = "top/some-id",
Hierarchy = [
new Hierarchy()
{
CollectionId = "some-id",
Slug = "root",
Parent = "top",
CustomerId = 1,
Type = ResourceType.StorageCollection,
Canonical = true
}
]
};

return collection;
}

private static Collection CreateTestCollection()
{
var storageRoot = new Collection
var collection = new Collection
{
Id = "some-id",
CustomerId = 1,
Slug = "root",
Label = new LanguageMap
{
{ "en", new List<string> { "repository root" } }
},
Created = DateTime.MinValue,
Modified = DateTime.MinValue,
Parent = "top",
FullPath = "top/some-id"
};

return storageRoot;
return collection;
}
}
30 changes: 16 additions & 14 deletions src/IIIFPresentation/API.Tests/Helpers/CollectionHelperXTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using API.Converters;
using API.Helpers;
using Models.Database.Collections;
using Models.Database.General;

namespace API.Tests.Helpers;

Expand All @@ -17,10 +18,10 @@ public class CollectionHelperXTests
public void GenerateHierarchicalCollectionId_CreatesIdWhenNoFullPath()
{
// Arrange
var collection = new Collection()
var collection = new Collection
{
Id = "test",
Slug = "slug",
Hierarchy = GetDefaultHierarchyList()
};

// Act
Expand All @@ -34,10 +35,10 @@ public void GenerateHierarchicalCollectionId_CreatesIdWhenNoFullPath()
public void GenerateHierarchicalCollectionId_CreatesIdWhenFullPath()
{
// Arrange
var collection = new Collection()
var collection = new Collection
{
Id = "test",
Slug = "slug",
Hierarchy = GetDefaultHierarchyList(),
FullPath = "top/test"
};

Expand All @@ -52,10 +53,10 @@ public void GenerateHierarchicalCollectionId_CreatesIdWhenFullPath()
public void GenerateFlatCollectionId_CreatesId()
{
// Arrange
var collection = new Collection()
var collection = new Collection
{
Id = "test",
Slug = "slug"
Hierarchy = GetDefaultHierarchyList()
};

// Act
Expand All @@ -69,15 +70,14 @@ public void GenerateFlatCollectionId_CreatesId()
public void GenerateFlatCollectionParent_CreatesParentId()
{
// Arrange
var collection = new Collection()
var hierarchy = new Hierarchy
{
Id = "test",
Slug = "slug",
Parent = "parent"
};

// Act
var id = collection.GenerateFlatCollectionParent(urlRoots);
var id = hierarchy.GenerateFlatCollectionParent(urlRoots);

// Assert
id.Should().Be("http://base/0/collections/parent");
Expand All @@ -87,10 +87,10 @@ public void GenerateFlatCollectionParent_CreatesParentId()
public void GenerateFlatCollectionViewId_CreatesViewId()
{
// Arrange
var collection = new Collection()
var collection = new Collection
{
Id = "test",
Slug = "slug"
Hierarchy = GetDefaultHierarchyList()
};

// Act
Expand All @@ -104,10 +104,10 @@ public void GenerateFlatCollectionViewId_CreatesViewId()
public void GenerateFlatCollectionViewNext_CreatesViewNext()
{
// Arrange
var collection = new Collection()
var collection = new Collection
{
Id = "test",
Slug = "slug"
Hierarchy = GetDefaultHierarchyList()
};

// Act
Expand All @@ -124,7 +124,7 @@ public void GenerateFlatCollectionViewLast_CreatesViewLast()
var collection = new Collection()
{
Id = "test",
Slug = "slug"
Hierarchy = GetDefaultHierarchyList()
};

// Act
Expand All @@ -133,4 +133,6 @@ public void GenerateFlatCollectionViewLast_CreatesViewLast()
// Assert
id.Should().Be("http://base/0/collections/test?page=1&pageSize=10&test");
}

private static List<Hierarchy> GetDefaultHierarchyList() => [ new() { Slug = "slug" } ];
}
Loading
Loading