-
Notifications
You must be signed in to change notification settings - Fork 31
EN-542 Add early access support for new MAPI endpoint `/early-access/… #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pokornyd
merged 5 commits into
kontent-ai:master
from
arguit:EN-542-add-early-access-support-mapi-variant-filter
Sep 2, 2025
+838
−0
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5a7ef81
EN-542 Add early access support for new MAPI endpoint `/early-access/…
eaf8cff
EN-542 Fix comments
167afd0
EN-542 Refactor CompletionStatus and Direction to use enums instead o…
f246a7d
EN-542 Add more tests
3ea0bf1
EN-542 Fix include_content usage description
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
Kontent.Ai.Management.Tests/Data/VariantFilter/VariantFilter.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "item": { | ||
| "id": "4b628214-e4fe-4fe0-b1ff-955df33e1515", | ||
| "name": "Sample Article", | ||
| "codename": "sample_article", | ||
| "type": { | ||
| "id": "ba5cd79d-6d4b-5bed-a681-6aa3a366c8f7", | ||
| "codename": "article" | ||
| }, | ||
| "collection": { | ||
| "id": "00000000-0000-0000-0000-000000000000", | ||
| "codename": "default" | ||
| }, | ||
| "spaces": [ | ||
| { | ||
| "id": "00000000-0000-0000-0000-000000000000", | ||
| "codename": "default" | ||
| } | ||
| ], | ||
| "sitemap_locations": [], | ||
| "last_modified": "2024-01-15T10:30:00.000Z" | ||
| } | ||
| }, | ||
| { | ||
| "item": { | ||
| "id": "6a8b4d04-7d3e-4d3c-8b9a-4c7e8f9a1b2c", | ||
| "name": "Another Article", | ||
| "codename": "another_article", | ||
| "type": { | ||
| "id": "ba5cd79d-6d4b-5bed-a681-6aa3a366c8f7", | ||
| "codename": "article" | ||
| }, | ||
| "collection": { | ||
| "id": "00000000-0000-0000-0000-000000000000", | ||
| "codename": "default" | ||
| }, | ||
| "spaces": [ | ||
| { | ||
| "id": "00000000-0000-0000-0000-000000000000", | ||
| "codename": "default" | ||
| } | ||
| ], | ||
| "sitemap_locations": [], | ||
| "external_id": "ext_another_article", | ||
| "last_modified": "2024-01-16T14:45:00.000Z" | ||
| }, | ||
| "variant": { | ||
| "item": { | ||
| "id": "6a8b4d04-7d3e-4d3c-8b9a-4c7e8f9a1b2c", | ||
| "codename": "another_article" | ||
| }, | ||
| "language": { | ||
| "id": "00000000-0000-0000-0000-000000000000", | ||
| "codename": "en-US" | ||
| }, | ||
| "elements": [], | ||
| "last_modified": "2024-01-16T14:45:00.000Z" | ||
| } | ||
| } | ||
| ], | ||
| "pagination": { | ||
| "continuation_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", | ||
| "next_page": "https://manage.kontent.ai/v2/projects/environmentId/early-access/variants/filter?continuation_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" | ||
| } | ||
| } | ||
151 changes: 151 additions & 0 deletions
151
Kontent.Ai.Management.Tests/ManagementClientTests/VariantFilterTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| using FluentAssertions; | ||
| using Kontent.Ai.Management.Models.Shared; | ||
| using Kontent.Ai.Management.Models.VariantFilter; | ||
| using Kontent.Ai.Management.Tests.Base; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Kontent.Ai.Management.Tests.ManagementClientTests; | ||
|
|
||
| public class VariantFilterTests : IClassFixture<FileSystemFixture> | ||
| { | ||
| private readonly FileSystemFixture _fileSystemFixture; | ||
|
|
||
| public VariantFilterTests(FileSystemFixture fileSystemFixture) | ||
| { | ||
| _fileSystemFixture = fileSystemFixture; | ||
| _fileSystemFixture.SetSubFolder("VariantFilter"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FilterVariantsAsync_WithValidRequest_ReturnsVariantFilterListingResponseServerModel() | ||
| { | ||
| var client = _fileSystemFixture.CreateMockClientWithResponse("VariantFilter.json"); | ||
|
|
||
| var request = new VariantFilterRequestModel | ||
| { | ||
| Filters = new VariantFilterFiltersModel | ||
| { | ||
| SearchPhrase = "test", | ||
| Language = Reference.ByCodename("en-US"), | ||
| ContentTypes = new List<Reference> | ||
| { | ||
| Reference.ByCodename("article") | ||
| }, | ||
| CompletionStatuses = new List<string> { "completed" } | ||
| }, | ||
| Order = new VariantFilterOrderModel | ||
| { | ||
| By = "name", | ||
| Direction = "asc" | ||
| } | ||
| }; | ||
|
|
||
| var response = await client.EarlyAccess.FilterVariantsAsync(request); | ||
|
|
||
| response.Should().NotBeNull(); | ||
| response.Should().BeAssignableTo<IListingResponseModel<VariantFilterItemModel>>(); | ||
|
|
||
| var firstItem = response.ToList().First(); | ||
| firstItem.Item.Should().NotBeNull(); | ||
| firstItem.Item.Id.Should().NotBeEmpty(); | ||
| firstItem.Item.Name.Should().NotBeNullOrEmpty(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FilterVariantsAsync_WithNullRequest_ThrowsArgumentNullException() | ||
| { | ||
| var client = _fileSystemFixture.CreateMockClientWithResponse("VariantFilter.json"); | ||
|
|
||
| await Assert.ThrowsAsync<ArgumentNullException>(async () => await client.EarlyAccess.FilterVariantsAsync(null)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FilterVariantsAsync_WithMinimalRequest_ReturnsVariantFilterListingResponseServerModel() | ||
| { | ||
| var client = _fileSystemFixture.CreateMockClientWithResponse("VariantFilter.json"); | ||
|
|
||
| var request = new VariantFilterRequestModel | ||
| { | ||
| Filters = new VariantFilterFiltersModel | ||
| { | ||
| Language = Reference.ByCodename("en-US") | ||
| } | ||
| }; | ||
|
|
||
| var response = await client.EarlyAccess.FilterVariantsAsync(request); | ||
|
|
||
| response.Should().NotBeNull(); | ||
| response.Should().BeAssignableTo<IListingResponseModel<VariantFilterItemModel>>(); | ||
|
|
||
| var firstItem = response.ToList().First(); | ||
| firstItem.Item.Should().NotBeNull(); | ||
| firstItem.Item.Id.Should().NotBeEmpty(); | ||
| firstItem.Item.Name.Should().NotBeNullOrEmpty(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FilterVariantsAsync_WithComplexFilters_ReturnsVariantFilterListingResponseServerModel() | ||
| { | ||
| var client = _fileSystemFixture.CreateMockClientWithResponse("VariantFilter.json"); | ||
|
|
||
| var request = new VariantFilterRequestModel | ||
| { | ||
| Filters = new VariantFilterFiltersModel | ||
| { | ||
| Language = Reference.ByCodename("en-US"), | ||
| ContentTypes = new List<Reference> | ||
| { | ||
| Reference.ByCodename("article"), | ||
| Reference.ByCodename("blog_post") | ||
| }, | ||
| Contributors = new List<UserIdentifier> | ||
| { | ||
| UserIdentifier.ByEmail("[email protected]") | ||
| }, | ||
| CompletionStatuses = new List<string> { "completed", "unfinished" }, | ||
| WorkflowSteps = new List<VariantFilterWorkflowStepsModel> | ||
| { | ||
| new VariantFilterWorkflowStepsModel | ||
| { | ||
| WorkflowReference = Reference.ByCodename("default"), | ||
| WorkflowStepReferences = new List<Reference> | ||
| { | ||
| Reference.ByCodename("draft") | ||
| } | ||
| } | ||
| }, | ||
| TaxonomyGroups = new List<VariantFilterTaxonomyGroupModel> | ||
| { | ||
| new VariantFilterTaxonomyGroupModel | ||
| { | ||
| TaxonomyReference = Reference.ByCodename("categories"), | ||
| TermReferences = new List<Reference> | ||
| { | ||
| Reference.ByCodename("tech") | ||
| }, | ||
| IncludeUncategorized = false | ||
| } | ||
| } | ||
| }, | ||
| Order = new VariantFilterOrderModel | ||
| { | ||
| By = "last_modified", | ||
| Direction = "desc" | ||
| } | ||
| }; | ||
|
|
||
| var response = await client.EarlyAccess.FilterVariantsAsync(request); | ||
|
|
||
| response.Should().NotBeNull(); | ||
| response.Should().BeAssignableTo<IListingResponseModel<VariantFilterItemModel>>(); | ||
|
|
||
| var firstItem = response.ToList().First(); | ||
arguit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| firstItem.Item.Should().NotBeNull(); | ||
arguit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| firstItem.Item.Id.Should().NotBeEmpty(); | ||
| firstItem.Item.Name.Should().NotBeNullOrEmpty(); | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
Kontent.Ai.Management.Tests/Modules/UrlBuilder/VariantFilterTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace Kontent.Ai.Management.Tests.Modules.UrlBuilder; | ||
|
|
||
| public partial class EndpointUrlBuilderTests | ||
| { | ||
| [Fact] | ||
| public void BuildVariantFilterUrl_ReturnsCorrectUrl() | ||
| { | ||
| var result = _builder.BuildVariantFilterUrl(); | ||
|
|
||
| result.Should().Be($"{ENDPOINT}/projects/{ENVIRONMENT_ID}/early-access/variants/filter"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using Kontent.Ai.Management.Models.Shared; | ||
| using Kontent.Ai.Management.Models.VariantFilter; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Kontent.Ai.Management; | ||
|
|
||
| /// <summary> | ||
| /// Represents a set of early access Content Management API requests. | ||
arguit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// These features are experimental and may change or be removed in future versions. | ||
| /// </summary> | ||
| public interface IManagementClientEarlyAccess | ||
| { | ||
| /// <summary> | ||
| /// Returns listing of filtered variants. | ||
| /// This is an early access feature that may change or be removed in future versions. | ||
| /// </summary> | ||
| /// <param name="variantFilterRequest">The variant filter request containing filters and ordering options.</param> | ||
| /// <returns>The <see cref="IListingResponseModel{VariantFilterItemModel}"/> instance representing the filtered variants.</returns> | ||
| Task<IListingResponseModel<VariantFilterItemModel>> FilterVariantsAsync(VariantFilterRequestModel variantFilterRequest); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| using Kontent.Ai.Management.Models.Shared; | ||
| using Kontent.Ai.Management.Models.VariantFilter; | ||
| using Kontent.Ai.Management.Modules.ActionInvoker; | ||
| using Kontent.Ai.Management.Modules.UrlBuilder; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Kontent.Ai.Management; | ||
|
|
||
| /// <summary> | ||
| /// Provides access to early access Content Management API features. | ||
| /// These features are experimental and may change or be removed in future versions. | ||
| /// </summary> | ||
| public sealed class ManagementClientEarlyAccess : IManagementClientEarlyAccess | ||
| { | ||
| private readonly ActionInvoker _actionInvoker; | ||
| private readonly EndpointUrlBuilder _urlBuilder; | ||
|
|
||
| internal ManagementClientEarlyAccess(ActionInvoker actionInvoker, EndpointUrlBuilder urlBuilder) | ||
| { | ||
| _actionInvoker = actionInvoker ?? throw new ArgumentNullException(nameof(actionInvoker)); | ||
| _urlBuilder = urlBuilder ?? throw new ArgumentNullException(nameof(urlBuilder)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<IListingResponseModel<VariantFilterItemModel>> FilterVariantsAsync(VariantFilterRequestModel variantFilterRequest) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(variantFilterRequest); | ||
|
|
||
| var endpointUrl = _urlBuilder.BuildVariantFilterUrl(); | ||
| var response = await _actionInvoker.InvokeMethodAsync<VariantFilterRequestModel, VariantFilterListingResponseServerModel>(endpointUrl, HttpMethod.Post, variantFilterRequest); | ||
|
|
||
| return new ListingResponseModel<VariantFilterItemModel>( | ||
| GetNextListingPageAsync<VariantFilterListingResponseServerModel, VariantFilterItemModel>, | ||
| response.Pagination?.Token, | ||
| endpointUrl, | ||
| response.Data); | ||
| } | ||
|
|
||
| private async Task<IListingResponse<TModel>> GetNextListingPageAsync<TListingResponse, TModel>(string continuationToken, string url) | ||
| where TListingResponse : IListingResponse<TModel> | ||
| { | ||
| var headers = new Dictionary<string, string> | ||
| { | ||
| { "x-continuation", continuationToken } | ||
| }; | ||
| var response = await _actionInvoker.InvokeReadOnlyMethodAsync<TListingResponse>(url, HttpMethod.Get, headers); | ||
|
|
||
| return response; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.