Skip to content

Commit

Permalink
fixes parameters for UpdateAccessUserSeat
Browse files Browse the repository at this point in the history
  • Loading branch information
auyer committed Jan 17, 2024
1 parent ed671df commit 83c7769
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions access_seats.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type UpdateAccessUserSeatResponse struct {
ResultInfo `json:"result_info"`
}

// UpdateAccessUserSeat updates a Access User Seat.
// UpdateAccessUserSeat updates a single Access User Seat.
//
// API documentation: https://developers.cloudflare.com/api/operations/zero-trust-seats-update-a-user-seat
func (api *API) UpdateAccessUserSeat(ctx context.Context, rc *ResourceContainer, params UpdateAccessUserSeatParams) ([]AccessUpdateAccessUserSeatResult, error) {
Expand All @@ -53,7 +53,8 @@ func (api *API) UpdateAccessUserSeat(ctx context.Context, rc *ResourceContainer,
rc.Identifier,
)

res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params)
// this requests expects an array of params, but this method only accepts a single param
res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, []UpdateAccessUserSeatParams{params})
if err != nil {
return []AccessUpdateAccessUserSeatResult{}, fmt.Errorf("%s: %w", errMakeRequestError, err)
}
Expand Down
9 changes: 9 additions & 0 deletions access_seats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -34,6 +35,14 @@ func TestUpdateAccessUserSeat(t *testing.T) {

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method)

req := []UpdateAccessUserSeatParams{}

// Try to decode the request body into the struct.
err := json.NewDecoder(r.Body).Decode(&req)
assert.NoError(t, err, "Failed to decode request body into UpdateAccessUserSeatParams")
assert.Equal(t, len(req), 1, "Expected 1 seat to be updated, got %d", len(req))

w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"errors": [],
Expand Down

0 comments on commit 83c7769

Please sign in to comment.