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

[feat] Add function to retrieve paginated list of child users #538

Merged
merged 9 commits into from
Jan 4, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

- Add `AllChildren` and `GetNextPageOfChildren` functions to `User` service

## v6.0.0 (2023-12-06)

- No changes since `v6.0.0-rc1`, see below.
Expand Down
12 changes: 12 additions & 0 deletions EasyPost.Tests/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,18 @@ internal static ParameterSets.User.CreateChild CreateChild(Dictionary<string, ob
Name = fixture.GetOrNull<string>("name"),
};
}

internal static ParameterSets.User.AllChildren AllChildren(Dictionary<string, object>? fixture)
{
fixture ??= new Dictionary<string, object>();

return new ParameterSets.User.AllChildren
{
PageSize = fixture.GetOrNullInt("page_size"),
BeforeId = fixture.GetOrNull<string>("before_id"),
AfterId = fixture.GetOrNull<string>("after_id"),
};
}
}

internal static class Webhooks
Expand Down
44 changes: 44 additions & 0 deletions EasyPost.Tests/ServicesTests/UserServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost.Exceptions.General;
using EasyPost.Models.API;
using EasyPost.Tests._Utilities;
using EasyPost.Tests._Utilities.Attributes;
Expand Down Expand Up @@ -77,6 +78,49 @@ public async Task TestRetrieveMe()
Assert.StartsWith("user_", user.Id);
}

[Fact]
[CrudOperations.Read]
[Testing.Function]
public async Task TestAllChildren()
{
UseVCR("all_children");

ChildUserCollection childUserCollection = await Client.User.AllChildren(new Dictionary<string, object> { { "page_size", Fixtures.PageSize } });
List<User> children = childUserCollection.Children;

Assert.True(children.Count <= Fixtures.PageSize);
foreach (User item in children)
{
Assert.IsType<User>(item);
}
}

[Fact]
[CrudOperations.Read]
[Testing.Function]
public async Task TestGetNextPageOfChildren()
{
UseVCR("get_next_page_of_children");

ChildUserCollection collection = await Client.User.AllChildren(new Dictionary<string, object> { { "page_size", Fixtures.PageSize } });

try
{
ChildUserCollection nextPageCollection = await Client.User.GetNextPageOfChildren(collection);

// If the first ID in the next page is the same as the first ID in the current page, then we didn't get the next page
Assert.NotEqual(collection.Children[0].Id, nextPageCollection.Children[0].Id);
}
catch (EndOfPaginationError) // There's no second page, that's not a failure
{
Assert.True(true);
}
catch // Any other exception is a failure
{
Assert.True(false);
}
}

[Fact]
[CrudOperations.Create]
[Testing.Function]
Expand Down
24 changes: 23 additions & 1 deletion EasyPost.Tests/ServicesTests/WithParameters/UserServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost.Models.API;
using EasyPost.Parameters.User;
using EasyPost.Tests._Utilities;
using EasyPost.Tests._Utilities.Attributes;
using EasyPost.Utilities.Internal.Attributes;
Expand Down Expand Up @@ -50,7 +51,28 @@ public async Task TestCreateChild()
}

[Fact]
[CrudOperations.Create]
[CrudOperations.Read]
[Testing.Function]
public async Task TestAllChildren()
{
UseVCR("all_children");

Dictionary<string, object> fixture = new Dictionary<string, object> { { "page_size", Fixtures.PageSize } };

AllChildren parameters = Fixtures.Parameters.Users.AllChildren(fixture);

ChildUserCollection childUserCollection = await Client.User.AllChildren(parameters);
List<User> children = childUserCollection.Children;

Assert.True(children.Count <= Fixtures.PageSize);
foreach (User item in children)
{
Assert.IsType<User>(item);
}
}

[Fact]
[CrudOperations.Update]
[Testing.Function]
public async Task TestUpdateBrand()
{
Expand Down
48 changes: 48 additions & 0 deletions EasyPost.Tests/cassettes/net/user_service/all_children.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading