From d9ed0c1b0fb04d161d27b556e33f0a03738e717d Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 18 Jun 2020 19:41:51 +0800 Subject: feat(back): Timeline service add post modified since. --- Timeline.Tests/Helpers/TestClock.cs | 2 +- Timeline.Tests/Services/TimelineServiceTest.cs | 34 ++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'Timeline.Tests') diff --git a/Timeline.Tests/Helpers/TestClock.cs b/Timeline.Tests/Helpers/TestClock.cs index de7d0eb7..0cbf236d 100644 --- a/Timeline.Tests/Helpers/TestClock.cs +++ b/Timeline.Tests/Helpers/TestClock.cs @@ -36,7 +36,7 @@ namespace Timeline.Tests.Helpers { if (_currentTime == null) return SetMockCurrentTime(); - _currentTime.Value.Add(timeSpan); + _currentTime += timeSpan; return _currentTime.Value; } } diff --git a/Timeline.Tests/Services/TimelineServiceTest.cs b/Timeline.Tests/Services/TimelineServiceTest.cs index cb2ade61..4f081b5d 100644 --- a/Timeline.Tests/Services/TimelineServiceTest.cs +++ b/Timeline.Tests/Services/TimelineServiceTest.cs @@ -63,11 +63,11 @@ namespace Timeline.Tests.Services [InlineData("tl")] public async Task Timeline_LastModified(string timelineName) { - _clock.ForwardCurrentTime(); + var initTime = _clock.ForwardCurrentTime(); void Check(Models.Timeline timeline) { - timeline.NameLastModified.Should().Be(_clock.GetCurrentTime()); + timeline.NameLastModified.Should().Be(initTime); timeline.LastModified.Should().Be(_clock.GetCurrentTime()); } @@ -90,5 +90,35 @@ namespace Timeline.Tests.Services await _timelineService.ChangeMember(timelineName, new List { "admin" }, null); await GetAndCheck(); } + + [Theory] + [InlineData("@user")] + [InlineData("tl")] + public async Task GetPosts_ModifiedSince(string timelineName) + { + _clock.ForwardCurrentTime(); + + var userId = await _userService.GetUserIdByUsername("user"); + + var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal); + if (!isPersonal) + await _timelineService.CreateTimeline(timelineName, userId); + + var postContentList = new string[] { "a", "b", "c", "d" }; + + DateTime testPoint = new DateTime(); + + foreach (var (content, index) in postContentList.Select((v, i) => (v, i))) + { + var t = _clock.ForwardCurrentTime(); + if (index == 1) + testPoint = t; + await _timelineService.CreateTextPost(timelineName, userId, content, null); + } + + var posts = await _timelineService.GetPosts(timelineName, testPoint); + posts.Should().HaveCount(2) + .And.Subject.Select(p => (p.Content as TextTimelinePostContent).Text).Should().Equal(postContentList.Skip(2)); + } } } -- cgit v1.2.3