Add webhook message get/update/delete

This commit is contained in:
Rory&
2026-07-15 00:27:03 +02:00
parent abd97eb1e6
commit 46f3ecb39e
2 changed files with 240 additions and 1 deletions
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using System.Net.Http.Json;
using System.Text.Json.Nodes;
using Spacebar.Models.Generic;
using Spacebar.Sdk.Core;
using Spacebar.Tests.Abstractions;
@@ -19,6 +20,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
private static SpacebarClientChannel? Channel = null!;
private static Webhook? Webhook = null!;
private static Message? WebhookMessage = null!;
public async ValueTask InitializeAsync() {
Client = await _userAbstraction.GetSharedUser();
@@ -48,6 +50,12 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
Assert.StringNotNullOrWhitespace(w.Result.Url);
Webhook = w.Result;
});
if (WebhookMessage is null)
WebhookMessage = await (await Assert.SuccessfullyHttpPostAsJsonAsync(Webhook.Url + "?wait=true", new JsonObject() {
{ "content", "meow" }
})).Content.ReadFromJsonAsync<Message>();
}
[Fact]
@@ -160,4 +168,23 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
{ "avatar_url", Client.ClientWellKnown.Api.BaseUrl + "/static/logo.png" }
});
}
[Fact]
public async Task GetWebhookMessageById() {
var msg = await Assert.SuccessfullyHttpGetAsync(Webhook.Url + "/messages/" + WebhookMessage.Id);
}
[Theory]
[MemberData(nameof(WebhookExecuteCombinations))]
public async Task EditWebhookMessageByIdWithData(string content, string? username, string? avatarUrl, bool? tts, int? flags) {
var payload = new JsonObject() {
{ "content", content }
};
if (username != null) payload.Add("username", username);
if (avatarUrl != null) payload.Add("avatar_url", avatarUrl);
if (tts != null) payload.Add("tts", tts);
if (flags != null) payload.Add("flags", flags);
await Assert.SuccessfullyHttpPostAsJsonAsync(Webhook.Url + "?wait=true", payload);
}
}