mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-22 14:09:56 +00:00
Add webhook message get/update/delete
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user