mirror of
https://github.com/spacebarchat/server.git
synced 2026-07-01 18:01:57 +00:00
Various tests stuff
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"Configuration": {
|
||||
"TestInstance": "http://localhost:3001",
|
||||
// "TestInstance": "http://localhost:3001",
|
||||
"TestInstance": "http://localhost:5085",
|
||||
"RegisterConcurrentCount": 150
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user