From 8f09e3172f249a9f5d229040415a0569e9d1c01b Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 6 Mar 2021 22:51:53 +0800 Subject: feat: Auto translate url in markdown post. --- .../IntegratedTests/TimelinePostTest.cs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs') diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs index b91de6c2..f00d9b13 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs @@ -14,6 +14,7 @@ using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Jpeg; using System.Net; +using System.Text.RegularExpressions; namespace Timeline.Tests.IntegratedTests { @@ -36,6 +37,23 @@ namespace Timeline.Tests.IntegratedTests }; } + private static HttpTimelinePostCreateRequest CreateMarkdownPostRequest(string text, DateTime? time = null, string? color = null) + { + return new HttpTimelinePostCreateRequest() + { + Time = time, + Color = color, + DataList = new List() + { + new HttpTimelinePostCreateRequestData() + { + ContentType = MimeTypes.TextMarkdown, + Data = Convert.ToBase64String(Encoding.UTF8.GetBytes(text)) + } + } + }; + } + private readonly ITestOutputHelper _outputHelper; public TimelinePostTest(ITestOutputHelper outputHelper) @@ -586,5 +604,19 @@ namespace Timeline.Tests.IntegratedTests post2.Editable.Should().BeFalse(); } } + + [Theory] + [MemberData(nameof(TimelineNameGeneratorTestData))] + public async Task Post_Markdown_Url_Map(TimelineNameGenerator generator) + { + using var client = await CreateClientAsUser(); + var post = await client.TestPostAsync($"timelines/{generator(1)}/posts", CreateMarkdownPostRequest("[aaa](1) ![bbb](2)")); + + var res = await client.GetAsync($"timelines/{generator(1)}/posts/{post.Id}/data"); + var markdown = await res.Content.ReadAsStringAsync(); + + markdown.Should().MatchRegex(@$"\[aaa\]\(https?://.*/timelines/{generator(1)}/posts/{post.Id}/data/1\)"); + markdown.Should().MatchRegex(@$"\[bbb\]\(https?://.*/timelines/{generator(1)}/posts/{post.Id}/data/2\)"); + } } } -- cgit v1.2.3