Files
ersatztv/ErsatzTV.Tests/Application/Search/GetSearchFieldCatalogHandlerTests.cs
T

64 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ErsatzTV.Application.Search.Queries;
using ErsatzTV.Core.Api.Search;
using NUnit.Framework;
using Shouldly;
namespace ErsatzTV.Tests.Application.Search;
[TestFixture]
public class GetSearchFieldCatalogHandlerTests
{
[Test]
public async Task Returns_Curated_Catalog_Without_Internal_Fields()
{
var handler = new GetSearchFieldCatalogHandler();
List<SearchFieldResponseModel> result = await handler.Handle(new GetSearchFieldCatalog(), CancellationToken.None);
result.ShouldNotBeEmpty();
result.Select(f => f.Name).ShouldNotContain("id");
result.Select(f => f.Name).ShouldNotContain("tag_full");
result.Select(f => f.Name).ShouldNotContain("library_folder_id");
}
[Test]
public async Task Every_Field_Has_A_Known_Type_And_A_Group()
{
var handler = new GetSearchFieldCatalogHandler();
string[] knownTypes = ["text", "fulltext", "number", "date", "enum"];
List<SearchFieldResponseModel> result = await handler.Handle(new GetSearchFieldCatalog(), CancellationToken.None);
foreach (SearchFieldResponseModel field in result)
{
knownTypes.ShouldContain(field.Type);
field.Group.ShouldNotBeNullOrWhiteSpace();
field.Label.ShouldNotBeNullOrWhiteSpace();
}
}
[Test]
public async Task Enum_Fields_Carry_NonEmpty_Values_And_NonEnum_Do_Not()
{
var handler = new GetSearchFieldCatalogHandler();
List<SearchFieldResponseModel> result = await handler.Handle(new GetSearchFieldCatalog(), CancellationToken.None);
foreach (SearchFieldResponseModel field in result)
{
if (field.Type == "enum")
{
field.Values.ShouldNotBeEmpty();
}
else
{
field.Values.ShouldBeEmpty();
}
}
}
}