aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-05-21 23:13:47 +0800
committerGitHub <noreply@github.com>2023-05-21 23:13:47 +0800
commitc59a057297c782f44a81a3e630b5094a58099edb (patch)
tree58c3020b0da9755fa769619bb3ad80e656f25cd9 /tests
parent64f6a5d113da0d5d187752c9398d6e8d22d24b79 (diff)
downloadgitea-c59a057297c782f44a81a3e630b5094a58099edb.tar.gz
gitea-c59a057297c782f44a81a3e630b5094a58099edb.zip
Refactor rename user and rename organization (#24052)
This PR is a refactor at the beginning. And now it did 4 things. - [x] Move renaming organizaiton and user logics into services layer and merged as one function - [x] Support rename a user capitalization only. For example, rename the user from `Lunny` to `lunny`. We just need to change one table `user` and others should not be touched. - [x] Before this PR, some renaming were missed like `agit` - [x] Fix bug the API reutrned from `http.StatusNoContent` to `http.StatusOK`
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_admin_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/integration/api_admin_test.go b/tests/integration/api_admin_test.go
index 53e4849aa5..7cfc3276ee 100644
--- a/tests/integration/api_admin_test.go
+++ b/tests/integration/api_admin_test.go
@@ -241,3 +241,44 @@ func TestAPICreateRepoForUser(t *testing.T) {
)
MakeRequest(t, req, http.StatusCreated)
}
+
+func TestAPIRenameUser(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+ adminUsername := "user1"
+ token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeSudo)
+ urlStr := fmt.Sprintf("/api/v1/admin/users/%s/rename?token=%s", "user2", token)
+ req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
+ // required
+ "new_name": "User2",
+ })
+ MakeRequest(t, req, http.StatusOK)
+
+ urlStr = fmt.Sprintf("/api/v1/admin/users/%s/rename?token=%s", "User2", token)
+ req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
+ // required
+ "new_name": "User2-2-2",
+ })
+ MakeRequest(t, req, http.StatusOK)
+
+ urlStr = fmt.Sprintf("/api/v1/admin/users/%s/rename?token=%s", "User2", token)
+ req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
+ // required
+ "new_name": "user1",
+ })
+ // the old user name still be used by with a redirect
+ MakeRequest(t, req, http.StatusTemporaryRedirect)
+
+ urlStr = fmt.Sprintf("/api/v1/admin/users/%s/rename?token=%s", "User2-2-2", token)
+ req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
+ // required
+ "new_name": "user1",
+ })
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
+
+ urlStr = fmt.Sprintf("/api/v1/admin/users/%s/rename?token=%s", "User2-2-2", token)
+ req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
+ // required
+ "new_name": "user2",
+ })
+ MakeRequest(t, req, http.StatusOK)
+}