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 {
|
for _, rt := range tasks {
|
||||||
// First create the related tasks if they do not exist
|
// 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
|
oldid := rt.ID
|
||||||
setBucketOrDefault(rt)
|
setBucketOrDefault(rt)
|
||||||
rt.ProjectID = t.ProjectID
|
rt.ProjectID = t.ProjectID
|
||||||
|
@ -35,6 +35,7 @@ func TestInsertFromStructure(t *testing.T) {
|
|||||||
testStructure := []*models.ProjectWithTasksAndBuckets{
|
testStructure := []*models.ProjectWithTasksAndBuckets{
|
||||||
{
|
{
|
||||||
Project: models.Project{
|
Project: models.Project{
|
||||||
|
ID: 1,
|
||||||
Title: "Test1",
|
Title: "Test1",
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
},
|
},
|
||||||
@ -45,11 +46,12 @@ func TestInsertFromStructure(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ChildProjects: []*models.ProjectWithTasksAndBuckets{
|
},
|
||||||
{
|
{
|
||||||
Project: models.Project{
|
Project: models.Project{
|
||||||
Title: "Testproject1",
|
Title: "Testproject1",
|
||||||
Description: "Something",
|
Description: "Something",
|
||||||
|
ParentProjectID: 1,
|
||||||
},
|
},
|
||||||
Buckets: []*models.Bucket{
|
Buckets: []*models.Bucket{
|
||||||
{
|
{
|
||||||
@ -131,27 +133,25 @@ func TestInsertFromStructure(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
err := InsertFromStructure(testStructure, u)
|
err := InsertFromStructure(testStructure, u)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertExists(t, "projects", map[string]interface{}{
|
db.AssertExists(t, "projects", map[string]interface{}{
|
||||||
"title": testStructure[0].ChildProjects[0].Title,
|
"title": testStructure[1].Title,
|
||||||
"description": testStructure[0].ChildProjects[0].Description,
|
"description": testStructure[1].Description,
|
||||||
}, false)
|
}, false)
|
||||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||||
"title": testStructure[0].ChildProjects[0].Tasks[5].Title,
|
"title": testStructure[1].Tasks[5].Title,
|
||||||
"bucket_id": testStructure[0].ChildProjects[0].Buckets[0].ID,
|
"bucket_id": testStructure[1].Buckets[0].ID,
|
||||||
}, false)
|
}, false)
|
||||||
db.AssertMissing(t, "tasks", map[string]interface{}{
|
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
|
"bucket_id": 1111, // No task with that bucket should exist
|
||||||
})
|
})
|
||||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||||
"title": testStructure[0].Tasks[0].Title,
|
"title": testStructure[0].Tasks[0].Title,
|
||||||
}, false)
|
}, false)
|
||||||
assert.NotEqual(t, 0, testStructure[0].ChildProjects[0].Tasks[0].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[0].ChildProjects[0].Tasks[6].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