summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-30 18:34:25 +0200
committerRory& <root@rory.gay>2026-06-30 18:34:25 +0200
commit472d1159b1ff44da100e168d8cdbfa228654ca44 (patch)
tree3a83ccd68bba9fee30cfbf05593a201c04e336e9
parentDont (re-/)add embeds if message has embed suppressed (diff)
downloadserver-ts-472d1159b1ff44da100e168d8cdbfa228654ca44.tar.xz
Various tests stuff
-rw-r--r--extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs18
-rw-r--r--extra/admin-api/Tests/Spacebar.Tests/Tests/PollTests.cs81
-rw-r--r--extra/admin-api/Tests/Spacebar.Tests/Tests/WebhookTests.cs2
-rw-r--r--extra/admin-api/Tests/Spacebar.Tests/appsettings.json3
4 files changed, 95 insertions, 9 deletions
diff --git a/extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs b/extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs

index f57916a3..01398b4d 100644 --- a/extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs +++ b/extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs
@@ -41,7 +41,7 @@ public class AuthenticationTests(ITestOutputHelper testOutputHelper, TestFixture DateOfBirth = new(), Consent = true }; - + var result = await Assert.SuccessfullyHttpPostAsJsonAsync($"{_config.TestInstance}/api/v9/auth/register", rr); testOutputHelper.WriteLine($"[{i++}] Registered {rr.Email} in {sw.Elapsed}..."); return (rr, result); @@ -50,7 +50,7 @@ public class AuthenticationTests(ITestOutputHelper testOutputHelper, TestFixture testOutputHelper.WriteLine("Waiting for server to settle..."); await Task.Delay(2500, TestContext.Current.CancellationToken); - + testOutputHelper.WriteLine("Cleaning up users..."); var cleanupTasks = tasks.Select(x => x.Result).Select(async res => { var resp = await res.Item2.Content.ReadFromJsonAsync<RegisterResponse>(); @@ -74,11 +74,15 @@ public class AuthenticationTests(ITestOutputHelper testOutputHelper, TestFixture DateOfBirth = new(), Consent = true }; - var rrRes = await Assert.SuccessfullyHttpPostAsJsonAsync($"{_config.TestInstance}/api/v9/auth/register", rr); - var loginRes = await Assert.SuccessfullyHttpPostAsJsonAsync($"{_config.TestInstance}/api/v9/auth/login", new LoginRequest() { - Login = rr.Email, - Password = rr.Password - }); + var rrRes = await Assert.SuccessfullyHttpPostAsJsonAsync( + $"{_config.TestInstance}/api/v9/auth/register", rr); + + var loginRes = await Assert.SuccessfullyHttpPostAsJsonAsync( + $"{_config.TestInstance}/api/v9/auth/login", + new LoginRequest() { + Login = rr.Email, + Password = rr.Password + }); } [Fact] diff --git a/extra/admin-api/Tests/Spacebar.Tests/Tests/PollTests.cs b/extra/admin-api/Tests/Spacebar.Tests/Tests/PollTests.cs
index e69de29b..d97011b5 100644 --- a/extra/admin-api/Tests/Spacebar.Tests/Tests/PollTests.cs +++ b/extra/admin-api/Tests/Spacebar.Tests/Tests/PollTests.cs
@@ -0,0 +1,81 @@ +using System.Net.Http.Json; +using System.Text.Json; +using System.Text.Json.Nodes; +using Spacebar.Sdk.Core; +using Spacebar.Tests.Abstractions; +using Spacebar.Tests.Extensions; +using Spacebar.Tests.Fixtures; +using Xunit.Microsoft.DependencyInjection.Abstracts; + +namespace Spacebar.Tests.Tests; + +public class PollTests(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 = null!; + private static SpacebarClientGuild? Guild; + private static SpacebarClientChannel? Channel = null!; + + public async ValueTask InitializeAsync() { + Client = await _userAbstraction.GetSharedUser(); + + if (Guild is null) + await Client.CreateGuild(new() { + Name = "Test guild" + }).ContinueWith(g => { + Assert.Equal("Test guild", g.Result.Name); + Guild = Client.GetGuild(g.Result.Id); + }); + + if (Channel is null) + await Guild!.CreateChannelAsync(new() { + Name = "test", + Type = 0 + }).ContinueWith(c => { + Assert.Equal("test", c.Result.Name); + Channel = Client.GetChannel(c.Result.Id); + }); + } + + [Fact] + public async Task SendMessage() { + await Assert.HttpSuccess(await Client.ApiHttpClient.PostAsJsonAsync($"channels/{Channel.Id}/messages", + JsonSerializer.Deserialize<JsonObject>( + """ + { + "mobile_network_type": "unknown", + "content": "", + "nonce": "1520116766829707264", + "tts": false, + "flags": 0, + "poll": { + "question": { + "text": "meow" + }, + "answers": [ + { + "poll_media": { + "text": "meowmeow" + } + }, + { + "poll_media": { + "text": "meowmeowmeow", + "emoji": { + "name": "😭" + } + } + } + ], + "allow_multiselect": false, + "duration": 24, + "layout_type": 1 + } + } + """), + cancellationToken: TestContext.Current.CancellationToken)); + } +} \ No newline at end of file diff --git a/extra/admin-api/Tests/Spacebar.Tests/Tests/WebhookTests.cs b/extra/admin-api/Tests/Spacebar.Tests/Tests/WebhookTests.cs
index b539aebb..68219216 100644 --- a/extra/admin-api/Tests/Spacebar.Tests/Tests/WebhookTests.cs +++ b/extra/admin-api/Tests/Spacebar.Tests/Tests/WebhookTests.cs
@@ -139,7 +139,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur yield return [content, username, avatarUrl, tts, flags]; } - [Theory()] + [Theory] [MemberData(nameof(WebhookExecuteCombinations))] public async Task SendWebhookMessageWithData(string content, string? username, string? avatarUrl, bool? tts, int? flags) { var payload = new JsonObject() { diff --git a/extra/admin-api/Tests/Spacebar.Tests/appsettings.json b/extra/admin-api/Tests/Spacebar.Tests/appsettings.json
index 6f444ea9..ecf2dd46 100644 --- a/extra/admin-api/Tests/Spacebar.Tests/appsettings.json +++ b/extra/admin-api/Tests/Spacebar.Tests/appsettings.json
@@ -1,6 +1,7 @@ { "Configuration": { - "TestInstance": "http://localhost:3001", +// "TestInstance": "http://localhost:3001", + "TestInstance": "http://localhost:5085", "RegisterConcurrentCount": 150 } } \ No newline at end of file