Skip to content
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

refactor: simplify e2e tests #471

Merged
merged 4 commits into from
Jul 31, 2023
Merged
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
14 changes: 8 additions & 6 deletions Vonage.Test.Unit/ProactiveConnect/Events/GetEvents/E2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Vonage.Test.Unit.ProactiveConnect.Events.GetEvents
{
[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(SerializationTest).Namespace)
Expand All @@ -25,12 +26,13 @@ public async Task GetEvents()
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
var result = await this.Helper.VonageClient.ProactiveConnectClient.GetEventsAsync(GetEventsRequest
.Build()
.WithPage(25)
.WithPageSize(50)
.Create());
result.Should().BeSuccess();
await this.Helper.VonageClient.ProactiveConnectClient.GetEventsAsync(GetEventsRequest
.Build()
.WithPage(25)
.WithPageSize(50)
.Create())
.Should()
.BeSuccessAsync(SerializationTest.VerifyResponse);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,45 @@ public void ShouldDeserialize200() =>
this.helper.Serializer
.DeserializeObject<PaginationResult<EmbeddedEvents>>(this.helper.GetResponseJson())
.Should()
.BeSuccess(success =>
{
success.Page.Should().Be(1);
success.PageSize.Should().Be(100);
success.TotalItems.Should().Be(1);
success.TotalPages.Should().Be(1);
success.Links.Self.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Links.Previous.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Links.Next.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Links.First.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Embedded.Events.Should().HaveCount(2);
var firstEvent = success.Embedded.Events.ToList()[0];
var secondEvent = success.Embedded.Events.ToList()[1];
firstEvent.OccurredAt.Should().Be(DateTimeOffset.Parse("2022-08-07T13:18:21.970Z"));
firstEvent.Type.Should().Be(BulkEventType.ActionCallSucceeded);
firstEvent.Id.Should().Be(new Guid("e8e1eb4d-61e0-4099-8fa7-c96f1c0764ba"));
firstEvent.JobId.Should().Be(new Guid("c68e871a-c239-474d-a905-7b95f4563b7e"));
firstEvent.ActionId.Should().Be(new Guid("26c5bbe2-113e-4201-bd93-f69e0a03d17f"));
firstEvent.RunId.Should().Be(new Guid("7d0d4e5f-6453-4c63-87cf-f95b04377324"));
firstEvent.RecipientId.Should().Be("14806904549");
firstEvent.SourceContext.Should().Be("et-e4ab4b75-9e7c-4f26-9328-394a5b842648");
firstEvent.Data.ToString().Should().Be(
"{\"url\":\"https://postman-echo.com/post\",\"args\":{},\"data\":{\"from\":\"\"},\"form\":{},\"json\":{\"from\":\"\"},\"files\":{},\"headers\":{\"host\":\"postman-echo.com\",\"user-agent\":\"got (https://github.com/sindresorhus/got)\",\"content-type\":\"application/json\",\"content-length\":\"11\",\"accept-encoding\":\"gzip, deflate, br\",\"x-amzn-trace-id\":\"Root=1-62efbb9e-53636b7b794accb87a3d662f\",\"x-forwarded-port\":\"443\",\"x-nexmo-trace-id\":\"8a6fed94-7296-4a39-9c52-348f12b4d61a\",\"x-forwarded-proto\":\"https\"}}");
secondEvent.OccurredAt.Should().Be(DateTimeOffset.Parse("2022-08-07T13:18:20.289Z"));
secondEvent.Type.Should().Be(BulkEventType.RecipientResponse);
secondEvent.Id.Should().Be(new Guid("8c8e9894-81be-4f6e-88d4-046b6c70ff8c"));
secondEvent.JobId.Should().Be(new Guid("c68e871a-c239-474d-a905-7b95f4563b7e"));
secondEvent.ActionId.Should().Be(new Guid("26c5bbe2-113e-4201-bd93-f69e0a03d17f"));
secondEvent.RunId.Should().Be(new Guid("7d0d4e5f-6453-4c63-87cf-f95b04377324"));
secondEvent.RecipientId.Should().Be("441632960758");
secondEvent.SourceContext.Should().Be("et-e4ab4b75-9e7c-4f26-9328-394a5b842648");
secondEvent.Data.ToString().Should()
.Be("{\"from\":\"441632960411\",\"text\":\"Erin J. Yearby\"}");
});
.BeSuccess(VerifyResponse);

internal static void VerifyResponse(PaginationResult<EmbeddedEvents> success)
{
success.Page.Should().Be(1);
success.PageSize.Should().Be(100);
success.TotalItems.Should().Be(1);
success.TotalPages.Should().Be(1);
success.Links.Self.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Links.Previous.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Links.Next.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Links.First.Href.Should()
.Be(new Uri("https://api-eu.vonage.com/v0.1/bulk/events?page_size=100&page=1"));
success.Embedded.Events.Should().HaveCount(2);
var firstEvent = success.Embedded.Events.ToList()[0];
var secondEvent = success.Embedded.Events.ToList()[1];
firstEvent.OccurredAt.Should().Be(DateTimeOffset.Parse("2022-08-07T13:18:21.970Z"));
firstEvent.Type.Should().Be(BulkEventType.ActionCallSucceeded);
firstEvent.Id.Should().Be(new Guid("e8e1eb4d-61e0-4099-8fa7-c96f1c0764ba"));
firstEvent.JobId.Should().Be(new Guid("c68e871a-c239-474d-a905-7b95f4563b7e"));
firstEvent.ActionId.Should().Be(new Guid("26c5bbe2-113e-4201-bd93-f69e0a03d17f"));
firstEvent.RunId.Should().Be(new Guid("7d0d4e5f-6453-4c63-87cf-f95b04377324"));
firstEvent.RecipientId.Should().Be("14806904549");
firstEvent.SourceContext.Should().Be("et-e4ab4b75-9e7c-4f26-9328-394a5b842648");
firstEvent.Data.ToString().Should().Be(
"{\"url\":\"https://postman-echo.com/post\",\"args\":{},\"data\":{\"from\":\"\"},\"form\":{},\"json\":{\"from\":\"\"},\"files\":{},\"headers\":{\"host\":\"postman-echo.com\",\"user-agent\":\"got (https://github.com/sindresorhus/got)\",\"content-type\":\"application/json\",\"content-length\":\"11\",\"accept-encoding\":\"gzip, deflate, br\",\"x-amzn-trace-id\":\"Root=1-62efbb9e-53636b7b794accb87a3d662f\",\"x-forwarded-port\":\"443\",\"x-nexmo-trace-id\":\"8a6fed94-7296-4a39-9c52-348f12b4d61a\",\"x-forwarded-proto\":\"https\"}}");
secondEvent.OccurredAt.Should().Be(DateTimeOffset.Parse("2022-08-07T13:18:20.289Z"));
secondEvent.Type.Should().Be(BulkEventType.RecipientResponse);
secondEvent.Id.Should().Be(new Guid("8c8e9894-81be-4f6e-88d4-046b6c70ff8c"));
secondEvent.JobId.Should().Be(new Guid("c68e871a-c239-474d-a905-7b95f4563b7e"));
secondEvent.ActionId.Should().Be(new Guid("26c5bbe2-113e-4201-bd93-f69e0a03d17f"));
secondEvent.RunId.Should().Be(new Guid("7d0d4e5f-6453-4c63-87cf-f95b04377324"));
secondEvent.RecipientId.Should().Be("441632960758");
secondEvent.SourceContext.Should().Be("et-e4ab4b75-9e7c-4f26-9328-394a5b842648");
secondEvent.Data.ToString().Should()
.Be("{\"from\":\"441632960411\",\"text\":\"Erin J. Yearby\"}");
}
}
}
66 changes: 0 additions & 66 deletions Vonage.Test.Unit/ProactiveConnect/Events/GetEvents/UseCaseTest.cs

This file was deleted.

47 changes: 39 additions & 8 deletions Vonage.Test.Unit/ProactiveConnect/Items/CreateItem/E2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Vonage.Test.Unit.ProactiveConnect.Items.CreateItem
{
[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(SerializationTest).Namespace)
Expand All @@ -25,14 +26,44 @@ public async Task CreateItem()
.UsingPost())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
var result = await this.Helper.VonageClient.ProactiveConnectClient.CreateItemAsync(CreateItemRequest
.Build()
.WithListId(new Guid("95a462d3-ed87-4aa5-9d91-098e08093b0b"))
.WithCustomData(new KeyValuePair<string, object>("value1", "value"))
.WithCustomData(new KeyValuePair<string, object>("value2", 0))
.WithCustomData(new KeyValuePair<string, object>("value3", true))
.Create());
result.Should().BeSuccess();
await this.Helper.VonageClient.ProactiveConnectClient.CreateItemAsync(CreateItemRequest
.Build()
.WithListId(new Guid("95a462d3-ed87-4aa5-9d91-098e08093b0b"))
.WithCustomData(new KeyValuePair<string, object>("value1", "value"))
.WithCustomData(new KeyValuePair<string, object>("value2", 0))
.WithCustomData(new KeyValuePair<string, object>("value3", true))
.Create())
.Should()
.BeSuccessAsync(SerializationTest.VerifyCreatedItem);
}

[Fact]
public async Task CreateItemWithComplexObjects()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v0.1/bulk/lists/95a462d3-ed87-4aa5-9d91-098e08093b0b/items")
.WithHeader("Authorization", "Bearer *")
.WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerializeComplexObject)))
.UsingPost())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.ProactiveConnectClient.CreateItemAsync(CreateItemRequest
.Build()
.WithListId(new Guid("95a462d3-ed87-4aa5-9d91-098e08093b0b"))
.WithCustomData(new KeyValuePair<string, object>("fizz", new {Foo = "bar"}))
.WithCustomData(new KeyValuePair<string, object>("baz", 2))
.WithCustomData(new KeyValuePair<string, object>("Bat", "qux"))
.WithCustomData(new KeyValuePair<string, object>("more_items", new object[]
{
1,
2,
"three",
true,
new {Foo = "bar"},
}))
.Create())
.Should()
.BeSuccessAsync(SerializationTest.VerifyCreatedItem);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ public void ShouldDeserialize200() =>
this.helper.Serializer
.DeserializeObject<ListItem>(this.helper.GetResponseJson())
.Should()
.BeSuccess(success =>
{
success.Id.Should().Be(new Guid("29192c4a-4058-49da-86c2-3e349d1065b7"));
success.CreatedAt.Should().Be(DateTimeOffset.Parse("2022-06-19T17:59:28.085Z"));
success.UpdatedAt.Should().Be(DateTimeOffset.Parse("2022-06-19T17:59:28.085Z"));
success.ListId.Should().Be(new Guid("4cb98f71-a879-49f7-b5cf-2314353eb52c"));
success.Data["value1"].ToString().Should().Be("value");
int.Parse(success.Data["value2"].ToString()).Should().Be(0);
bool.Parse(success.Data["value3"].ToString()).Should().BeTrue();
});
.BeSuccess(VerifyCreatedItem);

[Fact]
public void ShouldSerialize() =>
Expand Down Expand Up @@ -67,5 +58,16 @@ public void ShouldSerializeComplexObject() =>
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

internal static void VerifyCreatedItem(ListItem success)
{
success.Id.Should().Be(new Guid("29192c4a-4058-49da-86c2-3e349d1065b7"));
success.CreatedAt.Should().Be(DateTimeOffset.Parse("2022-06-19T17:59:28.085Z"));
success.UpdatedAt.Should().Be(DateTimeOffset.Parse("2022-06-19T17:59:28.085Z"));
success.ListId.Should().Be(new Guid("4cb98f71-a879-49f7-b5cf-2314353eb52c"));
success.Data["value1"].ToString().Should().Be("value");
int.Parse(success.Data["value2"].ToString()).Should().Be(0);
bool.Parse(success.Data["value3"].ToString()).Should().BeTrue();
}
}
}
72 changes: 0 additions & 72 deletions Vonage.Test.Unit/ProactiveConnect/Items/CreateItem/UseCaseTest.cs

This file was deleted.

Loading
Loading