diff options
author | crupest <crupest@outlook.com> | 2021-01-19 15:24:39 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-19 15:24:39 +0800 |
commit | fb6442f1716406c7a2da79e4a1cc42e23908d218 (patch) | |
tree | 455fbd07678b1b21a1bfa3ad7e3778b1957fd12f /BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs | |
parent | 208ae3f6371857e2b06cf789a640989f64f80a24 (diff) | |
download | timeline-fb6442f1716406c7a2da79e4a1cc42e23908d218.tar.gz timeline-fb6442f1716406c7a2da79e4a1cc42e23908d218.tar.bz2 timeline-fb6442f1716406c7a2da79e4a1cc42e23908d218.zip |
test: Add integrated tests for search api.
Diffstat (limited to 'BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs')
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs new file mode 100644 index 00000000..f96acfea --- /dev/null +++ b/BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs @@ -0,0 +1,63 @@ +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 SearchTest : IntegratedTestBase
+ {
+ [Fact]
+ public async Task TimelineSearch_Should_Work()
+ {
+ var client = await CreateClientAsUser();
+
+ {
+ await client.TestPostAsync("timelines", new HttpTimelineCreateRequest { Name = "hahaha" });
+ await client.TestPostAsync("timelines", new HttpTimelineCreateRequest { Name = "bababa" });
+ await client.TestPatchAsync("timelines/bababa", new HttpTimelinePatchRequest { Title = "hahaha" });
+ await client.TestPostAsync("timelines", new HttpTimelineCreateRequest { Name = "gagaga" });
+ }
+
+ {
+ var res = await client.TestGetAsync<List<HttpTimeline>>("search/timelines?q=hah");
+ res.Should().HaveCount(2);
+ res[0].Name.Should().Be("hahaha");
+ res[1].Name.Should().Be("bababa");
+ }
+
+ {
+ var res = await client.TestGetAsync<List<HttpTimeline>>("search/timelines?q=wuhu");
+ res.Should().BeEmpty();
+ }
+ }
+
+ [Fact]
+ public async Task UserSearch_Should_Work()
+ {
+ var client = await CreateClientAsAdministrator();
+
+ {
+ await client.TestPostAsync("userop/createuser", new HttpCreateUserRequest { Username = "hahaha", Password = "p" });
+ await client.TestPostAsync("userop/createuser", new HttpCreateUserRequest { Username = "bababa", Password = "p" });
+ await client.TestPatchAsync("users/bababa", new HttpUserPatchRequest { Nickname = "hahaha" });
+ await client.TestPostAsync("userop/createuser", new HttpCreateUserRequest { Username = "gagaga", Password = "p" });
+ }
+
+ {
+ var res = await client.TestGetAsync<List<HttpUser>>("search/users?q=hah");
+ res.Should().HaveCount(2);
+ res[0].Username.Should().Be("hahaha");
+ res[1].Username.Should().Be("bababa");
+ }
+
+ {
+ var res = await client.TestGetAsync<List<HttpUser>>("search/users?q=wuhu");
+ res.Should().BeEmpty();
+ }
+ }
+ }
+}
|