diff --git a/github/scim.go b/github/scim.go index 02136d7ef91..4b34c1663cd 100644 --- a/github/scim.go +++ b/github/scim.go @@ -110,19 +110,21 @@ func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org str // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#provision-and-invite-a-scim-user // //meta:operation POST /scim/v2/organizations/{org}/Users -func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*Response, error) { +func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*SCIMUserAttributes, *Response, error) { u := fmt.Sprintf("scim/v2/organizations/%v/Users", org) - u, err := addOptions(u, opts) + + req, err := s.client.NewRequest("POST", u, opts) if err != nil { - return nil, err + return nil, nil, err } - req, err := s.client.NewRequest("POST", u, nil) + user := new(SCIMUserAttributes) + resp, err := s.client.Do(ctx, req, user) if err != nil { - return nil, err + return nil, resp, err } - return s.client.Do(ctx, req, nil) + return user, resp, nil } // GetSCIMProvisioningInfoForUser returns SCIM provisioning information for a user. diff --git a/github/scim_test.go b/github/scim_test.go index 9e5274766aa..2ae4f194456 100644 --- a/github/scim_test.go +++ b/github/scim_test.go @@ -127,7 +127,8 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { mux.HandleFunc("/scim/v2/organizations/o/Users", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") - w.WriteHeader(http.StatusOK) + w.WriteHeader(http.StatusCreated) + fmt.Fprint(w, `{"id":"1234567890","userName":"userName"}`) }) ctx := context.Background() @@ -143,19 +144,31 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) { }, }, } - _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + user, _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) if err != nil { - t.Errorf("SCIM.ListSCIMProvisionedIdentities returned error: %v", err) + t.Errorf("SCIM.ProvisionAndInviteSCIMUser returned error: %v", err) + } + + want := &SCIMUserAttributes{ + ID: String("1234567890"), + UserName: "userName", + } + if !cmp.Equal(user, want) { + t.Errorf("SCIM.ProvisionAndInviteSCIMUser returned %+v, want %+v", user, want) } const methodName = "ProvisionAndInviteSCIMUser" testBadOptions(t, methodName, func() (err error) { - _, err = client.SCIM.ProvisionAndInviteSCIMUser(ctx, "\n", opts) + _, _, err = client.SCIM.ProvisionAndInviteSCIMUser(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + got, resp, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err }) }