From c641b45e58906476d3a18bb3fcf95d754e946ad5 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 5 Jul 2026 00:59:53 +0200 Subject: [PATCH] Basic gif search test --- .../Models/Spacebar.Models.Api/GifResponse.cs | 29 ++++++++++ .../Tests/Spacebar.Tests/Tests/GifTests.cs | 53 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 extra/admin-api/Models/Spacebar.Models.Api/GifResponse.cs create mode 100644 extra/admin-api/Tests/Spacebar.Tests/Tests/GifTests.cs 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 000000000..4cf3b51e4 --- /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 000000000..8c4eff337 --- /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(testOutputHelper, fixture), IAsyncLifetime { + private readonly Config _config = fixture.GetRequiredService(testOutputHelper); + private readonly SpacebarClientWellKnownResolverService _wellKnownResolver = fixture.GetRequiredService(testOutputHelper); + private readonly SpacebarClientProviderService _clientProvider = fixture.GetRequiredService(testOutputHelper); + private readonly UserAbstraction _userAbstraction = fixture.GetRequiredService(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 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>(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