|
5 | 5 | package integrations
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "encoding/json" |
8 | 9 | "fmt"
|
9 | 10 | "net/http"
|
10 | 11 | "testing"
|
@@ -163,3 +164,32 @@ func TestAPICreateUserInvalidEmail(t *testing.T) {
|
163 | 164 | })
|
164 | 165 | session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
165 | 166 | }
|
| 167 | + |
| 168 | +func TestAPIEditUser(t *testing.T) { |
| 169 | + defer prepareTestEnv(t)() |
| 170 | + adminUsername := "user1" |
| 171 | + session := loginUser(t, adminUsername) |
| 172 | + token := getTokenForLoggedInUser(t, session) |
| 173 | + urlStr := fmt.Sprintf("/api/v1/admin/users/%s?token=%s", "user2", token) |
| 174 | + |
| 175 | + req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ |
| 176 | + // required |
| 177 | + "login_name": "user2", |
| 178 | + "source_id": "0", |
| 179 | + // to change |
| 180 | + "full_name": "Full Name User 2", |
| 181 | + }) |
| 182 | + session.MakeRequest(t, req, http.StatusOK) |
| 183 | + |
| 184 | + empty := "" |
| 185 | + req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ |
| 186 | + LoginName: "user2", |
| 187 | + SourceID: 0, |
| 188 | + Email: &empty, |
| 189 | + }) |
| 190 | + resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity) |
| 191 | + |
| 192 | + errMap := make(map[string]interface{}) |
| 193 | + json.Unmarshal(resp.Body.Bytes(), &errMap) |
| 194 | + assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string)) |
| 195 | +} |
0 commit comments