Skip to content

Commit

Permalink
fix: Add fixes for Tenants List endpoint (#23)
Browse files Browse the repository at this point in the history
* The endpoint returns the list of tenants using the `entries` key
  instead of `items`.
* Endpoint path fixed to prepend `?` to querystring.
* `Cursor` is not a valid element for `ListTenantsRequest`, not used for
  pagination in this endpoint (`before` and `after` are used instead).
  • Loading branch information
adamantike authored Oct 4, 2023
1 parent 9acbc04 commit 59c91d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions knock/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ type Tenant struct {
// Client structs
type ListTenantsRequest struct {
PageSize int `url:"page_size,omitempty"`
Cursor string `url:"page_size,omitempty"`
Before string `url:"before,omitempty"`
After string `url:"after,omitempty"`
TenantID string `url:"tenant_id,omitempty"`
Name string `url:"name,omitempty"`
}

type ListTenantsResponse struct {
Items []*Tenant `json:"items"`
Entries []*Tenant `json:"entries"`
PageInfo *PageInfo `json:"page_info"`
}

Expand Down Expand Up @@ -79,7 +78,7 @@ func (ts *tenantsService) List(ctx context.Context, listReq *ListTenantsRequest)
if err != nil {
return nil, nil, errors.Wrap(err, "error parsing request to list tenants")
}
path := fmt.Sprintf("%s/%s", tenantsAPIBasePath, queryString.Encode())
path := fmt.Sprintf("%s/?%s", tenantsAPIBasePath, queryString.Encode())

req, err := ts.client.newRequest(http.MethodGet, path, listReq, nil)

Expand All @@ -94,7 +93,7 @@ func (ts *tenantsService) List(ctx context.Context, listReq *ListTenantsRequest)
return nil, nil, errors.Wrap(err, "error making request to list tenants")
}

return listRes.Items, listRes.PageInfo, nil
return listRes.Entries, listRes.PageInfo, nil
}
func (ts *tenantsService) Get(ctx context.Context, getTenantRequest *GetTenantRequest) (*Tenant, error) {
path := tenantAPIPath(getTenantRequest.ID)
Expand Down
2 changes: 1 addition & 1 deletion knock/tenants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestTenants_List(t *testing.T) {

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
out := `{"items":[{"__typename":"Tenant","properties":{"name":"cool-tenant-1","settings":{"branding":{"primary_color":"#FFFFFF"}}},"id":"tenant-id","updated_at":"2022-05-17T00:34:18.277163Z"}],"page_info":{"__typename":"PageInfo","after":"big-after","before":null,"page_size":1}}`
out := `{"entries":[{"__typename":"Tenant","properties":{"name":"cool-tenant-1","settings":{"branding":{"primary_color":"#FFFFFF"}}},"id":"tenant-id","updated_at":"2022-05-17T00:34:18.277163Z"}],"page_info":{"__typename":"PageInfo","after":"big-after","before":null,"page_size":1}}`
_, err := w.Write([]byte(out))
c.Assert(err, qt.IsNil)
}))
Expand Down

0 comments on commit 59c91d7

Please sign in to comment.