aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs
blob: 4bad700b76fa103fc62b54c1fee5c055fd21d93f (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using FluentAssertions;
using System.Collections.Generic;
using System.Threading.Tasks;
using Timeline.Models.Http;
using Xunit;
using Xunit.Abstractions;

namespace Timeline.Tests.IntegratedTests
{
    public class BookmarkTimelineTest : IntegratedTestBase
    {
        public BookmarkTimelineTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
        {

        }

        [Fact]
        public async Task AuthTest()
        {
            using var client = await CreateDefaultClient();

            await client.TestPutAssertUnauthorizedAsync("bookmarks/@user1");
            await client.TestDeleteAssertUnauthorizedAsync("bookmarks/@user1");
            await client.TestPostAssertUnauthorizedAsync("bookmarkop/move", new HttpBookmarkTimelineMoveRequest { Timeline = "aaa", NewPosition = 1 });
        }

        [Fact]
        public async Task InvalidModel()
        {
            using var client = await CreateClientAsUser();

            await client.TestPutAssertInvalidModelAsync("bookmarks/!!!");
            await client.TestDeleteAssertInvalidModelAsync("bookmarks/!!!");
            await client.TestPostAssertInvalidModelAsync("bookmarkop/move", new HttpBookmarkTimelineMoveRequest { Timeline = null!, NewPosition = 1 });
            await client.TestPostAssertInvalidModelAsync("bookmarkop/move", new HttpBookmarkTimelineMoveRequest { Timeline = "!!!", NewPosition = 1 });
            await client.TestPostAssertInvalidModelAsync("bookmarkop/move", new HttpBookmarkTimelineMoveRequest { Timeline = "aaa", NewPosition = null });
        }

        [Fact]
        public async Task ShouldWork()
        {
            using var client = await CreateClientAsUser();
            await client.TestPostAsync("timelines", new HttpTimelineCreateRequest { Name = "t1" });


            {
                var h = await client.TestGetAsync<List<HttpTimeline>>("bookmarks");
                h.Should().BeEmpty();
            }

            await client.TestPutAsync("bookmarks/@user1");

            {
                var h = await client.TestGetAsync<List<HttpTimeline>>("bookmarks");
                h.Should().HaveCount(1);
                h[0].Name.Should().Be("@user1");
            }

            await client.TestPutAsync("bookmarks/t1");

            {
                var h = await client.TestGetAsync<List<HttpTimeline>>("bookmarks");
                h.Should().HaveCount(2);
                h[0].Name.Should().Be("@user1");
                h[1].Name.Should().Be("t1");
            }

            await client.TestPostAsync("bookmarkop/move", new HttpHighlightTimelineMoveRequest { Timeline = "@user1", NewPosition = 2 });

            {
                var h = await client.TestGetAsync<List<HttpTimeline>>("bookmarks");
                h.Should().HaveCount(2);
                h[0].Name.Should().Be("t1");
                h[1].Name.Should().Be("@user1");
            }

            await client.TestDeleteAsync("bookmarks/@user1");

            {
                var h = await client.TestGetAsync<List<HttpTimeline>>("bookmarks");
                h.Should().HaveCount(1);
                h[0].Name.Should().Be("t1");
            }

            await client.TestDeleteAsync("bookmarks/t1");

            {
                var h = await client.TestGetAsync<List<HttpTimeline>>("bookmarks");
                h.Should().BeEmpty();
            }
        }

        [Fact]
        public async Task TimelineGet_IsBookmarkField_ShouldWork()
        {
            using var client = await CreateClientAsUser();
            await client.TestPostAsync("timelines", new HttpTimelineCreateRequest { Name = "t" });

            {
                var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
                t.IsBookmark.Should().BeFalse();
            }

            await client.TestPutAsync("bookmarks/t");

            {
                var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
                t.IsBookmark.Should().BeTrue();
            }

            {
                var client1 = await CreateDefaultClient();
                var t = await client1.TestGetAsync<HttpTimeline>("timelines/t");
                t.IsBookmark.Should().BeFalse();
            }

            {
                var client1 = await CreateClientAsAdministrator();
                var t = await client1.TestGetAsync<HttpTimeline>("timelines/t");
                t.IsBookmark.Should().BeFalse();
            }

            await client.TestDeleteAsync("bookmarks/t");

            {
                var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
                t.IsBookmark.Should().BeFalse();
            }
        }
    }
}