diff options
Diffstat (limited to 'BackEnd/Timeline.Tests')
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs | 91 | ||||
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs | 5 |
2 files changed, 96 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs new file mode 100644 index 00000000..d4b4d55d --- /dev/null +++ b/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs @@ -0,0 +1,91 @@ +using FluentAssertions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Timeline.Models.Http;
+using Xunit;
+
+namespace Timeline.Tests.IntegratedTests
+{
+ public class HighlightTimelineTest : IntegratedTestBase
+ {
+ [Fact]
+ public async Task PermissionTest()
+ {
+ using var client = await CreateClientAsUser();
+
+ await client.TestPutAssertForbiddenAsync("highlights/@user1");
+ await client.TestDeleteAssertForbiddenAsync("highlights/@user1");
+ await client.TestPostAssertForbiddenAsync("highlightop/move", new HttpHighlightTimelineMoveRequest { Timeline = "aaa", NewPosition = 1 });
+ }
+
+ [Fact]
+ public async Task InvalidModel()
+ {
+ using var client = await CreateClientAsAdministrator();
+
+ await client.TestPutAssertInvalidModelAsync("highlights/!!!");
+ await client.TestDeleteAssertInvalidModelAsync("highlights/!!!");
+ await client.TestPostAssertInvalidModelAsync("highlightop/move", new HttpHighlightTimelineMoveRequest { Timeline = null!, NewPosition = 1 });
+ await client.TestPostAssertInvalidModelAsync("highlightop/move", new HttpHighlightTimelineMoveRequest { Timeline = "aaa", NewPosition = null });
+ }
+
+ [Fact]
+ public async Task ShouldWork()
+ {
+ {
+ using var client1 = await CreateClientAsUser();
+ await client1.TestPostAsync("timelines", new TimelineCreateRequest { Name = "t1" });
+ }
+
+ using var client = await CreateClientAsAdministrator();
+
+ {
+ var h = await client.TestGetAsync<List<HttpTimeline>>("highlights");
+ h.Should().BeEmpty();
+ }
+
+ await client.TestPutAsync("highlights/@user1");
+
+ {
+ var h = await client.TestGetAsync<List<HttpTimeline>>("highlights");
+ h.Should().HaveCount(1);
+ h[0].Name.Should().Be("@user1");
+ }
+
+ await client.TestPutAsync("highlights/t1");
+
+ {
+ var h = await client.TestGetAsync<List<HttpTimeline>>("highlights");
+ h.Should().HaveCount(2);
+ h[0].Name.Should().Be("@user1");
+ h[1].Name.Should().Be("t1");
+ }
+
+ await client.TestPostAsync("highlightop/move", new HttpHighlightTimelineMoveRequest { Timeline = "@user1", NewPosition = 2 });
+
+ {
+ var h = await client.TestGetAsync<List<HttpTimeline>>("highlights");
+ h.Should().HaveCount(2);
+ h[0].Name.Should().Be("t1");
+ h[1].Name.Should().Be("@user1");
+ }
+
+ await client.TestDeleteAsync("highlights/@user1");
+
+ {
+ var h = await client.TestGetAsync<List<HttpTimeline>>("highlights");
+ h.Should().HaveCount(1);
+ h[0].Name.Should().Be("t1");
+ }
+
+ await client.TestDeleteAsync("highlights/t1");
+
+ {
+ var h = await client.TestGetAsync<List<HttpTimeline>>("highlights");
+ h.Should().BeEmpty();
+ }
+ }
+ }
+}
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs index 7cff0c39..ec517362 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/HttpClientTestExtensions.cs @@ -212,6 +212,11 @@ namespace Timeline.Tests.IntegratedTests await client.TestJsonSendAssertForbiddenAsync(HttpMethod.Post, url, jsonBody, errorCode, headerSetup);
}
+ public static async Task TestPutAssertForbiddenAsync(this HttpClient client, string url, object? jsonBody = null, int? errorCode = null, HeaderSetup? headerSetup = null)
+ {
+ await client.TestJsonSendAssertForbiddenAsync(HttpMethod.Put, url, jsonBody, errorCode, headerSetup);
+ }
+
public static async Task TestPatchAssertForbiddenAsync(this HttpClient client, string url, object? jsonBody = null, int? errorCode = null, HeaderSetup? headerSetup = null)
{
await client.TestJsonSendAssertForbiddenAsync(HttpMethod.Patch, url, jsonBody, errorCode, headerSetup);
|