Skip to content

Commit 26c6c16

Browse files
authored
[feat] Add function to retrieve paginated list of child users (#538)
- 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
1 parent 8ffd509 commit 26c6c16

File tree

16 files changed

+748
-119
lines changed

16 files changed

+748
-119
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Add `AllChildren` and `GetNextPageOfChildren` functions to `User` service
6+
37
## v6.0.0 (2023-12-06)
48

59
- No changes since `v6.0.0-rc1`, see below.

EasyPost.Tests/Fixture.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,18 @@ internal static ParameterSets.User.CreateChild CreateChild(Dictionary<string, ob
717717
Name = fixture.GetOrNull<string>("name"),
718718
};
719719
}
720+
721+
internal static ParameterSets.User.AllChildren AllChildren(Dictionary<string, object>? fixture)
722+
{
723+
fixture ??= new Dictionary<string, object>();
724+
725+
return new ParameterSets.User.AllChildren
726+
{
727+
PageSize = fixture.GetOrNullInt("page_size"),
728+
BeforeId = fixture.GetOrNull<string>("before_id"),
729+
AfterId = fixture.GetOrNull<string>("after_id"),
730+
};
731+
}
720732
}
721733

722734
internal static class Webhooks

EasyPost.Tests/ServicesTests/UserServiceTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4+
using EasyPost.Exceptions.General;
45
using EasyPost.Models.API;
56
using EasyPost.Tests._Utilities;
67
using EasyPost.Tests._Utilities.Attributes;
@@ -77,6 +78,49 @@ public async Task TestRetrieveMe()
7778
Assert.StartsWith("user_", user.Id);
7879
}
7980

81+
[Fact]
82+
[CrudOperations.Read]
83+
[Testing.Function]
84+
public async Task TestAllChildren()
85+
{
86+
UseVCR("all_children");
87+
88+
ChildUserCollection childUserCollection = await Client.User.AllChildren(new Dictionary<string, object> { { "page_size", Fixtures.PageSize } });
89+
List<User> children = childUserCollection.Children;
90+
91+
Assert.True(children.Count <= Fixtures.PageSize);
92+
foreach (User item in children)
93+
{
94+
Assert.IsType<User>(item);
95+
}
96+
}
97+
98+
[Fact]
99+
[CrudOperations.Read]
100+
[Testing.Function]
101+
public async Task TestGetNextPageOfChildren()
102+
{
103+
UseVCR("get_next_page_of_children");
104+
105+
ChildUserCollection collection = await Client.User.AllChildren(new Dictionary<string, object> { { "page_size", Fixtures.PageSize } });
106+
107+
try
108+
{
109+
ChildUserCollection nextPageCollection = await Client.User.GetNextPageOfChildren(collection);
110+
111+
// 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
112+
Assert.NotEqual(collection.Children[0].Id, nextPageCollection.Children[0].Id);
113+
}
114+
catch (EndOfPaginationError) // There's no second page, that's not a failure
115+
{
116+
Assert.True(true);
117+
}
118+
catch // Any other exception is a failure
119+
{
120+
Assert.True(false);
121+
}
122+
}
123+
80124
[Fact]
81125
[CrudOperations.Create]
82126
[Testing.Function]

EasyPost.Tests/ServicesTests/WithParameters/UserServiceTest.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Threading.Tasks;
33
using EasyPost.Models.API;
4+
using EasyPost.Parameters.User;
45
using EasyPost.Tests._Utilities;
56
using EasyPost.Tests._Utilities.Attributes;
67
using EasyPost.Utilities.Internal.Attributes;
@@ -50,7 +51,28 @@ public async Task TestCreateChild()
5051
}
5152

5253
[Fact]
53-
[CrudOperations.Create]
54+
[CrudOperations.Read]
55+
[Testing.Function]
56+
public async Task TestAllChildren()
57+
{
58+
UseVCR("all_children");
59+
60+
Dictionary<string, object> fixture = new Dictionary<string, object> { { "page_size", Fixtures.PageSize } };
61+
62+
AllChildren parameters = Fixtures.Parameters.Users.AllChildren(fixture);
63+
64+
ChildUserCollection childUserCollection = await Client.User.AllChildren(parameters);
65+
List<User> children = childUserCollection.Children;
66+
67+
Assert.True(children.Count <= Fixtures.PageSize);
68+
foreach (User item in children)
69+
{
70+
Assert.IsType<User>(item);
71+
}
72+
}
73+
74+
[Fact]
75+
[CrudOperations.Update]
5476
[Testing.Function]
5577
public async Task TestUpdateBrand()
5678
{

EasyPost.Tests/cassettes/net/user_service/all_children.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyPost.Tests/cassettes/net/user_service/get_next_page_of_children.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyPost.Tests/cassettes/net/user_service_with_parameters/all_children.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyPost.Tests/cassettes/netstandard/user_service/all_children.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EasyPost.Tests/cassettes/netstandard/user_service/get_next_page_of_children.json

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)