Adds name and description to webhooks (#18217)
* Model, service, test and migration updates to add name and description to webhook. * Update typed client models. * Fixed migration. * Front-end rendering and update of name and description. * Updated OpenApi.json * Reworked integration tests to avoid breaking change. * add name and description to editor header * remove name and description properties * render name as first column in the table * remove focus from url * remove required from name * add parentheses to align UX * add webhook paths * use edit path const in collection * add paths for root * remove unused * remove unused state --------- Co-authored-by: Mads Rasmussen <madsr@hey.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
@@ -7,13 +7,15 @@ using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
// TODO (V16): Make this test class internal (along with any others in this project). We should just expose the base classes and helpers.
|
||||
// Could also consider moving the base classes to a different assembly, and shipping that, but not our tests.
|
||||
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IWebhookService WebhookService => GetRequiredService<IWebhookService>();
|
||||
|
||||
[Test]
|
||||
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentPublish, "00000000-0000-0000-0000-010000000000")]
|
||||
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentDelete, "00000000-0000-0000-0000-000200000000")]
|
||||
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentUnpublish, "00000000-0000-0000-0000-300000000000")]
|
||||
@@ -21,8 +23,9 @@ public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.MediaSave, "00000000-0000-0000-0000-000000500000")]
|
||||
public async Task Can_Create_And_Get(string url, string webhookEvent, Guid key)
|
||||
{
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook(url, true, new[] { key }, new[] { webhookEvent }));
|
||||
var webhook = await WebhookService.GetAsync(createdWebhook.Result.Key);
|
||||
IWebhook webhook = new Webhook(url, true, [key], [webhookEvent]);
|
||||
var createdWebhook = await WebhookService.CreateAsync(webhook);
|
||||
webhook = await WebhookService.GetAsync(createdWebhook.Result.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -34,12 +37,57 @@ public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Create_And_Update_And_Get_With_Name_And_Description()
|
||||
{
|
||||
var contentTypeKey = Guid.NewGuid();
|
||||
const string Url = "https://example.com";
|
||||
const string Event = Constants.WebhookEvents.Aliases.ContentPublish;
|
||||
const string Name = "Example name";
|
||||
const string Description = "Example description";
|
||||
IWebhook webhook = new Webhook(Url, true, [contentTypeKey], [Event])
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description
|
||||
};
|
||||
var createdWebhook = await WebhookService.CreateAsync(webhook);
|
||||
webhook = await WebhookService.GetAsync(createdWebhook.Result.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(webhook);
|
||||
Assert.AreEqual(1, webhook.Events.Length);
|
||||
Assert.IsTrue(webhook.Events.Contains(Event));
|
||||
Assert.AreEqual(Url, webhook.Url);
|
||||
Assert.AreEqual(Name, webhook.Name);
|
||||
Assert.AreEqual(Description, webhook.Description);
|
||||
Assert.IsTrue(webhook.ContentTypeKeys.Contains(contentTypeKey));
|
||||
});
|
||||
|
||||
const string UpdatedName = "Updated name";
|
||||
const string UpdatedDescription = "Updated description";
|
||||
|
||||
webhook.Name = UpdatedName;
|
||||
webhook.Description = UpdatedDescription;
|
||||
|
||||
await WebhookService.UpdateAsync(webhook);
|
||||
|
||||
var updatedWebhook = await WebhookService.GetAsync(webhook.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(updatedWebhook);
|
||||
Assert.AreEqual(UpdatedName, updatedWebhook.Name);
|
||||
Assert.AreEqual(UpdatedDescription, updatedWebhook.Description);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Get_All()
|
||||
{
|
||||
var createdWebhookOne = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
|
||||
var createdWebhookTwo = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.Aliases.ContentDelete }));
|
||||
var createdWebhookThree = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.Aliases.ContentUnpublish }));
|
||||
var createdWebhookOne = await WebhookService.CreateAsync(new Webhook("https://example.com", true, [Guid.NewGuid()], [Constants.WebhookEvents.Aliases.ContentPublish]));
|
||||
var createdWebhookTwo = await WebhookService.CreateAsync(new Webhook("https://example.com", true, [Guid.NewGuid()], [Constants.WebhookEvents.Aliases.ContentDelete]));
|
||||
var createdWebhookThree = await WebhookService.CreateAsync(new Webhook("https://example.com", true, [Guid.NewGuid()], [Constants.WebhookEvents.Aliases.ContentUnpublish]));
|
||||
var webhooks = await WebhookService.GetAllAsync(0, int.MaxValue);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
@@ -59,7 +107,7 @@ public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.MediaSave, "00000000-0000-0000-0000-000000500000")]
|
||||
public async Task Can_Delete(string url, string webhookEvent, Guid key)
|
||||
{
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook(url, true, new[] { key }, new[] { webhookEvent }));
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook(url, true, [key], [webhookEvent]));
|
||||
var webhook = await WebhookService.GetAsync(createdWebhook.Result.Key);
|
||||
|
||||
Assert.IsNotNull(webhook);
|
||||
@@ -71,7 +119,7 @@ public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
[Test]
|
||||
public async Task Can_Create_With_No_EntityKeys()
|
||||
{
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: [Constants.WebhookEvents.Aliases.ContentPublish]));
|
||||
var webhook = await WebhookService.GetAsync(createdWebhook.Result.Key);
|
||||
|
||||
Assert.IsNotNull(webhook);
|
||||
@@ -81,8 +129,8 @@ public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
[Test]
|
||||
public async Task Can_Update()
|
||||
{
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
|
||||
createdWebhook.Result.Events = new[] { Constants.WebhookEvents.Aliases.ContentDelete };
|
||||
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: [Constants.WebhookEvents.Aliases.ContentPublish]));
|
||||
createdWebhook.Result.Events = [Constants.WebhookEvents.Aliases.ContentDelete];
|
||||
await WebhookService.UpdateAsync(createdWebhook.Result);
|
||||
|
||||
var updatedWebhook = await WebhookService.GetAsync(createdWebhook.Result.Key);
|
||||
@@ -94,9 +142,9 @@ public class WebhookServiceTests : UmbracoIntegrationTest
|
||||
[Test]
|
||||
public async Task Can_Get_By_EventName()
|
||||
{
|
||||
var webhook1 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
|
||||
var webhook2 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentUnpublish }));
|
||||
var webhook3 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentUnpublish }));
|
||||
var webhook1 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: [Constants.WebhookEvents.Aliases.ContentPublish]));
|
||||
var webhook2 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: [Constants.WebhookEvents.Aliases.ContentUnpublish]));
|
||||
var webhook3 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: [Constants.WebhookEvents.Aliases.ContentUnpublish]));
|
||||
|
||||
var result = await WebhookService.GetByAliasAsync(Constants.WebhookEvents.Aliases.ContentUnpublish);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user