2021-01-24 11:43:05 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Jellyfin.Api.Helpers;
|
|
|
|
using Jellyfin.Data.Enums;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Tests.Helpers
|
|
|
|
{
|
2021-02-11 17:46:27 +01:00
|
|
|
public static class RequestHelpersTests
|
2021-01-24 11:43:05 +01:00
|
|
|
{
|
|
|
|
[Theory]
|
|
|
|
[MemberData(nameof(GetOrderBy_Success_TestData))]
|
2021-02-11 17:46:27 +01:00
|
|
|
public static void GetOrderBy_Success(IReadOnlyList<string> sortBy, IReadOnlyList<SortOrder> requestedSortOrder, (string, SortOrder)[] expected)
|
2021-01-24 11:43:05 +01:00
|
|
|
{
|
|
|
|
Assert.Equal(expected, RequestHelpers.GetOrderBy(sortBy, requestedSortOrder));
|
|
|
|
}
|
|
|
|
|
2021-09-11 22:31:24 +02:00
|
|
|
public static TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]> GetOrderBy_Success_TestData()
|
2021-01-24 11:43:05 +01:00
|
|
|
{
|
2021-09-11 22:31:24 +02:00
|
|
|
var data = new TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]>();
|
|
|
|
|
|
|
|
data.Add(
|
2021-01-24 11:43:05 +01:00
|
|
|
Array.Empty<string>(),
|
|
|
|
Array.Empty<SortOrder>(),
|
2021-09-11 22:31:24 +02:00
|
|
|
Array.Empty<(string, SortOrder)>());
|
|
|
|
|
|
|
|
data.Add(
|
2021-01-24 11:43:05 +01:00
|
|
|
new string[]
|
|
|
|
{
|
|
|
|
"IsFavoriteOrLiked",
|
|
|
|
"Random"
|
|
|
|
},
|
|
|
|
Array.Empty<SortOrder>(),
|
|
|
|
new (string, SortOrder)[]
|
|
|
|
{
|
|
|
|
("IsFavoriteOrLiked", SortOrder.Ascending),
|
|
|
|
("Random", SortOrder.Ascending),
|
2021-09-11 22:31:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
data.Add(
|
2021-01-24 11:43:05 +01:00
|
|
|
new string[]
|
|
|
|
{
|
|
|
|
"SortName",
|
|
|
|
"ProductionYear"
|
|
|
|
},
|
|
|
|
new SortOrder[]
|
|
|
|
{
|
|
|
|
SortOrder.Descending
|
|
|
|
},
|
|
|
|
new (string, SortOrder)[]
|
|
|
|
{
|
|
|
|
("SortName", SortOrder.Descending),
|
2021-01-24 17:55:25 +01:00
|
|
|
("ProductionYear", SortOrder.Descending),
|
2021-09-11 22:31:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
2021-01-24 11:43:05 +01:00
|
|
|
}
|
2021-02-11 17:46:27 +01:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public static void GetItemTypeStrings_Empty_Empty()
|
|
|
|
{
|
|
|
|
Assert.Empty(RequestHelpers.GetItemTypeStrings(Array.Empty<BaseItemKind>()));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public static void GetItemTypeStrings_Valid_Success()
|
|
|
|
{
|
|
|
|
BaseItemKind[] input =
|
|
|
|
{
|
|
|
|
BaseItemKind.AggregateFolder,
|
|
|
|
BaseItemKind.Audio,
|
|
|
|
BaseItemKind.BasePluginFolder,
|
|
|
|
BaseItemKind.CollectionFolder
|
|
|
|
};
|
|
|
|
|
|
|
|
string[] expected =
|
|
|
|
{
|
|
|
|
"AggregateFolder",
|
|
|
|
"Audio",
|
|
|
|
"BasePluginFolder",
|
|
|
|
"CollectionFolder"
|
|
|
|
};
|
|
|
|
|
|
|
|
var res = RequestHelpers.GetItemTypeStrings(input);
|
|
|
|
|
|
|
|
Assert.Equal(expected, res);
|
|
|
|
}
|
2021-01-24 11:43:05 +01:00
|
|
|
}
|
|
|
|
}
|