-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement Stop on ExperienceComposer
- Loading branch information
Showing
5 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
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,31 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.Video.ExperienceComposer.Stop; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Video.ExperienceComposer.Stop; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
public E2ETest() : base(typeof(E2ETest).Namespace) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task Stop() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render/EXP-123") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); | ||
await this.Helper.VonageClient.VideoClient.ExperienceComposerClient | ||
.StopAsync(StopRequest.Parse(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a"), "EXP-123")) | ||
.Should() | ||
.BeSuccessAsync(); | ||
} | ||
} |
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,49 @@ | ||
using System; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.Video.ExperienceComposer.Stop; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Video.ExperienceComposer.Stop; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
private const string ValidExperienceComposerId = "EXP-123"; | ||
private readonly Guid validApplicationId = Guid.NewGuid(); | ||
|
||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
StopRequest.Parse(this.validApplicationId, ValidExperienceComposerId) | ||
.Map(request => request.GetEndpointPath()) | ||
.Should() | ||
.BeSuccess($"/v2/project/{this.validApplicationId}/render/EXP-123"); | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
[InlineData(null)] | ||
public void Parse_ShouldReturnFailure_GivenExperienceComposerIdIsEmpty(string invalidId) => | ||
StopRequest.Parse(Guid.NewGuid(), invalidId) | ||
.Should() | ||
.BeParsingFailure("ExperienceComposerId cannot be null or whitespace."); | ||
|
||
[Fact] | ||
public void Parse_ShouldReturnFailure_GivenApplicationIdIsEmpty() => | ||
StopRequest.Parse(Guid.Empty, ValidExperienceComposerId) | ||
.Should() | ||
.BeParsingFailure("ApplicationId cannot be empty."); | ||
|
||
[Fact] | ||
public void Parse_ShouldSetApplicationId() => | ||
StopRequest.Parse(this.validApplicationId, ValidExperienceComposerId) | ||
.Map(request => request.ApplicationId) | ||
.Should() | ||
.BeSuccess(this.validApplicationId); | ||
|
||
[Fact] | ||
public void Parse_ShouldSetExperienceComposerId() => | ||
StopRequest.Parse(this.validApplicationId, ValidExperienceComposerId) | ||
.Map(request => request.ExperienceComposerId) | ||
.Should() | ||
.BeSuccess(ValidExperienceComposerId); | ||
} |
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
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,50 @@ | ||
using System; | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Client.Builders; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Validation; | ||
|
||
namespace Vonage.Video.ExperienceComposer.Stop; | ||
|
||
/// <summary> | ||
/// Represents a request to retrieve a session. | ||
/// </summary> | ||
public readonly struct StopRequest : IVonageRequest, IHasApplicationId | ||
{ | ||
/// <inheritdoc /> | ||
public Guid ApplicationId { get; internal init; } | ||
|
||
/// <summary> | ||
/// ID of the Experience Composer instance | ||
/// </summary> | ||
public string ExperienceComposerId { get; internal init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => | ||
VonageRequestBuilder | ||
.Initialize(HttpMethod.Delete, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/v2/project/{this.ApplicationId}/render/{this.ExperienceComposerId}"; | ||
|
||
/// <summary> | ||
/// Parses the input into a GetEventRequest. | ||
/// </summary> | ||
/// <param name="applicationId">The application Id.</param> | ||
/// <param name="experienceComposerId">The experience composer Id.</param> | ||
/// <returns>A success state with the request if the parsing succeeded. A failure state with an error if it failed.</returns> | ||
public static Result<StopRequest> Parse(Guid applicationId, string experienceComposerId) => | ||
Result<StopRequest> | ||
.FromSuccess(new StopRequest | ||
{ApplicationId = applicationId, ExperienceComposerId = experienceComposerId}) | ||
.Map(InputEvaluation<StopRequest>.Evaluate) | ||
.Bind(evaluation => evaluation.WithRules(VerifyExperienceComposerId, VerifyApplicationId)); | ||
|
||
private static Result<StopRequest> VerifyExperienceComposerId(StopRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.ExperienceComposerId, nameof(ExperienceComposerId)); | ||
|
||
private static Result<StopRequest> VerifyApplicationId(StopRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.ApplicationId, nameof(ApplicationId)); | ||
} |