diff --git a/extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs b/extra/admin-api/Tests/Spacebar.Tests/Tests/AuthenticationTests.cs index f57916a39..01398b4d4 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(); @@ -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 e69de29bb..d97011b53 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(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 = 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( + """ + { + "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 b539aebb7..682192169 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 6f444ea92..ecf2dd46b 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