Skip to content

Commit

Permalink
feat: implement GetSessions on ExperienceComposer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 21, 2024
1 parent ea3ec87 commit 53d26c0
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"count": 1,
"items": [
{
"id": "1248e7070b81464c9789f46ad10e7764",
"sessionId": "flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN",
"applicationId": "93e36bb9-b72c-45b6-a9ea-5c37dbc49906",
"createdAt": 1437676551000,
"callbackUrl": "https://example.com/video/events",
"updatedAt": 1437676551000,
"name": "Composed stream for Live event #1",
"url": "https://example.com/",
"resolution": "720x1280",
"status": "failed",
"streamId": "e32445b743678c98230f238",
"reason": "Could not load URL"
}
]
}
59 changes: 59 additions & 0 deletions Vonage.Test/Video/ExperienceComposer/GetSessions/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Vonage.Test.Common.Extensions;
using Vonage.Video.ExperienceComposer.GetSessions;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Test.Video.ExperienceComposer.GetSessions;

[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(E2ETest).Namespace)
{
}

[Fact]
public async Task GetSessions()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render")
.WithParam("offset", "150")
.WithParam("count", "150")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.VideoClient.ExperienceComposerClient
.GetSessionsAsync(GetSessionsRequest
.Build()
.WithApplicationId(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a"))
.WithCount(150)
.WithOffset(150)
.Create())
.Should()
.BeSuccessAsync(SerializationTest.BuildExpectedResponse());
}

[Fact]
public async Task GetSessionsWithDefaultParameters()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render")
.WithParam("offset", "0")
.WithParam("count", "50")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.VideoClient.ExperienceComposerClient
.GetSessionsAsync(GetSessionsRequest
.Build()
.WithApplicationId(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a"))
.Create())
.Should()
.BeSuccessAsync(SerializationTest.BuildExpectedResponse());
}
}
105 changes: 105 additions & 0 deletions Vonage.Test/Video/ExperienceComposer/GetSessions/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using Vonage.Test.Common.Extensions;
using Vonage.Video.ExperienceComposer.GetSessions;
using Xunit;

namespace Vonage.Test.Video.ExperienceComposer.GetSessions;

[Trait("Category", "Request")]
public class RequestBuilderTest
{
private const int ValidOffset = 100;
private const int ValidCount = 100;
private readonly Guid validApplicationId = Guid.NewGuid();

[Fact]
public void Build_ShouldHaveDefaultOffset() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.Create()
.Map(request => request.Offset)
.Should()
.BeSuccess(0);

[Fact]
public void Build_ShouldHaveDefaultCount() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.Create()
.Map(request => request.Count)
.Should()
.BeSuccess(50);

[Fact]
public void Build_ShouldReturnFailure_GivenCountIsHigherThanOneThousand() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.WithCount(1001)
.Create()
.Should()
.BeParsingFailure("Count cannot be higher than 1000.");

[Fact]
public void Build_ShouldReturnFailure_GivenCountIsLowerThanFifty() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.WithCount(49)
.Create()
.Should()
.BeParsingFailure("Count cannot be lower than 50.");

[Fact]
public void Build_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
GetSessionsRequest
.Build()
.WithApplicationId(Guid.Empty)
.Create()
.Should()
.BeParsingFailure("ApplicationId cannot be empty.");

[Fact]
public void Build_ShouldReturnFailure_GivenOffsetIsLowerThanZero() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.WithOffset(-1)
.Create()
.Should()
.BeParsingFailure("Offset cannot be lower than 0.");

[Fact]
public void Build_ShouldSetApplicationId() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.Create()
.Map(request => request.ApplicationId)
.Should()
.BeSuccess(this.validApplicationId);

[Fact]
public void Build_ShouldSetCount() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.WithCount(ValidCount)
.Create()
.Map(request => request.Count)
.Should()
.BeSuccess(ValidCount);

[Fact]
public void Build_ShouldSetOffset() =>
GetSessionsRequest
.Build()
.WithApplicationId(this.validApplicationId)
.WithOffset(ValidOffset)
.Create()
.Map(request => request.Offset)
.Should()
.BeSuccess(ValidOffset);
}
31 changes: 31 additions & 0 deletions Vonage.Test/Video/ExperienceComposer/GetSessions/RequestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Vonage.Test.Common.Extensions;
using Vonage.Video.ExperienceComposer.GetSessions;
using Xunit;

namespace Vonage.Test.Video.ExperienceComposer.GetSessions;

[Trait("Category", "Request")]
public class RequestTest
{
[Theory]
[InlineData(null, null, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=0&count=50")]
[InlineData(100, null, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=0&count=100")]
[InlineData(null, 100, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=100&count=50")]
[InlineData(100, 100, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=100&count=100")]
public void GetEndpointPath_ShouldReturnApiEndpoint(int? count, int? offset, string expectedEndpoint)
{
var builder = GetSessionsRequest.Build().WithApplicationId(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a"));
if (count.HasValue)
{
builder = builder.WithCount(count.Value);
}

if (offset.HasValue)
{
builder = builder.WithOffset(offset.Value);
}

builder.Create().Map(request => request.GetEndpointPath()).Should().BeSuccess(expectedEndpoint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Vonage.Serialization;
using Vonage.Server;
using Vonage.Test.Common;
using Vonage.Test.Common.Extensions;
using Vonage.Video.ExperienceComposer;
using Vonage.Video.ExperienceComposer.GetSessions;
using Xunit;

namespace Vonage.Test.Video.ExperienceComposer.GetSessions;

[Trait("Category", "Serialization")]
public class SerializationTest
{
private readonly SerializationTestHelper helper = new SerializationTestHelper(
typeof(SerializationTest).Namespace,
JsonSerializerBuilder.BuildWithCamelCase());

[Fact]
public void ShouldDeserialize200() => this.helper.Serializer
.DeserializeObject<GetSessionsResponse>(this.helper.GetResponseJson())
.Should()
.BeSuccess(BuildExpectedResponse());

internal static GetSessionsResponse BuildExpectedResponse() => new GetSessionsResponse(1, new[]
{
new Session("1248e7070b81464c9789f46ad10e7764",
"flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN",
new Guid("93e36bb9-b72c-45b6-a9ea-5c37dbc49906"),
1437676551000,
new Uri("https://example.com/video/events"),
1437676551000,
"Composed stream for Live event #1",
new Uri("https://example.com/"),
RenderResolution.HighDefinitionPortrait,
SessionStatus.Failed,
"e32445b743678c98230f238",
"Could not load URL"),
});
}
3 changes: 3 additions & 0 deletions Vonage.Test/Vonage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,9 @@
<None Update="Video\ExperienceComposer\GetSession\Data\ShouldDeserialize200-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Video\ExperienceComposer\GetSessions\Data\ShouldDeserialize200-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
12 changes: 12 additions & 0 deletions Vonage/Video/ExperienceComposer/ExperienceComposerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Vonage.Common.Monads;
using Vonage.Serialization;
using Vonage.Video.ExperienceComposer.GetSession;
using Vonage.Video.ExperienceComposer.GetSessions;

namespace Vonage.Video.ExperienceComposer;

Expand All @@ -26,4 +27,15 @@ internal ExperienceComposerClient(VonageHttpClientConfiguration configuration) =
/// </returns>
public Task<Result<Session>> GetSessionAsync(Result<GetSessionRequest> request) =>
this.vonageClient.SendWithResponseAsync<GetSessionRequest, Session>(request);

/// <summary>
/// Retrieves all experience composer sessions in an application.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>
/// A success state with the archive if the operation succeeded. A failure state with the error message if it
/// failed.
/// </returns>
public Task<Result<GetSessionsResponse>> GetSessionsAsync(Result<GetSessionsRequest> request) =>
this.vonageClient.SendWithResponseAsync<GetSessionsRequest, GetSessionsResponse>(request);
}
44 changes: 44 additions & 0 deletions Vonage/Video/ExperienceComposer/GetSessions/GetSessionsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Net.Http;
using Vonage.Common.Client;
using Vonage.Common.Client.Builders;

namespace Vonage.Video.ExperienceComposer.GetSessions;

/// <summary>
/// Represents a request to retrieve sessions.
/// </summary>
public readonly struct GetSessionsRequest : IVonageRequest, IHasApplicationId
{
/// <inheritdoc />
public Guid ApplicationId { get; internal init; }

/// <summary>
/// Set a count query parameter to limit the number of experience composers to be returned. The default number of
/// archives returned is 50 (or fewer, if there are fewer than 50 archives). The default is 50 and the maximum is 1000
/// </summary>
public int Count { get; internal init; }

/// <summary>
/// Set an offset query parameters to specify the index offset of the first experience composer. 0 is offset of the
/// most recently started archive (excluding deleted archive). 1 is the offset of the experience composer that started
/// prior to the most recent composer. The default value is 0.
/// </summary>
public int Offset { get; internal init; }

/// <inheritdoc />
public HttpRequestMessage BuildRequestMessage() =>
VonageRequestBuilder
.Initialize(HttpMethod.Get, this.GetEndpointPath())
.Build();

/// <summary>
/// Initializes a builder.
/// </summary>
/// <returns>The builder.</returns>
public static IBuilderForApplicationId Build() => new GetSessionsRequestBuilder();

/// <inheritdoc />
public string GetEndpointPath() =>
$"/v2/project/{this.ApplicationId}/render?offset={this.Offset}&count={this.Count}";
}
Loading

0 comments on commit 53d26c0

Please sign in to comment.