From 1bb5c09b5d973ac184922380b1e6379875ac5fa7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 20 Nov 2020 02:56:42 +0100 Subject: 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 --- integrations/api_admin_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'integrations/api_admin_test.go') 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)) +} -- cgit v1.2.3