aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
blob: 9629fc0a7969c1561f35b89b301f2873b687dd16 (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
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);
            }
        }
    }
}