-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EN-238 Add WebSpotlight support via Management Api
- Loading branch information
František Záhora
authored and
František Záhora
committed
Jul 4, 2024
1 parent
24e60b5
commit e0c9db6
Showing
13 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
Kontent.Ai.Management.Tests/Data/WebSpotlight/ActivationWebSpotlightResponse.json
This file contains 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,4 @@ | ||
{ | ||
"enabled": true, | ||
"root_type_id": "0689fcb3-24f1-49f4-b115-e7b816d59e9d" | ||
} |
4 changes: 4 additions & 0 deletions
4
...agement.Tests/Data/WebSpotlight/ActivationWebSpotlightWithProvidedRootTypeIdResponse.json
This file contains 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,4 @@ | ||
{ | ||
"enabled": true, | ||
"root_type_id": "3660e894-bae8-4dcd-9d3e-5fc9205c2ece" | ||
} |
4 changes: 4 additions & 0 deletions
4
Kontent.Ai.Management.Tests/Data/WebSpotlight/DeactivationWebSpotlightResponse.json
This file contains 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,4 @@ | ||
{ | ||
"enabled": false, | ||
"root_type_id": "0689fcb3-24f1-49f4-b115-e7b816d59e9d" | ||
} |
4 changes: 4 additions & 0 deletions
4
Kontent.Ai.Management.Tests/Data/WebSpotlight/GetStatusWebSpotlightResponse.json
This file contains 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,4 @@ | ||
{ | ||
"enabled": true, | ||
"root_type_id": "0689fcb3-24f1-49f4-b115-e7b816d59e9d" | ||
} |
This file contains 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
88 changes: 88 additions & 0 deletions
88
Kontent.Ai.Management.Tests/ManagementClientTests/WebSpotlightTests.cs
This file contains 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,88 @@ | ||
using Kontent.Ai.Management.Models.WebSpotlight; | ||
using Kontent.Ai.Management.Tests.Base; | ||
using System; | ||
using System.Net.Http; | ||
using Xunit; | ||
using static Kontent.Ai.Management.Tests.Base.Scenario; | ||
|
||
namespace Kontent.Ai.Management.Tests.ManagementClientTests; | ||
|
||
public class WebSpotlightTests : IClassFixture<FileSystemFixture> | ||
{ | ||
private static readonly string WebSpotlightBaseUrl = $"{Endpoint}/projects/{ENVIRONMENT_ID}/web-spotlight"; | ||
private readonly Scenario _scenario = new(folder: "WebSpotlight"); | ||
|
||
[Fact] | ||
public async void ActivateWebSpotlight_Returns_EnabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("ActivationWebSpotlightResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var response = await client | ||
.ActivateWebSpotlightAsync(); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.Response(response) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void ActivateWebSpotlight_WithProvidedValidRootType_Returns_EnabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("ActivationWebSpotlightWithProvidedRootTypeIdResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var rootTypeId = Guid.Parse("3660e894-bae8-4dcd-9d3e-5fc9205c2ece"); | ||
var webSpotlightActivateModel = new WebSpotlightActivateModel { RootTypeId = rootTypeId }; | ||
|
||
await client.ActivateWebSpotlightAsync(webSpotlightActivateModel); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.RequestPayload(webSpotlightActivateModel) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void DeactivateWebSpotlight_Returns_DisabledStatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("DeactivationWebSpotlightResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var response = await client | ||
.DeactivateWebSpotlightAsync(); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Put) | ||
.Response(response) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
|
||
[Fact] | ||
public async void GetWebSpotlightStatus_Returns_StatusAndRootTypeId() | ||
{ | ||
var client = _scenario | ||
.WithResponses("GetStatusWebSpotlightResponse.json") | ||
.CreateManagementClient(); | ||
|
||
var response = await client | ||
.GetWebSpotlightStatusAsync(); | ||
|
||
_scenario | ||
.CreateExpectations() | ||
.HttpMethod(HttpMethod.Get) | ||
.Response(response) | ||
.Url(WebSpotlightBaseUrl) | ||
.Validate(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Kontent.Ai.Management.Tests/Modules/UrlBuilder/WebSpotlightTests.cs
This file contains 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 Xunit; | ||
|
||
namespace Kontent.Ai.Management.Tests.Modules.UrlBuilder; | ||
|
||
public partial class EndpointUrlBuilderTests | ||
{ | ||
[Fact] | ||
public void BuildWebSpotlightUrl_ReturnsWebSpotlightUrl() | ||
{ | ||
var expectedUrl = $"{ENDPOINT}/projects/{ENVIRONMENT_ID}/web-spotlight"; | ||
var actualUrl = _builder.BuildWebSpotlightUrl(); | ||
|
||
Assert.Equal(expectedUrl, actualUrl); | ||
} | ||
} |
This file contains 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 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,42 @@ | ||
using Kontent.Ai.Management.Models.WebSpotlight; | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Kontent.Ai.Management; | ||
|
||
/// <summary> | ||
/// Executes requests against the Kontent.ai Management API. | ||
/// </summary> | ||
public partial class ManagementClient | ||
{ | ||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> ActivateWebSpotlightAsync(WebSpotlightActivateModel webSpotlightActivateModel) | ||
{ | ||
ArgumentNullException.ThrowIfNull(webSpotlightActivateModel); | ||
|
||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeMethodAsync<WebSpotlightActivateModel, WebSpotlightModel>(endpointUrl, HttpMethod.Put, webSpotlightActivateModel); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> ActivateWebSpotlightAsync() | ||
{ | ||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeReadOnlyMethodAsync<WebSpotlightModel>(endpointUrl, HttpMethod.Put); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> DeactivateWebSpotlightAsync() | ||
{ | ||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeReadOnlyMethodAsync<WebSpotlightModel>(endpointUrl, HttpMethod.Put); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<WebSpotlightModel> GetWebSpotlightStatusAsync() | ||
{ | ||
var endpointUrl = _urlBuilder.BuildWebSpotlightUrl(); | ||
return await _actionInvoker.InvokeReadOnlyMethodAsync<WebSpotlightModel>(endpointUrl, HttpMethod.Get); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Kontent.Ai.Management/Models/WebSpotlight/WebSpotlightActivateModel.cs
This file contains 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,16 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
|
||
namespace Kontent.Ai.Management.Models.WebSpotlight; | ||
|
||
/// <summary> | ||
/// Represents the web spotlight activation model. | ||
/// </summary> | ||
public class WebSpotlightActivateModel | ||
{ | ||
/// <summary> | ||
/// Gets or sets the web spotlight's Root Type ID. | ||
/// </summary> | ||
[JsonProperty("root_type_id")] | ||
public Guid? RootTypeId { get; set; } | ||
} |
22 changes: 22 additions & 0 deletions
22
Kontent.Ai.Management/Models/WebSpotlight/WebSpotlightModel.cs
This file contains 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,22 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
|
||
namespace Kontent.Ai.Management.Models.WebSpotlight; | ||
|
||
/// <summary> | ||
/// Represents the web spotlight model. | ||
/// </summary> | ||
public class WebSpotlightModel | ||
{ | ||
/// <summary> | ||
/// Gets or sets the web spotlight's Enabled. | ||
/// </summary> | ||
[JsonProperty("enabled")] | ||
public bool Enabled { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the web spotlight's Root Type ID. | ||
/// </summary> | ||
[JsonProperty("root_type_id")] | ||
public Guid? RootTypeId { get; set; } | ||
} |
This file contains 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
11 changes: 11 additions & 0 deletions
11
Kontent.Ai.Management/Modules/UrlBuilder/Templates/WebSpotlightTemplate.cs
This file contains 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,11 @@ | ||
using System; | ||
|
||
namespace Kontent.Ai.Management.Modules.UrlBuilder.Templates; | ||
|
||
internal class WebSpotlightTemplate : UrlTemplate | ||
{ | ||
public override string Url => "/web-spotlight"; | ||
public override string UrlId => throw new InvalidOperationException("Web Spotlight does not have Id Url."); | ||
public override string UrlCodename => throw new InvalidOperationException("Web Spotlight does not have Codename Url."); | ||
public override string UrlExternalId => throw new InvalidOperationException("Web Spotlight does not have External Id Url."); | ||
} |