From 9f2d404ca39d5e55af9147c41d3cb31f2c4e727f Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 23 Sep 2025 13:56:52 +0200 Subject: [PATCH] Add test for sibling endpoint returning parent id even when its a folder (#20118) * Improve GetManagementApiUrl to use the globally defined default version if not specified on the controller * Add a test to check logic introduced in #20083 * Update tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs Co-authored-by: Andy Butland * Update tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs Co-authored-by: Andy Butland --------- Co-authored-by: Andy Butland --- .../DocumentTypeSiblingControllerTests.cs | 60 +++++++++++++++++++ .../UmbracoTestServerTestBase.cs | 5 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs diff --git a/tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs b/tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs new file mode 100644 index 0000000000..5242716a35 --- /dev/null +++ b/tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs @@ -0,0 +1,60 @@ +using System.Linq.Expressions; +using System.Net.Http.Json; +using NUnit.Framework; +using Umbraco.Cms.Api.Common.ViewModels.Pagination; +using Umbraco.Cms.Api.Management.Controllers.DocumentType.Tree; +using Umbraco.Cms.Api.Management.ViewModels.Tree; +using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Services.OperationStatus; +using Umbraco.Cms.Tests.Common.Builders; + +namespace Umbraco.Cms.Tests.Integration.ManagementApi.Trees; + +[TestFixture] +internal sealed class DocumentTypeSiblingControllerTests : ManagementApiTest +{ + private IContentTypeContainerService ContentTypeContainerService => GetRequiredService(); + + private ContentTypeService ContentTypeService => (ContentTypeService)GetRequiredService(); + + protected override Expression> MethodSelector => + x => x.Siblings(CancellationToken.None, Guid.Empty, 0, 0, false); + + [Test] + public async Task Document_Type_Siblings_Under_Folder_Have_Correct_Parent() + { + // create folder + Attempt folderResult = + await ContentTypeContainerService.CreateAsync(null, "Root Container", null, Constants.Security.SuperUserKey); + + // create contentTypeOne + IContentType contentTypeOne = ContentTypeBuilder.CreateBasicContentType(); + contentTypeOne.Alias = "contentTypeOne"; + contentTypeOne.ParentId = folderResult.Result.Id; + contentTypeOne.Variations = ContentVariation.Nothing; + ContentTypeService.Save(contentTypeOne); + + // create contentTypeTwo + IContentType contentTypeTwo = ContentTypeBuilder.CreateBasicContentType(); + contentTypeTwo.Alias = "contentTypeTwo"; + contentTypeTwo.ParentId = folderResult.Result.Id; + contentTypeTwo.Variations = ContentVariation.Nothing; + ContentTypeService.Save(contentTypeTwo); + + // get siblings of doctype one + await AuthenticateClientAsync(Client, "test@test.test", "test@test.test", true); + var siblingsResponse = await GetManagementApiResponseAsync(contentTypeOne.Key); + var responseModel = await siblingsResponse.Content.ReadFromJsonAsync>(); + + Assert.IsTrue(responseModel.Items.All(i => i.Parent!.Id == folderResult.Result.Key)); + } + + private async Task GetManagementApiResponseAsync(Guid target) + { + var url = GetManagementApiUrl(x => + x.Siblings(CancellationToken.None, target, 10, 10, false)); + return await Client.GetAsync(url); + } +} diff --git a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 134e06ef64..19bf18c5b7 100644 --- a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Cms.Api.Delivery.Controllers.Content; @@ -132,7 +133,9 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest } - methodParams["version"] = method?.GetCustomAttribute()?.Versions?.First().MajorVersion.ToString(); + methodParams["version"] = + method?.GetCustomAttribute()?.Versions?.First().MajorVersion.ToString() // get it from the attribute + ?? Factory.Services.GetRequiredService>()?.Value.DefaultApiVersion.MajorVersion.ToString(); // or use the default version from options if (method == null) { throw new MissingMethodException(