More tests

This commit is contained in:
Rory&
2026-06-19 05:59:12 +02:00
parent d401aea643
commit 0c6da7e718
2 changed files with 43 additions and 22 deletions
@@ -16,6 +16,7 @@ public class ChannelTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
private static AuthenticatedSpacebarClient Client { get; set; } = null!;
private static Guild? Guild { get; set; }
private static Channel? Channel { get; set; }
public async ValueTask InitializeAsync() {
testOutputHelper.WriteLine("Running InitializeAsync");
@@ -25,6 +26,7 @@ public class ChannelTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
Guild ??= await Client.CreateGuild(new() {
Name = "Test guild"
});
Channel ??= await Client.GetGuild(Guild.Id).CreateChannelAsync(new() { Name = "meow", Type = 0 });
}
[Fact]
@@ -32,7 +34,7 @@ public class ChannelTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
Assert.Equal("Test guild", Guild!.Name);
var channel = await Client!.GetGuild(Guild.Id).CreateChannelAsync(new() {
Name = "test",
Type = 0
Type = 0 // TODO: this should be the default
});
Assert.Equal("test", channel.Name);
@@ -40,18 +42,15 @@ public class ChannelTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
[Fact]
public async Task GetChannel() {
Assert.Equal("Test guild", Guild!.Name);
var channel = await Client!.GetGuild(Guild.Id).CreateChannelAsync(new() {
Name = "test",
Type = 0
});
Assert.Equal("test", channel.Name);
var res = await Client.ApiHttpClient.GetAsync("channels/" + channel.Id, TestContext.Current.CancellationToken);
await Assert.HttpSuccess(res);
var res = await Assert.HttpSuccess(await Client.ApiHttpClient.GetAsync("channels/" + Channel.Id, TestContext.Current.CancellationToken));
var channelResp = await res.Content.ReadFromJsonAsync<Channel>(cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(channel.Name, channelResp!.Name);
Assert.Equal(channel.Id, channelResp!.Id);
Assert.Equal(Channel.Name, channelResp!.Name);
Assert.Equal(Channel.Id, channelResp!.Id);
}
[Fact]
public async Task SendTyping() {
await Assert.HttpSuccess(await Client.ApiHttpClient.PostAsync($"channels/{Channel!.Id}/typing", null, TestContext.Current.CancellationToken));
}
}
@@ -1,4 +1,6 @@
using Spacebar.Sdk.Core;
using ArcaneLibs.Extensions;
using Spacebar.Models.Generic;
using Spacebar.Sdk.Core;
using Spacebar.Tests.Abstractions;
using Spacebar.Tests.Extensions;
using Spacebar.Tests.Fixtures;
@@ -6,35 +8,55 @@ using Xunit.Microsoft.DependencyInjection.Abstracts;
namespace Spacebar.Tests.Tests;
public class GuildTests(ITestOutputHelper testOutputHelper, TestFixture fixture) : TestBed<TestFixture>(testOutputHelper, fixture) {
public class GuildTests(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!;
private static Guild? Guild { get; set; }
private static Channel? Channel { get; set; }
public async ValueTask InitializeAsync() {
testOutputHelper.WriteLine("Running InitializeAsync");
// All these tests can share a single client
Client = await _userAbstraction.GetSharedUser();
// ...and a guild
Guild ??= await Client.CreateGuild(new() {
Name = "Test guild"
});
Channel ??= await Client.GetGuild(Guild.Id).CreateChannelAsync(new() { Name = "meow", Type = 0 });
}
[Fact]
public async Task CreateGuild() {
var client = await _userAbstraction.GetSharedUser();
var guild = await client.CreateGuild(new() {
var guild = await Client.CreateGuild(new() {
Name = "Test guild"
});
Assert.Equal("Test guild", guild.Name);
}
[Fact]
public async Task GetChannels() {
var client = await _userAbstraction.GetSharedUser();
var guild = await client.CreateGuild(new() {
var guild = await Client.CreateGuild(new() {
Name = "Test guild"
});
Assert.Equal("Test guild", guild.Name);
var channels = await client.GetGuild(guild.Id).GetChannelsAsync();
var channels = await Client.GetGuild(guild.Id).GetChannelsAsync();
Assert.NotEmpty(channels);
foreach (var channel in channels) {
Assert.StringNotNullOrWhitespace(channel.Name);
}
}
[Fact]
public async Task SetChannelOrder() {
var cg = Client.GetGuild(Guild.Id);
var guildChannels = await cg.GetChannelsAsync();
// testOutputHelper.WriteLine(guildChannels.Select(x=>(x.Id, x.Name)).ToJson(includeFields: true));
}
}