From be4503f51592e93a775924f1b091df8988a8f235 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Thu, 8 Aug 2024 16:09:49 -0600 Subject: [PATCH] - Fix child user pagination parameters (#231) --- CHANGELOG.md | 1 + list_options.go | 16 ++++++++ .../TestUserGetNextChildUserPage.yaml | 37 ++++++++----------- user.go | 2 +- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9352a1..f5ecd1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next Release - Update HTTP logic to use query for GET/DELETE requests and body for POST/PUT/PATCH requests +- Fix parameters for retrieving next page of child users ## v4.5.0 (2024-07-24) diff --git a/list_options.go b/list_options.go index da50470..29d9e88 100644 --- a/list_options.go +++ b/list_options.go @@ -24,3 +24,19 @@ func nextPageParameters(hasMore bool, lastID string, pageSize int) (out *ListOpt } return } + +// nextChildUserPageParameters returns the next page of a paginated collection of child users. +// If pageSize is 0, it will use the default page size +func nextChildUserPageParameters(hasMore bool, lastID string, pageSize int) (out *ListOptions, err error) { + if !hasMore { + err = EndOfPaginationError + return + } + out = &ListOptions{ + AfterID: lastID, + } + if pageSize > 0 { + out.PageSize = pageSize + } + return +} diff --git a/tests/cassettes/TestUserGetNextChildUserPage.yaml b/tests/cassettes/TestUserGetNextChildUserPage.yaml index 3ccd480..ac5920f 100644 --- a/tests/cassettes/TestUserGetNextChildUserPage.yaml +++ b/tests/cassettes/TestUserGetNextChildUserPage.yaml @@ -40,20 +40,20 @@ interactions: X-Download-Options: - noopen X-Ep-Request-Uuid: - - 4d57346d66ad68a3f440b8c700377a24 + - 84cd602b66b53c49f3f9814f00071378 X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb43nuq + - bigweb32nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb3nuq c0f5e722d1 - - extlb2nuq fa152d4755 + - intlb4nuq c0f5e722d1 + - extlb1nuq b6e1b5034c X-Runtime: - - "0.035672" + - "0.143346" X-Version-Label: - - easypost-202408021936-66687f8918-master + - easypost-202408082122-d71f4bb148-master X-Xss-Protection: - 1; mode=block status: 200 OK @@ -67,15 +67,12 @@ interactions: - REDACTED User-Agent: - REDACTED - url: https://api.easypost.com/v2/users/children?before_id=user_181e86f095d64d028676afb1bfdb9774&page_size=5 + url: https://api.easypost.com/v2/users/children?after_id=user_181e86f095d64d028676afb1bfdb9774&page_size=5 method: GET response: - body: '{"children":[{"created_at":"2023-09-20T18:01:26Z","id":"user_5f0c48e7a66b42398740b0149b1bb24c","name":"Test - User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true},{"created_at":"2023-09-20T18:09:24Z","id":"user_97f56192c53d490aa7851087b88618a4","name":"Test - User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true},{"created_at":"2023-11-30T20:12:09Z","id":"user_3d8dac28f4ba42729036133637356d40","name":"Test - User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true},{"created_at":"2024-07-26T19:35:11Z","id":"user_f81b29477fec4243a7de2ecc3c4f4907","name":"Test - User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true},{"created_at":"2024-07-26T20:01:28Z","id":"user_181e86f095d64d028676afb1bfdb9774","name":"Test - User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true}],"has_more":true}' + body: '{"children":[{"created_at":"2024-08-02T22:13:55Z","id":"user_03b5468f836c4cb09c017668747a9b7f","name":"Test + User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true},{"created_at":"2024-08-02T23:15:46Z","id":"user_be313b8dbcf040108b045e7a33cd5fba","name":"Test + User","object":"User","parent_id":"user_a76997d126dd488f8ad22d52301300b0","phone_number":"REDACTED","verified":true}],"has_more":false}' headers: Cache-Control: - private, no-cache, no-store @@ -91,27 +88,25 @@ interactions: - max-age=31536000; includeSubDomains; preload X-Backend: - easypost - X-Canary: - - direct X-Content-Type-Options: - nosniff X-Download-Options: - noopen X-Ep-Request-Uuid: - - 4d57346d66ad68a3f440b8c700377a33 + - 84cd602b66b53c4af3f9814f000713a5 X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb32nuq + - bigweb35nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb4nuq c0f5e722d1 - - extlb2nuq fa152d4755 + - intlb3nuq c0f5e722d1 + - extlb1nuq b6e1b5034c X-Runtime: - - "0.027236" + - "0.027869" X-Version-Label: - - easypost-202408021936-66687f8918-master + - easypost-202408082122-d71f4bb148-master X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/user.go b/user.go index 6a180e4..1aa4d1c 100644 --- a/user.go +++ b/user.go @@ -153,7 +153,7 @@ func (c *Client) GetNextChildUserPageWithPageSizeWithContext(ctx context.Context return } lastID := collection.Children[len(collection.Children)-1].ID - params, err := nextPageParameters(collection.HasMore, lastID, pageSize) + params, err := nextChildUserPageParameters(collection.HasMore, lastID, pageSize) if err != nil { return }