-
Notifications
You must be signed in to change notification settings - Fork 47
feat(issues): move a work item to another project #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package handler_test | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/Devlaner/devlane/api/internal/model" | ||
| "github.com/Devlaner/devlane/api/internal/testutil" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIssue_MoveToProject(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| target := testutil.CreateProject(t, ts.DB, w.Workspace.ID, w.User.ID) | ||
|
|
||
| // An issue in the source project with a state and a label. | ||
| issue := testutil.CreateIssue(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| state := testutil.CreateState(t, ts.DB, w.Project.ID, w.Workspace.ID) | ||
| require.NoError(t, ts.DB.Model(issue).Update("state_id", state.ID).Error) | ||
| label := testutil.CreateLabel(t, ts.DB, w.Project.ID, w.Workspace.ID) | ||
| require.NoError(t, ts.DB.Create(&model.IssueLabel{ | ||
| IssueID: issue.ID, LabelID: label.ID, ProjectID: w.Project.ID, WorkspaceID: w.Workspace.ID, | ||
| }).Error) | ||
|
|
||
| // A child work item parented to the issue; it must be detached on move so the | ||
| // same-project parent/child invariant holds. | ||
| child := testutil.CreateIssue(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| require.NoError(t, ts.DB.Model(child).Update("parent_id", issue.ID).Error) | ||
|
|
||
| // Pre-seed the target with an issue so the moved item gets a fresh sequence. | ||
| testutil.CreateIssue(t, ts.DB, target.ID, w.Workspace.ID, w.User.ID) | ||
|
|
||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + "/issues/" | ||
| rr := ts.POST(base+issue.ID.String()+"/move/", map[string]any{"target_project_id": target.ID.String()}, w.Session) | ||
| require.Equal(t, http.StatusOK, rr.Code, "body=%s", rr.Body.String()) | ||
| body := testutil.MustJSONMap(t, rr) | ||
| require.Equal(t, target.ID.String(), body["project_id"]) | ||
| require.Nil(t, body["state_id"], "state should reset on move") | ||
|
|
||
| // Project-scoped associations are dropped. | ||
| var labels int64 | ||
| require.NoError(t, ts.DB.Model(&model.IssueLabel{}).Where("issue_id = ?", issue.ID).Count(&labels).Error) | ||
| require.Zero(t, labels, "labels should be cleared on move") | ||
|
|
||
| // The row really lives in the target project now. | ||
| var moved model.Issue | ||
| require.NoError(t, ts.DB.First(&moved, "id = ?", issue.ID).Error) | ||
| require.Equal(t, target.ID, moved.ProjectID) | ||
| require.Nil(t, moved.StateID) | ||
|
|
||
| // The child stays in the source project but is detached from the moved parent. | ||
| var movedChild model.Issue | ||
| require.NoError(t, ts.DB.First(&movedChild, "id = ?", child.ID).Error) | ||
| require.Equal(t, w.Project.ID, movedChild.ProjectID, "child stays in source project") | ||
| require.Nil(t, movedChild.ParentID, "child should be detached from a cross-project parent") | ||
| } | ||
|
|
||
| func TestIssue_MoveToSameProjectRejected(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| issue := testutil.CreateIssue(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + "/issues/" | ||
| rr := ts.POST(base+issue.ID.String()+"/move/", map[string]any{"target_project_id": w.Project.ID.String()}, w.Session) | ||
| require.Equal(t, http.StatusBadRequest, rr.Code, "body=%s", rr.Body.String()) | ||
| } | ||
|
|
||
| func TestIssue_MoveRequiresTarget(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| issue := testutil.CreateIssue(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + "/issues/" | ||
| rr := ts.POST(base+issue.ID.String()+"/move/", map[string]any{}, w.Session) | ||
| require.Equal(t, http.StatusBadRequest, rr.Code, "body=%s", rr.Body.String()) | ||
| } | ||
|
|
||
| func TestIssue_MoveCrossWorkspaceRejected(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| // A project that belongs to a different workspace. | ||
| otherUser := testutil.CreateUser(t, ts.DB) | ||
| otherWS := testutil.CreateWorkspace(t, ts.DB, otherUser.ID) | ||
| foreign := testutil.CreateProject(t, ts.DB, otherWS.ID, otherUser.ID) | ||
|
|
||
| issue := testutil.CreateIssue(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + "/issues/" | ||
| rr := ts.POST(base+issue.ID.String()+"/move/", map[string]any{"target_project_id": foreign.ID.String()}, w.Session) | ||
| require.Equal(t, http.StatusNotFound, rr.Code, "body=%s", rr.Body.String()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.