fix(import): create related tasks without an id
This commit is contained in:
parent
68d4dcd7e6
commit
c6bdb5752a
@ -223,7 +223,7 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
|
||||
for _, rt := range tasks {
|
||||
// First create the related tasks if they do not exist
|
||||
if _, exists := tasksByOldID[rt.ID]; !exists {
|
||||
if _, exists := tasksByOldID[rt.ID]; !exists || rt.ID == 0 {
|
||||
oldid := rt.ID
|
||||
setBucketOrDefault(rt)
|
||||
rt.ProjectID = t.ProjectID
|
||||
|
@ -35,6 +35,7 @@ func TestInsertFromStructure(t *testing.T) {
|
||||
testStructure := []*models.ProjectWithTasksAndBuckets{
|
||||
{
|
||||
Project: models.Project{
|
||||
ID: 1,
|
||||
Title: "Test1",
|
||||
Description: "Lorem Ipsum",
|
||||
},
|
||||
@ -45,11 +46,12 @@ func TestInsertFromStructure(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ChildProjects: []*models.ProjectWithTasksAndBuckets{
|
||||
},
|
||||
{
|
||||
Project: models.Project{
|
||||
Title: "Testproject1",
|
||||
Description: "Something",
|
||||
ParentProjectID: 1,
|
||||
},
|
||||
Buckets: []*models.Bucket{
|
||||
{
|
||||
@ -131,27 +133,25 @@ func TestInsertFromStructure(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
err := InsertFromStructure(testStructure, u)
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "projects", map[string]interface{}{
|
||||
"title": testStructure[0].ChildProjects[0].Title,
|
||||
"description": testStructure[0].ChildProjects[0].Description,
|
||||
"title": testStructure[1].Title,
|
||||
"description": testStructure[1].Description,
|
||||
}, false)
|
||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||
"title": testStructure[0].ChildProjects[0].Tasks[5].Title,
|
||||
"bucket_id": testStructure[0].ChildProjects[0].Buckets[0].ID,
|
||||
"title": testStructure[1].Tasks[5].Title,
|
||||
"bucket_id": testStructure[1].Buckets[0].ID,
|
||||
}, false)
|
||||
db.AssertMissing(t, "tasks", map[string]interface{}{
|
||||
"title": testStructure[0].ChildProjects[0].Tasks[6].Title,
|
||||
"title": testStructure[1].Tasks[6].Title,
|
||||
"bucket_id": 1111, // No task with that bucket should exist
|
||||
})
|
||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||
"title": testStructure[0].Tasks[0].Title,
|
||||
}, false)
|
||||
assert.NotEqual(t, 0, testStructure[0].ChildProjects[0].Tasks[0].BucketID) // Should get the default bucket
|
||||
assert.NotEqual(t, 0, testStructure[0].ChildProjects[0].Tasks[6].BucketID) // Should get the default bucket
|
||||
assert.NotEqual(t, 0, testStructure[1].Tasks[0].BucketID) // Should get the default bucket
|
||||
assert.NotEqual(t, 0, testStructure[1].Tasks[6].BucketID) // Should get the default bucket
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user