mirror of https://github.com/go-gitea/gitea.git
Create a project dynamically to avoid override
This commit is contained in:
parent
4ce383f731
commit
e56f89fdba
|
@ -4,12 +4,12 @@
|
||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -30,7 +30,23 @@ func TestPrivateRepoProject(t *testing.T) {
|
||||||
func TestMoveRepoProjectColumns(t *testing.T) {
|
func TestMoveRepoProjectColumns(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
project1 := unittest.AssertExistsAndLoadBean(t, &project_model.Project{ID: 1})
|
project1 := project_model.Project{
|
||||||
|
Title: "new created project",
|
||||||
|
RepoID: 1,
|
||||||
|
Type: project_model.TypeRepository,
|
||||||
|
BoardType: project_model.BoardTypeNone,
|
||||||
|
}
|
||||||
|
err := project_model.NewProject(db.DefaultContext, &project1)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
err = project_model.NewBoard(db.DefaultContext, &project_model.Board{
|
||||||
|
Title: fmt.Sprintf("column %d", i+1),
|
||||||
|
ProjectID: project1.ID,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
columns, err := project1.GetBoards(db.DefaultContext)
|
columns, err := project1.GetBoards(db.DefaultContext)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, columns, 3)
|
assert.Len(t, columns, 3)
|
||||||
|
@ -39,11 +55,11 @@ func TestMoveRepoProjectColumns(t *testing.T) {
|
||||||
assert.EqualValues(t, 2, columns[2].Sorting)
|
assert.EqualValues(t, 2, columns[2].Sorting)
|
||||||
|
|
||||||
sess := loginUser(t, "user2")
|
sess := loginUser(t, "user2")
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/projects/1")
|
req := NewRequest(t, "GET", fmt.Sprintf("/user2/repo1/projects/%d", project1.ID))
|
||||||
resp := sess.MakeRequest(t, req, http.StatusOK)
|
resp := sess.MakeRequest(t, req, http.StatusOK)
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
req = NewRequestWithJSON(t, "POST", "/user2/repo1/projects/1/move?_csrf="+htmlDoc.GetCSRF(), map[string]any{
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/user2/repo1/projects/%d/move?_csrf="+htmlDoc.GetCSRF(), project1.ID), map[string]any{
|
||||||
"columns": []map[string]any{
|
"columns": []map[string]any{
|
||||||
{"columnID": columns[1].ID, "sorting": 0},
|
{"columnID": columns[1].ID, "sorting": 0},
|
||||||
{"columnID": columns[2].ID, "sorting": 1},
|
{"columnID": columns[2].ID, "sorting": 1},
|
||||||
|
@ -60,7 +76,7 @@ func TestMoveRepoProjectColumns(t *testing.T) {
|
||||||
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)
|
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)
|
||||||
|
|
||||||
// update the sorting back
|
// update the sorting back
|
||||||
req = NewRequestWithJSON(t, "POST", "/user2/repo1/projects/1/move?_csrf="+htmlDoc.GetCSRF(), map[string]any{
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/user2/repo1/projects/%d/move?_csrf="+htmlDoc.GetCSRF(), project1.ID), map[string]any{
|
||||||
"columns": []map[string]any{
|
"columns": []map[string]any{
|
||||||
{"columnID": columns[0].ID, "sorting": 0},
|
{"columnID": columns[0].ID, "sorting": 0},
|
||||||
{"columnID": columns[1].ID, "sorting": 1},
|
{"columnID": columns[1].ID, "sorting": 1},
|
||||||
|
@ -68,4 +84,6 @@ func TestMoveRepoProjectColumns(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
sess.MakeRequest(t, req, http.StatusOK)
|
sess.MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
assert.NoError(t, project_model.DeleteProjectByID(db.DefaultContext, project1.ID))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue