summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-07-05 00:59:53 +0200
committerRory& <root@rory.gay>2026-07-05 00:59:53 +0200
commitc641b45e58906476d3a18bb3fcf95d754e946ad5 (patch)
tree8d39fa4e9c0f8f02132c9c426db0fd22e8f4a720
parentMerge remote-tracking branch 'aldproductions/rename-unused-rights' (diff)
downloadserver-ts-c641b45e58906476d3a18bb3fcf95d754e946ad5.tar.xz
Basic gif search test
-rw-r--r--extra/admin-api/Models/Spacebar.Models.Api/GifResponse.cs29
-rw-r--r--extra/admin-api/Tests/Spacebar.Tests/Tests/GifTests.cs53
2 files changed, 82 insertions, 0 deletions
diff --git a/extra/admin-api/Models/Spacebar.Models.Api/GifResponse.cs b/extra/admin-api/Models/Spacebar.Models.Api/GifResponse.cs
new file mode 100644

index 00000000..4cf3b51e --- /dev/null +++ b/extra/admin-api/Models/Spacebar.Models.Api/GifResponse.cs
@@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; + +namespace Spacebar.Models.Api; + +public class GifItem { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("title"), Obsolete("Deprecated")] + public string? Title { get; set; } + + [JsonPropertyName("url")] + public string Url { get; set; } + + [JsonPropertyName("src")] + public string Source { get; set; } + + [JsonPropertyName("gif_src")] + public string GifSource { get; set; } + + [JsonPropertyName("preview")] + public string Preview { get; set; } + + [JsonPropertyName("width")] + public int Width { get; set; } + + [JsonPropertyName("height")] + public int Height { get; set; } +} \ No newline at end of file diff --git a/extra/admin-api/Tests/Spacebar.Tests/Tests/GifTests.cs b/extra/admin-api/Tests/Spacebar.Tests/Tests/GifTests.cs new file mode 100644
index 00000000..8c4eff33 --- /dev/null +++ b/extra/admin-api/Tests/Spacebar.Tests/Tests/GifTests.cs
@@ -0,0 +1,53 @@ +using System.Diagnostics; +using System.Net.Http.Json; +using System.Text.Json.Nodes; +using ArcaneLibs.Extensions; +using Spacebar.Models.AdminApi; +using Spacebar.Models.Api; +using Spacebar.Models.Generic; +using Spacebar.Sdk.Core; +using Spacebar.Tests.Abstractions; +using Spacebar.Tests.Extensions; +using Spacebar.Tests.Fixtures; +using Xunit.Internal; +using Xunit.Microsoft.DependencyInjection.Abstracts; + +namespace Spacebar.Tests.Tests; + +public class GifTests(ITestOutputHelper testOutputHelper, TestFixture fixture) : TestBed<TestFixture>(testOutputHelper, fixture), IAsyncLifetime { + private readonly Config _config = fixture.GetRequiredService<Config>(testOutputHelper); + private readonly SpacebarClientWellKnownResolverService _wellKnownResolver = fixture.GetRequiredService<SpacebarClientWellKnownResolverService>(testOutputHelper); + private readonly SpacebarClientProviderService _clientProvider = fixture.GetRequiredService<SpacebarClientProviderService>(testOutputHelper); + private readonly UserAbstraction _userAbstraction = fixture.GetRequiredService<UserAbstraction>(testOutputHelper); + + private static AuthenticatedSpacebarClient Client { get; set; } = null!; + + public async ValueTask InitializeAsync() { + testOutputHelper.WriteLine("Running InitializeAsync"); + // All these tests can share a single client + Client = await _userAbstraction.GetSharedUser(); + } + + public static IEnumerable<object[]> GifSearchTestMatrix() { + foreach (var query in (string[])["meow", "meowmeow"]) + foreach (var provider in (string[])["tenor"]) + yield return [query, provider]; + } + + [Theory, MemberData(nameof(GifSearchTestMatrix))] + public async Task SearchGifs(string query, string provider) { + var resp = await Assert.HttpSuccess(await Client.ApiHttpClient.GetAsync($"gifs/search?q={query}&provider={provider}", TestContext.Current.CancellationToken)); + var respContent = await resp.Content.ReadFromJsonAsync<List<GifItem>>(cancellationToken: TestContext.Current.CancellationToken); + + Assert.True(respContent!.Count > 0, "respContent.Count > 0"); + Assert.All(respContent, gif => { + Assert.StringNotNullOrWhitespace(gif.Id); + Assert.StringNotNullOrWhitespace(gif.GifSource); + Assert.StringNotNullOrWhitespace(gif.Preview); + Assert.StringNotNullOrWhitespace(gif.Source); + Assert.StringNotNullOrWhitespace(gif.Url); + Assert.NotEqual(0, gif.Width); + Assert.NotEqual(0, gif.Height); + }); + } +} \ No newline at end of file