Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For alignment with the main project, perhaps namespace and folder should be: Umbraco.Cms.Tests.Integration.ManagementApi.Controllers.DocumentType.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, "[email protected]", "[email protected]", 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -132,7 +133,9 @@ protected string GetManagementApiUrl<T>(Expression<Func<T, object>> methodSelect
}


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(
Expand Down