forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(account_members): Add CreateAccountMemberWithStatus
The API call for adding members to an account optionally allows a status field, which can be used to immediately accept an invitation. The CreateAccountMemberWithStatus method has been added, replacing CreateAccountMember and taking the extra status parameter, and CreateAccountMember has been recreated as a wrapper for backwards compatibility.
- Loading branch information
Showing
2 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,27 @@ var expectedNewAccountMemberStruct = AccountMember{ | |
}, | ||
} | ||
|
||
var expectedNewAccountMemberAcceptedStruct = AccountMember{ | ||
ID: "4536bcfad5faccb111b47003c79917fa", | ||
Code: "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0", | ||
User: AccountMemberUserDetails{ | ||
Email: "[email protected]", | ||
TwoFactorAuthenticationEnabled: false, | ||
}, | ||
Status: "accepted", | ||
Roles: []AccountRole{ | ||
{ | ||
ID: "3536bcfad5faccb999b47003c79917fb", | ||
Name: "Account Administrator", | ||
Description: "Administrative access to the entire Account", | ||
Permissions: map[string]AccountRolePermission{ | ||
"analytics": {Read: true, Edit: true}, | ||
"billing": {Read: true, Edit: true}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var newUpdatedAccountMemberStruct = AccountMember{ | ||
ID: "4536bcfad5faccb111b47003c79917fa", | ||
Code: "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0", | ||
|
@@ -151,6 +172,57 @@ func TestAccountMembersWithoutAccountID(t *testing.T) { | |
} | ||
} | ||
|
||
func TestCreateAccountMemberWithStatus(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
handler := func(w http.ResponseWriter, r *http.Request) { | ||
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) | ||
w.Header().Set("content-type", "application/json") | ||
fmt.Fprintf(w, `{ | ||
"success": true, | ||
"errors": [], | ||
"messages": [], | ||
"result": { | ||
"id": "4536bcfad5faccb111b47003c79917fa", | ||
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0", | ||
"user": { | ||
"id": null, | ||
"first_name": null, | ||
"last_name": null, | ||
"email": "[email protected]", | ||
"two_factor_authentication_enabled": false | ||
}, | ||
"status": "accepted", | ||
"roles": [{ | ||
"id": "3536bcfad5faccb999b47003c79917fb", | ||
"name": "Account Administrator", | ||
"description": "Administrative access to the entire Account", | ||
"permissions": { | ||
"analytics": { | ||
"read": true, | ||
"edit": true | ||
}, | ||
"billing": { | ||
"read": true, | ||
"edit": true | ||
} | ||
} | ||
}] | ||
} | ||
} | ||
`) | ||
} | ||
|
||
mux.HandleFunc("/accounts/01a7362d577a6c3019a474fd6f485823/members", handler) | ||
|
||
actual, err := client.CreateAccountMemberWithStatus(context.Background(), "01a7362d577a6c3019a474fd6f485823", "[email protected]", []string{"3536bcfad5faccb999b47003c79917fb"}, "accepted") | ||
|
||
if assert.NoError(t, err) { | ||
assert.Equal(t, expectedNewAccountMemberAcceptedStruct, actual) | ||
} | ||
} | ||
|
||
func TestCreateAccountMember(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|