2025-02-04 06:36:38 +01:00
|
|
|
using System.Globalization;
|
2023-10-31 12:30:12 +01:00
|
|
|
using NUnit.Framework;
|
2023-10-31 10:06:14 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Webhooks;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
2025-03-21 18:02:31 +01:00
|
|
|
internal sealed class WebhookLogServiceTests : UmbracoIntegrationTest
|
2023-10-31 10:06:14 +01:00
|
|
|
{
|
|
|
|
|
private IWebhookLogService WebhookLogService => GetRequiredService<IWebhookLogService>();
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Can_Create_And_Get()
|
|
|
|
|
{
|
2025-02-04 06:36:38 +01:00
|
|
|
var webHookKey = Guid.NewGuid();
|
2023-10-31 10:06:14 +01:00
|
|
|
var createdWebhookLog = await WebhookLogService.CreateAsync(new WebhookLog
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.UtcNow,
|
2023-11-09 14:18:34 +01:00
|
|
|
EventAlias = Constants.WebhookEvents.Aliases.ContentPublish,
|
2023-10-31 10:06:14 +01:00
|
|
|
RequestBody = "Test Request Body",
|
|
|
|
|
ResponseBody = "Test response body",
|
|
|
|
|
StatusCode = "200",
|
|
|
|
|
RetryCount = 0,
|
|
|
|
|
Key = Guid.NewGuid(),
|
2025-02-04 06:36:38 +01:00
|
|
|
WebhookKey = webHookKey
|
2023-10-31 10:06:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2025-02-04 06:36:38 +01:00
|
|
|
var allWebhookLogsPaged = await WebhookLogService.Get();
|
|
|
|
|
var specificWebhookLogsPaged = await WebhookLogService.Get(webHookKey);
|
2023-10-31 10:06:14 +01:00
|
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
2025-02-04 06:36:38 +01:00
|
|
|
AssertGetResult(createdWebhookLog, allWebhookLogsPaged);
|
|
|
|
|
AssertGetResult(createdWebhookLog, specificWebhookLogsPaged);
|
|
|
|
|
|
|
|
|
|
static void AssertGetResult(WebhookLog createdWebhookLog, PagedModel<WebhookLog> allWebhookLogsPaged)
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull(allWebhookLogsPaged);
|
|
|
|
|
Assert.IsNotEmpty(allWebhookLogsPaged.Items);
|
|
|
|
|
Assert.AreEqual(1, allWebhookLogsPaged.Items.Count());
|
|
|
|
|
var webhookLog = allWebhookLogsPaged.Items.First();
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.Date.ToString(CultureInfo.InvariantCulture), webhookLog.Date.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.EventAlias, webhookLog.EventAlias);
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.RequestBody, webhookLog.RequestBody);
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.ResponseBody, webhookLog.ResponseBody);
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.StatusCode, webhookLog.StatusCode);
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.RetryCount, webhookLog.RetryCount);
|
|
|
|
|
Assert.AreEqual(createdWebhookLog.Key, webhookLog.Key);
|
|
|
|
|
}
|
2023-10-31 10:06:14 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|