Add basic test structure

This commit is contained in:
kolaente 2020-12-18 01:24:47 +01:00
parent 2846322bde
commit 6027aecc2b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 189 additions and 16 deletions

View File

@ -55,13 +55,13 @@ type task struct {
CreatedDateTime time.Time `json:"createdDateTime"`
LastModifiedDateTime time.Time `json:"lastModifiedDateTime"`
ID string `json:"id"`
Body body `json:"body"`
DueDateTime dueDateTime `json:"dueDateTime"`
Recurrence recurrence `json:"recurrence"`
ReminderDateTime reminderDateTime `json:"reminderDateTime"`
CompletedDateTime completedDateTime `json:"completedDateTime"`
Body *body `json:"body"`
DueDateTime *dateTimeTimeZone `json:"dueDateTime"`
Recurrence *recurrence `json:"recurrence"`
ReminderDateTime *dateTimeTimeZone `json:"reminderDateTime"`
CompletedDateTime *dateTimeTimeZone `json:"completedDateTime"`
}
type completedDateTime struct {
type dateTimeTimeZone struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
}
@ -69,10 +69,6 @@ type body struct {
Content string `json:"content"`
ContentType string `json:"contentType"`
}
type dueDateTime struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
}
type pattern struct {
Type string `json:"type"`
Interval int `json:"interval"`
@ -90,12 +86,8 @@ type taskRange struct {
NumberOfOccurrences int `json:"numberOfOccurrences"`
}
type recurrence struct {
Pattern pattern `json:"pattern"`
Range taskRange `json:"range"`
}
type reminderDateTime struct {
DateTime string `json:"dateTime"`
TimeZone string `json:"timeZone"`
Pattern *pattern `json:"pattern"`
Range *taskRange `json:"range"`
}
type tasksResponse struct {
@ -225,6 +217,18 @@ func getMicrosoftTodoData(token string) (microsoftTodoData []*list, err error) {
}
func convertMicrosoftTodoData(todoData []*list) (vikunjsStructure []*models.NamespaceWithLists, err error) {
// One namespace with all lists
// Lists only with naem
// Title
// Description
// Done Status
// Priority
// Reminders
// Due Date
// Repeating
return
}

View File

@ -0,0 +1,169 @@
// 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 microsofttodo
import (
"testing"
"time"
"code.vikunja.io/api/pkg/models"
"github.com/alecthomas/assert"
"github.com/d4l3k/messagediff"
)
func TestConverting(t *testing.T) {
testtime := &dateTimeTimeZone{
DateTime: "2020-12-18T03:00:00.4770000",
TimeZone: "UTC",
}
testtimeTime, err := time.Parse(time.RFC3339Nano, "2020-12-18T03:00:00.4770000Z")
assert.NoError(t, err)
microsoftTodoData := []*list{
{
DisplayName: "List 1",
Tasks: []*task{
{
Title: "Task 1",
Status: "notStarted",
Body: &body{
Content: "This is a description",
ContentType: "text",
},
},
{
Title: "Task 2",
Status: "completed",
CompletedDateTime: testtime,
},
{
Title: "Task 3",
Status: "notStarted",
Importance: "low",
},
{
Title: "Task 4",
Status: "notStarted",
Importance: "high",
},
{
Title: "Task 5",
Status: "notStarted",
IsReminderOn: true,
ReminderDateTime: testtime,
},
{
Title: "Task 6",
Status: "notStarted",
DueDateTime: testtime,
},
{
Title: "Task 7",
Status: "notStarted",
DueDateTime: testtime,
Recurrence: &recurrence{
Pattern: &pattern{
// Every week
Type: "weekly",
Interval: 1,
},
},
},
},
},
{
DisplayName: "List 2",
Tasks: []*task{
{
Title: "Task 1",
Status: "notStarted",
},
{
Title: "Task 2",
Status: "notStarted",
},
},
},
}
expectedHierachie := []*models.NamespaceWithLists{
{
Namespace: models.Namespace{
Title: "Migrated from Microsoft Todo",
},
Lists: []*models.List{
{
Title: "List 1",
Tasks: []*models.Task{
{
Title: "Task 1",
Description: "This is a description",
},
{
Title: "Task 2",
Done: true,
DoneAt: testtimeTime,
},
{
Title: "Task 3",
Priority: 1,
},
{
Title: "Task 4",
Priority: 3,
},
{
Title: "Task 5",
Reminders: []time.Time{
testtimeTime,
},
},
{
Title: "Task 6",
DueDate: testtimeTime,
},
{
Title: "Task 7",
DueDate: testtimeTime,
RepeatAfter: 60 * 60 * 24 * 7, // The amount of seconds in a week
},
},
},
{
Title: "List 2",
Tasks: []*models.Task{
{
Title: "Task 1",
},
{
Title: "Task 2",
},
},
},
},
},
}
hierachie, err := convertMicrosoftTodoData(microsoftTodoData)
assert.NoError(t, err)
assert.NotNil(t, hierachie)
if diff, equal := messagediff.PrettyDiff(hierachie, expectedHierachie); !equal {
t.Errorf("converted microsoft todo data = %v, want %v, diff: %v", hierachie, expectedHierachie, diff)
}
}