diff options
Diffstat (limited to 'Timeline.Tests/IntegratedTests/TimelineTest.cs')
-rw-r--r-- | Timeline.Tests/IntegratedTests/TimelineTest.cs | 124 |
1 files changed, 118 insertions, 6 deletions
diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 3b4b1754..ec46b96a 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -488,7 +488,7 @@ namespace Timeline.Tests.IntegratedTests {
var res = await client.DeleteAsync("timelines/t1");
- res.Should().HaveStatusCode(HttpStatusCode.NotFound);
+ res.Should().HaveStatusCode(400);
}
}
}
@@ -545,15 +545,15 @@ namespace Timeline.Tests.IntegratedTests }
{
var res = await client.PatchAsJsonAsync(generator("notexist", null), new TimelinePatchRequest { });
- res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode);
+ res.Should().HaveStatusCode(400).And.HaveCommonBody(errorCode);
}
{
var res = await client.PutAsync(generator("notexist", "members/user1"), null);
- res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode);
+ res.Should().HaveStatusCode(400).And.HaveCommonBody(errorCode);
}
{
var res = await client.DeleteAsync(generator("notexist", "members/user1"));
- res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode);
+ res.Should().HaveStatusCode(400).And.HaveCommonBody(errorCode);
}
{
var res = await client.GetAsync(generator("notexist", "posts"));
@@ -561,11 +561,11 @@ namespace Timeline.Tests.IntegratedTests }
{
var res = await client.PostAsJsonAsync(generator("notexist", "posts"), TimelineHelper.TextPostCreateRequest("aaa"));
- res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode);
+ res.Should().HaveStatusCode(400).And.HaveCommonBody(errorCode);
}
{
var res = await client.DeleteAsync(generator("notexist", "posts/123"));
- res.Should().HaveStatusCode(404).And.HaveCommonBody(errorCode);
+ res.Should().HaveStatusCode(400).And.HaveCommonBody(errorCode);
}
{
var res = await client.GetAsync(generator("notexist", "posts/123/data"));
@@ -1407,5 +1407,117 @@ namespace Timeline.Tests.IntegratedTests .Which.Should().BeEquivalentTo(timeline);
}
}
+
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task Title(TimelineUrlGenerator urlGenerator)
+ {
+ using var client = await CreateClientAsUser();
+
+ {
+ var res = await client.GetAsync(urlGenerator(1));
+ var timeline = res.Should().HaveStatusCode(200)
+ .And.HaveJsonBody<TimelineInfo>()
+ .Which;
+ timeline.Title.Should().Be(timeline.Name);
+ }
+
+ {
+ var res = await client.PatchAsJsonAsync(urlGenerator(1), new TimelinePatchRequest { Title = "atitle" });
+ res.Should().HaveStatusCode(200)
+ .And.HaveJsonBody<TimelineInfo>()
+ .Which.Title.Should().Be("atitle");
+ }
+
+ {
+ var res = await client.GetAsync(urlGenerator(1));
+ res.Should().HaveStatusCode(200)
+ .And.HaveJsonBody<TimelineInfo>()
+ .Which.Title.Should().Be("atitle");
+ }
+ }
+
+ [Fact]
+ public async Task ChangeName()
+ {
+ {
+ using var client = await CreateDefaultClient();
+ var res = await client.PostAsJsonAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "tttttttt" });
+ res.Should().HaveStatusCode(401);
+ }
+
+ {
+ using var client = await CreateClientAs(2);
+ var res = await client.PostAsJsonAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "tttttttt" });
+ res.Should().HaveStatusCode(403);
+ }
+
+ using (var client = await CreateClientAsUser())
+ {
+ {
+ var res = await client.PostAsJsonAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "!!!", NewName = "tttttttt" });
+ res.Should().BeInvalidModel();
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "ttt", NewName = "!!!!" });
+ res.Should().BeInvalidModel();
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "ttttt", NewName = "tttttttt" });
+ res.Should().HaveStatusCode(400).And.HaveCommonBody().Which.Code.Should().Be(ErrorCodes.TimelineController.NotExist);
+ }
+
+ {
+ var res = await client.PostAsJsonAsync("timelineop/changename", new TimelineChangeNameRequest { OldName = "t1", NewName = "newt" });
+ res.Should().HaveStatusCode(200).And.HaveJsonBody<TimelineInfo>().Which.Name.Should().Be("newt");
+ }
+
+ {
+ var res = await client.GetAsync("timelines/t1");
+ res.Should().HaveStatusCode(404);
+ }
+
+ {
+ var res = await client.GetAsync("timelines/newt");
+ res.Should().HaveStatusCode(200).And.HaveJsonBody<TimelineInfo>().Which.Name.Should().Be("newt");
+ }
+ }
+ }
+
+ [Theory]
+ [MemberData(nameof(TimelineUrlGeneratorData))]
+ public async Task PostDataETag(TimelineUrlGenerator urlGenerator)
+ {
+ using var client = await CreateClientAsUser();
+
+ long id;
+ string etag;
+
+ {
+ var res = await client.PostAsJsonAsync(urlGenerator(1, "posts"), new TimelinePostCreateRequest
+ {
+ Content = new TimelinePostCreateRequestContent
+ {
+ Type = TimelinePostContentTypes.Image,
+ Data = Convert.ToBase64String(ImageHelper.CreatePngWithSize(100, 50))
+ }
+ });
+ res.Should().HaveStatusCode(200);
+ var body = await res.ReadBodyAsJsonAsync<TimelinePostInfo>();
+ body.Content.ETag.Should().NotBeNullOrEmpty();
+
+ id = body.Id;
+ etag = body.Content.ETag;
+ }
+
+ {
+ var res = await client.GetAsync(urlGenerator(1, $"posts/{id}/data"));
+ res.Should().HaveStatusCode(200);
+ res.Headers.ETag.Should().NotBeNull();
+ res.Headers.ETag.ToString().Should().Be(etag);
+ }
+ }
}
}
|