From 9494c9717f0d9983ec1c8db092387fef7199b00d Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 19 Jan 2021 15:24:39 +0800 Subject: test: Add integrated tests for search api. --- .../Timeline.Tests/IntegratedTests/SearchTest.cs | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs (limited to 'BackEnd/Timeline.Tests/IntegratedTests/SearchTest.cs') 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>("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>("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>("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>("search/users?q=wuhu"); + res.Should().BeEmpty(); + } + } + } +} -- cgit v1.2.3