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 <abutland73@gmail.com>

* Update tests/Umbraco.Tests.Integration/ManagementApi/Trees/DocumentTypeSiblingControllerTests.cs

Co-authored-by: Andy Butland <abutland73@gmail.com>

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Sven Geusens
2025-09-23 13:56:52 +02:00
committed by GitHub
parent 8a2f1bc233
commit 9f2d404ca3
2 changed files with 64 additions and 1 deletions

View File

@@ -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<SiblingsDocumentTypeTreeController>
{
private IContentTypeContainerService ContentTypeContainerService => GetRequiredService<IContentTypeContainerService>();
private ContentTypeService ContentTypeService => (ContentTypeService)GetRequiredService<IContentTypeService>();
protected override Expression<Func<SiblingsDocumentTypeTreeController, object>> 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<EntityContainer, EntityContainerOperationStatus> 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<SubsetViewModel<DocumentTreeItemResponseModel>>();
Assert.IsTrue(responseModel.Items.All(i => i.Parent!.Id == folderResult.Result.Key));
}
private async Task<HttpResponseMessage> GetManagementApiResponseAsync(Guid target)
{
var url = GetManagementApiUrl<SiblingsDocumentTypeTreeController>(x =>
x.Siblings(CancellationToken.None, target, 10, 10, false));
return await Client.GetAsync(url);
}
}

View File

@@ -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<MapToApiVersionAttribute>()?.Versions?.First().MajorVersion.ToString();
methodParams["version"] =
method?.GetCustomAttribute<MapToApiVersionAttribute>()?.Versions?.First().MajorVersion.ToString() // get it from the attribute
?? Factory.Services.GetRequiredService<IOptions<ApiVersioningOptions>>()?.Value.DefaultApiVersion.MajorVersion.ToString(); // or use the default version from options
if (method == null)
{
throw new MissingMethodException(