aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Api.Tests/Helpers/RequestHelpersTests.cs
blob: 4ba7e1d2ff665d0051e1aa415d01c393f7779dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using Jellyfin.Api.Helpers;
using Jellyfin.Data.Enums;
using Xunit;

namespace Jellyfin.Api.Tests.Helpers
{
    public static class RequestHelpersTests
    {
        [Theory]
        [MemberData(nameof(GetOrderBy_Success_TestData))]
        public static void GetOrderBy_Success(IReadOnlyList<string> sortBy, IReadOnlyList<SortOrder> requestedSortOrder, (string, SortOrder)[] expected)
        {
            Assert.Equal(expected, RequestHelpers.GetOrderBy(sortBy, requestedSortOrder));
        }

        public static TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]> GetOrderBy_Success_TestData()
        {
            var data = new TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]>();

            data.Add(
                Array.Empty<string>(),
                Array.Empty<SortOrder>(),
                Array.Empty<(string, SortOrder)>());

            data.Add(
                new string[]
                {
                    "IsFavoriteOrLiked",
                    "Random"
                },
                Array.Empty<SortOrder>(),
                new (string, SortOrder)[]
                {
                    ("IsFavoriteOrLiked", SortOrder.Ascending),
                    ("Random", SortOrder.Ascending),
                });

            data.Add(
                new string[]
                {
                    "SortName",
                    "ProductionYear"
                },
                new SortOrder[]
                {
                    SortOrder.Descending
                },
                new (string, SortOrder)[]
                {
                    ("SortName", SortOrder.Descending),
                    ("ProductionYear", SortOrder.Descending),
                });

            return data;
        }

        [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);
        }
    }
}