2020-02-18 23:00:54 +01:00
|
|
|
// Vikunja is a todo-list application to facilitate your life.
|
|
|
|
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package migration
|
|
|
|
|
|
|
|
import (
|
2020-10-11 22:10:03 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-02-18 23:00:54 +01:00
|
|
|
"code.vikunja.io/api/pkg/db"
|
|
|
|
"code.vikunja.io/api/pkg/files"
|
|
|
|
"code.vikunja.io/api/pkg/models"
|
|
|
|
"code.vikunja.io/api/pkg/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInsertFromStructure(t *testing.T) {
|
|
|
|
u := &user.User{
|
|
|
|
ID: 1,
|
|
|
|
}
|
|
|
|
t.Run("normal", func(t *testing.T) {
|
|
|
|
db.LoadAndAssertFixtures(t)
|
|
|
|
testStructure := []*models.NamespaceWithLists{
|
|
|
|
{
|
|
|
|
Namespace: models.Namespace{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "Test1",
|
2020-02-18 23:00:54 +01:00
|
|
|
Description: "Lorem Ipsum",
|
|
|
|
},
|
|
|
|
Lists: []*models.List{
|
|
|
|
{
|
|
|
|
Title: "Testlist1",
|
|
|
|
Description: "Something",
|
2020-12-16 15:19:09 +01:00
|
|
|
Buckets: []*models.Bucket{
|
|
|
|
{
|
|
|
|
ID: 1234,
|
|
|
|
Title: "Test Bucket",
|
|
|
|
},
|
|
|
|
},
|
2020-02-18 23:00:54 +01:00
|
|
|
Tasks: []*models.Task{
|
|
|
|
{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "Task1",
|
2020-02-18 23:00:54 +01:00
|
|
|
Description: "Lorem",
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "Task with related tasks",
|
2020-02-18 23:00:54 +01:00
|
|
|
RelatedTasks: map[models.RelationKind][]*models.Task{
|
|
|
|
models.RelationKindSubtask: {
|
|
|
|
{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "Related to task with related task",
|
2020-02-18 23:00:54 +01:00
|
|
|
Description: "As subtask",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "Task with attachments",
|
2020-02-18 23:00:54 +01:00
|
|
|
Attachments: []*models.TaskAttachment{
|
|
|
|
{
|
|
|
|
File: &files.File{
|
|
|
|
Name: "testfile",
|
|
|
|
Size: 4,
|
|
|
|
FileContent: []byte{1, 2, 3, 4},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-23 22:50:54 +02:00
|
|
|
{
|
|
|
|
Title: "Task with labels",
|
|
|
|
Labels: []*models.Label{
|
|
|
|
{
|
|
|
|
Title: "Label1",
|
|
|
|
HexColor: "ff00ff",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Title: "Label2",
|
|
|
|
HexColor: "ff00ff",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Title: "Task with same label",
|
|
|
|
Labels: []*models.Label{
|
|
|
|
{
|
|
|
|
Title: "Label1",
|
|
|
|
HexColor: "ff00ff",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-12-16 15:19:09 +01:00
|
|
|
{
|
|
|
|
Title: "Task in a bucket",
|
|
|
|
BucketID: 1234,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Title: "Task in a nonexisting bucket",
|
|
|
|
BucketID: 1111,
|
|
|
|
},
|
2020-02-18 23:00:54 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err := InsertFromStructure(testStructure, u)
|
|
|
|
assert.NoError(t, err)
|
2020-12-16 15:19:09 +01:00
|
|
|
db.AssertExists(t, "namespaces", map[string]interface{}{
|
|
|
|
"title": testStructure[0].Namespace.Title,
|
|
|
|
"description": testStructure[0].Namespace.Description,
|
|
|
|
}, false)
|
|
|
|
db.AssertExists(t, "list", map[string]interface{}{
|
|
|
|
"title": testStructure[0].Lists[0].Title,
|
|
|
|
"description": testStructure[0].Lists[0].Description,
|
|
|
|
}, false)
|
|
|
|
db.AssertExists(t, "tasks", map[string]interface{}{
|
|
|
|
"title": testStructure[0].Lists[0].Tasks[5].Title,
|
|
|
|
"bucket_id": testStructure[0].Lists[0].Buckets[0].ID,
|
|
|
|
}, false)
|
|
|
|
db.AssertMissing(t, "tasks", map[string]interface{}{
|
|
|
|
"title": testStructure[0].Lists[0].Tasks[6].Title,
|
|
|
|
"bucket_id": 1111, // No task with that bucket should exist
|
|
|
|
})
|
|
|
|
assert.NotEqual(t, 0, testStructure[0].Lists[0].Tasks[0].BucketID) // Should get the default bucket
|
|
|
|
assert.NotEqual(t, 0, testStructure[0].Lists[0].Tasks[6].BucketID) // Should get the default bucket
|
2020-02-18 23:00:54 +01:00
|
|
|
})
|
|
|
|
}
|