aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-11-17 23:04:21 +0800
committercrupest <crupest@outlook.com>2019-11-17 23:04:21 +0800
commit59c10650fc36e8c79c1def088240fd90a5151250 (patch)
tree46282455cd6bdf43bf2215d3918f5803b2a31674 /Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
parentc2b107eda8a14f836d663638641a3e3f17373b5d (diff)
downloadtimeline-59c10650fc36e8c79c1def088240fd90a5151250.tar.gz
timeline-59c10650fc36e8c79c1def088240fd90a5151250.tar.bz2
timeline-59c10650fc36e8c79c1def088240fd90a5151250.zip
Fix typo in path of personal timeline controller actions. Add timeline permission test.
Diffstat (limited to 'Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs')
-rw-r--r--Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
new file mode 100644
index 00000000..9629fc0a
--- /dev/null
+++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
@@ -0,0 +1,62 @@
+using FluentAssertions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc.Testing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Text.Json;
+using System.Threading.Tasks;
+using Timeline.Models.Http;
+using Timeline.Tests.Helpers;
+using Timeline.Tests.Helpers.Authentication;
+using Xunit;
+
+namespace Timeline.Tests.IntegratedTests
+{
+ public class PersonalTimelineTest : IntegratedTestBase
+ {
+ public PersonalTimelineTest(WebApplicationFactory<Startup> factory)
+ : base(factory)
+ {
+
+ }
+
+ [Theory]
+ [InlineData(AuthType.None, 200, 401, 401, 401, 401)]
+ [InlineData(AuthType.User, 200, 200, 403, 200, 403)]
+ [InlineData(AuthType.Admin, 200, 200, 200, 200, 200)]
+ public async Task Permission_Timeline(AuthType authType, int get, int opPropertyUser, int opPropertyAdmin, int opMemberUser, int opMemberAdmin)
+ {
+ using var client = await Factory.CreateClientAs(authType);
+ {
+ var res = await client.GetAsync("users/user/timeline");
+ res.Should().HaveStatusCode(get);
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("users/user/timeline/op/property",
+ new TimelinePropertyChangeRequest { Description = "hahaha" });
+ res.Should().HaveStatusCode(opPropertyUser);
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("users/admin/timeline/op/property",
+ new TimelinePropertyChangeRequest { Description = "hahaha" });
+ res.Should().HaveStatusCode(opPropertyAdmin);
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("users/user/timeline/op/member",
+ new TimelineMemberChangeRequest { Add = new List<string> { "admin" } });
+ res.Should().HaveStatusCode(opMemberUser);
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("users/admin/timeline/op/member",
+ new TimelineMemberChangeRequest { Add = new List<string> { "user" } });
+ res.Should().HaveStatusCode(opMemberAdmin);
+ }
+ }
+ }
+}