diff options
author | 6543 <6543@obermui.de> | 2020-11-20 02:56:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 20:56:42 -0500 |
commit | 1bb5c09b5d973ac184922380b1e6379875ac5fa7 (patch) | |
tree | 293984f50fd016e9da7cfb78102eeacc5f14b01a /integrations/api_admin_test.go | |
parent | 24b3b2140a094a108707c2994946b5a99eda016f (diff) | |
download | gitea-1bb5c09b5d973ac184922380b1e6379875ac5fa7.tar.gz gitea-1bb5c09b5d973ac184922380b1e6379875ac5fa7.zip |
API: Admin EditUser: Make FullName, Email, Website & Location optional (#13562)
* API: Admin EditUser: Make FullName, Email, Website & Location optional
* update swagger docs
* add Tests
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'integrations/api_admin_test.go')
-rw-r--r-- | integrations/api_admin_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/integrations/api_admin_test.go b/integrations/api_admin_test.go index 80d6b52289..79fdc4a9f7 100644 --- a/integrations/api_admin_test.go +++ b/integrations/api_admin_test.go @@ -5,6 +5,7 @@ package integrations import ( + "encoding/json" "fmt" "net/http" "testing" @@ -163,3 +164,32 @@ func TestAPICreateUserInvalidEmail(t *testing.T) { }) session.MakeRequest(t, req, http.StatusUnprocessableEntity) } + +func TestAPIEditUser(t *testing.T) { + defer prepareTestEnv(t)() + adminUsername := "user1" + session := loginUser(t, adminUsername) + token := getTokenForLoggedInUser(t, session) + urlStr := fmt.Sprintf("/api/v1/admin/users/%s?token=%s", "user2", token) + + req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ + // required + "login_name": "user2", + "source_id": "0", + // to change + "full_name": "Full Name User 2", + }) + session.MakeRequest(t, req, http.StatusOK) + + empty := "" + req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ + LoginName: "user2", + SourceID: 0, + Email: &empty, + }) + resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity) + + errMap := make(map[string]interface{}) + json.Unmarshal(resp.Body.Bytes(), &errMap) + assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string)) +} |