diff options
author | crupest <crupest@outlook.com> | 2020-12-17 23:44:40 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-12-17 23:44:40 +0800 |
commit | 5cbc306fc82bf14157ced4ff8b935191d20dae5d (patch) | |
tree | f5ce5a6ffebab52a4a990faa0d12937244cc3185 | |
parent | b9e55a05730cf4ede8dd5bd7a6f9befe5bc3580e (diff) | |
download | timeline-5cbc306fc82bf14157ced4ff8b935191d20dae5d.tar.gz timeline-5cbc306fc82bf14157ced4ff8b935191d20dae5d.tar.bz2 timeline-5cbc306fc82bf14157ced4ff8b935191d20dae5d.zip |
...
4 files changed, 100 insertions, 2 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);
diff --git a/BackEnd/Timeline/Services/HighlightTimelineService.cs b/BackEnd/Timeline/Services/HighlightTimelineService.cs index ea3e4c7e..b19efe21 100644 --- a/BackEnd/Timeline/Services/HighlightTimelineService.cs +++ b/BackEnd/Timeline/Services/HighlightTimelineService.cs @@ -108,13 +108,13 @@ namespace Timeline.Services public async Task<List<TimelineInfo>> GetHighlightTimelines()
{
- var entities = await _database.HighlightTimelines.OrderBy(t => t.Order).Select(t => new { t.Id }).ToListAsync();
+ var entities = await _database.HighlightTimelines.OrderBy(t => t.Order).Select(t => new { t.TimelineId }).ToListAsync();
var result = new List<TimelineInfo>();
foreach (var entity in entities)
{
- result.Add(await _timelineService.GetTimelineById(entity.Id));
+ result.Add(await _timelineService.GetTimelineById(entity.TimelineId));
}
return result;
diff --git a/BackEnd/Timeline/Startup.cs b/BackEnd/Timeline/Startup.cs index bf34f9e2..d20fc54b 100644 --- a/BackEnd/Timeline/Startup.cs +++ b/BackEnd/Timeline/Startup.cs @@ -101,6 +101,8 @@ namespace Timeline services.AddScoped<ITimelineService, TimelineService>();
services.AddScoped<ITimelinePostService, TimelinePostService>();
+ services.AddScoped<IHighlightTimelineService, HighlightTimelineService>();
+
services.AddDbContext<DatabaseContext>((services, options) =>
{
var pathProvider = services.GetRequiredService<IPathProvider>();
|