Skip to content

Commit

Permalink
[feat] Add function to retrieve paginated list of child users (#538)
Browse files Browse the repository at this point in the history
- Add `AllChildren` and `GetNextPageOfChildren` functions to User service
- Add unit tests, cassettes
- Fix straggling back CRUD decorators
- Split BaseUser into explicit User and ReferralCustomer classes
- Add "verified" property to User class for child users
  • Loading branch information
nwithan8 committed Jan 4, 2024
1 parent 8ffd509 commit 26c6c16
Show file tree
Hide file tree
Showing 16 changed files with 748 additions and 119 deletions.
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

0 comments on commit 26c6c16

Please sign in to comment.