Add Trello conversion test

This commit is contained in:
kolaente 2020-12-16 17:53:04 +01:00
parent 4876542124
commit 48c74deb83
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 280 additions and 1 deletions

2
go.mod
View File

@ -29,7 +29,7 @@ require (
github.com/client9/misspell v0.3.4
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cweill/gotests v1.5.3
github.com/d4l3k/messagediff v1.2.1 // indirect
github.com/d4l3k/messagediff v1.2.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/disintegration/imaging v1.6.2
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0

View File

@ -0,0 +1,279 @@
// Vikunja is a to-do 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 trello
import (
"code.vikunja.io/api/pkg/models"
"github.com/adlio/trello"
"github.com/d4l3k/messagediff"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestConvertTrelloToVikunja(t *testing.T) {
time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z")
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",
},
},
},
{
Name: "Test Card 2",
Pos: 124,
},
{
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
expectedHierachie := []*models.NamespaceWithLists{
{
Namespace: models.Namespace{
Title: "Imported from Trello",
},
Lists: []*models.List{
{
Title: "TestBoard",
Description: "This is a description",
Buckets: []*models.Bucket{
{
ID: 1,
Title: "Test List 1",
},
{
ID: 2,
Title: "Test List 2",
},
},
Tasks: []*models.Task{
{
Title: "Test Card 1",
Description: "Card Description",
BucketID: 1,
Position: 123,
DueDate: time1,
Labels: []*models.Label{
{
ID: 11111,
Title: "Label 1",
HexColor: trelloColorMap["green"],
},
{
ID: 22222,
Title: "Label 2",
HexColor: trelloColorMap["orange"],
},
},
},
{
Title: "Test Card 2",
BucketID: 1,
Position: 124,
},
{
Title: "Test Card 3",
BucketID: 1,
Position: 126,
},
{
Title: "Test Card 4",
BucketID: 1,
Position: 127,
Labels: []*models.Label{
{
ID: 22222,
Title: "Label 2",
HexColor: trelloColorMap["orange"],
},
},
},
{
Title: "Test Card 5",
BucketID: 2,
Position: 111,
Labels: []*models.Label{
{
ID: 3333,
Title: "Label 3",
HexColor: trelloColorMap["blue"],
},
},
},
{
Title: "Test Card 6",
BucketID: 2,
Position: 222,
DueDate: time1,
},
{
Title: "Test Card 7",
BucketID: 2,
Position: 333,
},
{
Title: "Test Card 8",
BucketID: 2,
Position: 444,
},
},
},
{
Title: "TestBoard 2",
Buckets: []*models.Bucket{
{
ID: 3,
Title: "Test List 4",
},
},
Tasks: []*models.Task{
{
Title: "Test Card 634",
BucketID: 3,
Position: 123,
},
},
},
{
Title: "TestBoard Archived",
IsArchived: true,
Buckets: []*models.Bucket{
{
ID: 4,
Title: "Test List 5",
},
},
Tasks: []*models.Task{
{
Title: "Test Card 63423",
BucketID: 4,
Position: 123,
},
},
},
},
},
}
hierachie, err := convertTrelloDataToVikunja(trelloData)
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)
}
}