2020-12-17 14:44:04 +01:00
|
|
|
// Vikunja is a to-do list application to facilitate your life.
|
2021-02-02 20:19:13 +01:00
|
|
|
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
2020-12-17 14:44:04 +01:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
2020-12-23 16:41:52 +01:00
|
|
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
2020-12-17 14:44:04 +01:00
|
|
|
// 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
|
2020-12-23 16:41:52 +01:00
|
|
|
// GNU Affero General Public Licensee for more details.
|
2020-12-17 14:44:04 +01:00
|
|
|
//
|
2020-12-23 16:41:52 +01:00
|
|
|
// You should have received a copy of the GNU Affero General Public Licensee
|
2020-12-17 14:44:04 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package trello
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-10-01 17:05:12 +02:00
|
|
|
"os"
|
2020-12-17 14:44:04 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.vikunja.io/api/pkg/config"
|
|
|
|
"code.vikunja.io/api/pkg/files"
|
|
|
|
"code.vikunja.io/api/pkg/models"
|
|
|
|
"github.com/adlio/trello"
|
|
|
|
"github.com/d4l3k/messagediff"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvertTrelloToVikunja(t *testing.T) {
|
|
|
|
|
|
|
|
config.InitConfig()
|
|
|
|
|
|
|
|
time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z")
|
|
|
|
assert.NoError(t, err)
|
2022-10-01 17:05:12 +02:00
|
|
|
exampleFile, err := os.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg")
|
2020-12-17 14:44:04 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
trelloData := []*trello.Board{
|
|
|
|
{
|
|
|
|
Name: "TestBoard",
|
|
|
|
Desc: "This is a description",
|
|
|
|
Closed: false,
|
|
|
|
Lists: []*trello.List{
|
|
|
|
{
|
|
|
|
Name: "Test List 1",
|
|
|
|
Cards: []*trello.Card{
|
|
|
|
{
|
|
|
|
Name: "Test Card 1",
|
|
|
|
Desc: "Card Description",
|
|
|
|
Pos: 123,
|
|
|
|
Due: &time1,
|
|
|
|
Labels: []*trello.Label{
|
|
|
|
{
|
|
|
|
ID: "ide1",
|
|
|
|
Name: "Label 1",
|
|
|
|
Color: "green",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "ide2",
|
|
|
|
Name: "Label 2",
|
|
|
|
Color: "orange",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Attachments: []*trello.Attachment{
|
|
|
|
{
|
|
|
|
Name: "Testimage.jpg",
|
|
|
|
IsUpload: true,
|
|
|
|
MimeType: "image/jpg",
|
|
|
|
URL: "https://vikunja.io/testimage.jpg",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test Card 2",
|
|
|
|
Pos: 124,
|
|
|
|
Checklists: []*trello.Checklist{
|
|
|
|
{
|
|
|
|
Name: "Checklist 1",
|
|
|
|
CheckItems: []trello.CheckItem{
|
|
|
|
{
|
|
|
|
State: "pending",
|
|
|
|
Name: "Pending Task",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
State: "completed",
|
|
|
|
Name: "Completed Task",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Checklist 2",
|
|
|
|
CheckItems: []trello.CheckItem{
|
|
|
|
{
|
|
|
|
State: "pending",
|
|
|
|
Name: "Pending Task",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
State: "pending",
|
|
|
|
Name: "Another Pending Task",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test Card 3",
|
|
|
|
Pos: 126,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test Card 4",
|
|
|
|
Pos: 127,
|
|
|
|
Labels: []*trello.Label{
|
|
|
|
{
|
|
|
|
ID: "ide2",
|
|
|
|
Name: "Label 2",
|
|
|
|
Color: "orange",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test List 2",
|
|
|
|
Cards: []*trello.Card{
|
|
|
|
{
|
|
|
|
Name: "Test Card 5",
|
|
|
|
Pos: 111,
|
|
|
|
Labels: []*trello.Label{
|
|
|
|
{
|
|
|
|
ID: "ide3",
|
|
|
|
Name: "Label 3",
|
|
|
|
Color: "blue",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test Card 6",
|
|
|
|
Due: &time1,
|
|
|
|
Pos: 222,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test Card 7",
|
|
|
|
Pos: 333,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Test Card 8",
|
|
|
|
Pos: 444,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "TestBoard 2",
|
|
|
|
Closed: false,
|
|
|
|
Lists: []*trello.List{
|
|
|
|
{
|
|
|
|
Name: "Test List 4",
|
|
|
|
Cards: []*trello.Card{
|
|
|
|
{
|
|
|
|
Name: "Test Card 634",
|
|
|
|
Pos: 123,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "TestBoard Archived",
|
|
|
|
Closed: true,
|
|
|
|
Lists: []*trello.List{
|
|
|
|
{
|
|
|
|
Name: "Test List 5",
|
|
|
|
Cards: []*trello.Card{
|
|
|
|
{
|
|
|
|
Name: "Test Card 63423",
|
|
|
|
Pos: 123,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
trelloData[0].Prefs.BackgroundImage = "https://vikunja.io/testimage.jpg" // Using an image which we are hosting, so it'll still be up
|
|
|
|
|
2021-09-04 21:26:31 +02:00
|
|
|
expectedHierachie := []*models.NamespaceWithListsAndTasks{
|
2020-12-17 14:44:04 +01:00
|
|
|
{
|
|
|
|
Namespace: models.Namespace{
|
|
|
|
Title: "Imported from Trello",
|
|
|
|
},
|
2021-09-04 21:26:31 +02:00
|
|
|
Lists: []*models.ListWithTasksAndBuckets{
|
2020-12-17 14:44:04 +01:00
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
List: models.List{
|
|
|
|
Title: "TestBoard",
|
|
|
|
Description: "This is a description",
|
|
|
|
BackgroundInformation: bytes.NewBuffer(exampleFile),
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
Buckets: []*models.Bucket{
|
|
|
|
{
|
|
|
|
ID: 1,
|
|
|
|
Title: "Test List 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: 2,
|
|
|
|
Title: "Test List 2",
|
|
|
|
},
|
|
|
|
},
|
2021-09-04 21:26:31 +02:00
|
|
|
Tasks: []*models.TaskWithComments{
|
2020-12-17 14:44:04 +01:00
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 1",
|
|
|
|
Description: "Card Description",
|
|
|
|
BucketID: 1,
|
|
|
|
KanbanPosition: 123,
|
|
|
|
DueDate: time1,
|
|
|
|
Labels: []*models.Label{
|
|
|
|
{
|
|
|
|
Title: "Label 1",
|
|
|
|
HexColor: trelloColorMap["green"],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Title: "Label 2",
|
|
|
|
HexColor: trelloColorMap["orange"],
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
2021-09-04 21:26:31 +02:00
|
|
|
Attachments: []*models.TaskAttachment{
|
|
|
|
{
|
|
|
|
File: &files.File{
|
|
|
|
Name: "Testimage.jpg",
|
|
|
|
Mime: "image/jpg",
|
|
|
|
Size: uint64(len(exampleFile)),
|
|
|
|
FileContent: exampleFile,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 2",
|
|
|
|
Description: `
|
2020-12-17 14:44:04 +01:00
|
|
|
|
|
|
|
## Checklist 1
|
|
|
|
|
|
|
|
* [ ] Pending Task
|
|
|
|
* [x] Completed Task
|
|
|
|
|
|
|
|
## Checklist 2
|
|
|
|
|
|
|
|
* [ ] Pending Task
|
|
|
|
* [ ] Another Pending Task`,
|
2021-09-04 21:26:31 +02:00
|
|
|
BucketID: 1,
|
|
|
|
KanbanPosition: 124,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 3",
|
|
|
|
BucketID: 1,
|
|
|
|
KanbanPosition: 126,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 4",
|
|
|
|
BucketID: 1,
|
|
|
|
KanbanPosition: 127,
|
|
|
|
Labels: []*models.Label{
|
|
|
|
{
|
|
|
|
Title: "Label 2",
|
|
|
|
HexColor: trelloColorMap["orange"],
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 5",
|
|
|
|
BucketID: 2,
|
|
|
|
KanbanPosition: 111,
|
|
|
|
Labels: []*models.Label{
|
|
|
|
{
|
|
|
|
Title: "Label 3",
|
|
|
|
HexColor: trelloColorMap["blue"],
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 6",
|
|
|
|
BucketID: 2,
|
|
|
|
KanbanPosition: 222,
|
|
|
|
DueDate: time1,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 7",
|
|
|
|
BucketID: 2,
|
|
|
|
KanbanPosition: 333,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 8",
|
|
|
|
BucketID: 2,
|
|
|
|
KanbanPosition: 444,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
List: models.List{
|
|
|
|
Title: "TestBoard 2",
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
Buckets: []*models.Bucket{
|
|
|
|
{
|
|
|
|
ID: 3,
|
|
|
|
Title: "Test List 4",
|
|
|
|
},
|
|
|
|
},
|
2021-09-04 21:26:31 +02:00
|
|
|
Tasks: []*models.TaskWithComments{
|
2020-12-17 14:44:04 +01:00
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 634",
|
|
|
|
BucketID: 3,
|
|
|
|
KanbanPosition: 123,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
List: models.List{
|
|
|
|
Title: "TestBoard Archived",
|
|
|
|
IsArchived: true,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
Buckets: []*models.Bucket{
|
|
|
|
{
|
|
|
|
ID: 4,
|
|
|
|
Title: "Test List 5",
|
|
|
|
},
|
|
|
|
},
|
2021-09-04 21:26:31 +02:00
|
|
|
Tasks: []*models.TaskWithComments{
|
2020-12-17 14:44:04 +01:00
|
|
|
{
|
2021-09-04 21:26:31 +02:00
|
|
|
Task: models.Task{
|
|
|
|
Title: "Test Card 63423",
|
|
|
|
BucketID: 4,
|
|
|
|
KanbanPosition: 123,
|
|
|
|
},
|
2020-12-17 14:44:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-11-14 21:47:51 +01:00
|
|
|
hierachie, err := convertTrelloDataToVikunja(trelloData, "")
|
2020-12-17 14:44:04 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, hierachie)
|
|
|
|
if diff, equal := messagediff.PrettyDiff(hierachie, expectedHierachie); !equal {
|
|
|
|
t.Errorf("converted trello data = %v, want %v, diff: %v", hierachie, expectedHierachie, diff)
|
|
|
|
}
|
|
|
|
}
|