mirror of
https://github.com/spacebarchat/server.git
synced 2026-07-26 16:40:59 +00:00
Add webhook message delete test
This commit is contained in:
@@ -28,6 +28,13 @@ public static class AssertHttpExtensions {
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<HttpResponseMessage> SuccessfullyHttpDeleteAsync(string url) {
|
||||
var res = await Hc.DeleteAsync(url);
|
||||
if (!res.IsSuccessStatusCode)
|
||||
Assert.True(res.IsSuccessStatusCode, $"Could not DELETE {url}: {(int)res.StatusCode} {res.StatusCode}\n{await GetFormattedErrorDetails(res)}");
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<HttpResponseMessage> HttpSuccess(HttpResponseMessage res) {
|
||||
if (!res.IsSuccessStatusCode)
|
||||
Assert.True(res.IsSuccessStatusCode,
|
||||
|
||||
@@ -41,7 +41,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
|
||||
Assert.Equal("test", c.Result.Name);
|
||||
Channel = Client.GetChannel(c.Result.Id);
|
||||
});
|
||||
|
||||
|
||||
if (Webhook is null)
|
||||
await Channel!.CreateWebhookAsync(new() {
|
||||
Name = "meow"
|
||||
@@ -50,8 +50,7 @@ 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" }
|
||||
@@ -67,7 +66,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
|
||||
Assert.Equal("meow", wh.Name);
|
||||
Assert.StringNotNullOrWhitespace(wh.Url);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteWebhookByToken() {
|
||||
var wh = await Channel!.CreateWebhookAsync(new() {
|
||||
@@ -78,7 +77,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
|
||||
Assert.StringNotNullOrWhitespace(wh.Url);
|
||||
await Assert.HttpSuccess(await Client.ApiHttpClient.DeleteAsync(wh.Url, TestContext.Current.CancellationToken));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteWebhook() {
|
||||
var wh = await Channel!.CreateWebhookAsync(new() {
|
||||
@@ -157,7 +156,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -173,7 +172,16 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
|
||||
public async Task GetWebhookMessageById() {
|
||||
var msg = await Assert.SuccessfullyHttpGetAsync(Webhook.Url + "/messages/" + WebhookMessage.Id);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteWebhookMessageById() {
|
||||
var msg = await Assert.SuccessfullyHttpPostAsJsonAsync(Webhook.Url + "?wait=true", new JsonObject() {
|
||||
{ "content", "meow" },
|
||||
});
|
||||
var actualMsg = await msg.Content.ReadFromJsonAsync<Message>();
|
||||
await Assert.SuccessfullyHttpDeleteAsync(Webhook.Url + "/messages/" + actualMsg!.Id);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(WebhookExecuteCombinations))]
|
||||
public async Task EditWebhookMessageByIdWithData(string content, string? username, string? avatarUrl, bool? tts, int? flags) {
|
||||
@@ -184,7 +192,7 @@ public class WebhookTests(ITestOutputHelper testOutputHelper, TestFixture fixtur
|
||||
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