2020-02-07 17:27:45 +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.
|
2019-12-07 15:30:51 +01:00
|
|
|
//
|
2020-01-09 18:33:22 +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-01-09 18:33:22 +01:00
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2019-12-07 15:30:51 +01:00
|
|
|
//
|
2020-01-09 18:33:22 +01:00
|
|
|
// 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.
|
2019-12-07 15:30:51 +01:00
|
|
|
//
|
2020-12-23 16:41:52 +01:00
|
|
|
// You should have received a copy of the GNU Affero General Public Licensee
|
2020-01-09 18:33:22 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-12-07 15:30:51 +01:00
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2020-10-11 22:10:03 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-06-27 19:04:01 +02:00
|
|
|
"code.vikunja.io/api/pkg/config"
|
2019-12-07 15:30:51 +01:00
|
|
|
"code.vikunja.io/api/pkg/db"
|
|
|
|
"code.vikunja.io/api/pkg/files"
|
2020-01-26 18:08:06 +01:00
|
|
|
"code.vikunja.io/api/pkg/user"
|
2019-12-07 15:30:51 +01:00
|
|
|
"code.vikunja.io/web"
|
|
|
|
"gopkg.in/d4l3k/messagediff.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTaskCollection_ReadAll(t *testing.T) {
|
|
|
|
// Dummy users
|
2020-01-26 18:08:06 +01:00
|
|
|
user1 := &user.User{
|
2021-04-11 17:08:43 +02:00
|
|
|
ID: 1,
|
|
|
|
Username: "user1",
|
|
|
|
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
|
|
|
|
Issuer: "local",
|
|
|
|
EmailRemindersEnabled: true,
|
|
|
|
OverdueTasksRemindersEnabled: true,
|
|
|
|
Created: testCreatedTime,
|
|
|
|
Updated: testUpdatedTime,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
2020-01-26 18:08:06 +01:00
|
|
|
user2 := &user.User{
|
2021-04-11 17:08:43 +02:00
|
|
|
ID: 2,
|
|
|
|
Username: "user2",
|
|
|
|
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
|
|
|
|
Issuer: "local",
|
|
|
|
EmailRemindersEnabled: true,
|
|
|
|
OverdueTasksRemindersEnabled: true,
|
|
|
|
Created: testCreatedTime,
|
|
|
|
Updated: testUpdatedTime,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
2020-01-26 18:08:06 +01:00
|
|
|
user6 := &user.User{
|
2021-04-11 17:08:43 +02:00
|
|
|
ID: 6,
|
|
|
|
Username: "user6",
|
|
|
|
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
|
|
|
|
Issuer: "local",
|
|
|
|
EmailRemindersEnabled: true,
|
|
|
|
OverdueTasksRemindersEnabled: true,
|
|
|
|
Created: testCreatedTime,
|
|
|
|
Updated: testUpdatedTime,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
2021-04-07 14:44:39 +02:00
|
|
|
linkShareUser2 := &user.User{
|
|
|
|
ID: -2,
|
|
|
|
Name: "Link Share",
|
|
|
|
Created: testCreatedTime,
|
|
|
|
Updated: testUpdatedTime,
|
|
|
|
}
|
2019-12-07 15:30:51 +01:00
|
|
|
|
2020-06-27 19:04:01 +02:00
|
|
|
loc := config.GetTimeZone()
|
|
|
|
|
2020-12-20 13:41:36 +01:00
|
|
|
label4 := &Label{
|
|
|
|
ID: 4,
|
|
|
|
Title: "Label #4 - visible via other task",
|
|
|
|
CreatedByID: 2,
|
|
|
|
CreatedBy: user2,
|
|
|
|
Created: testCreatedTime,
|
|
|
|
Updated: testUpdatedTime,
|
|
|
|
}
|
|
|
|
|
2019-12-07 15:30:51 +01:00
|
|
|
// We use individual variables for the tasks here to be able to rearrange or remove ones more easily
|
|
|
|
task1 := &Task{
|
|
|
|
ID: 1,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #1",
|
2019-12-07 15:30:51 +01:00
|
|
|
Description: "Lorem Ipsum",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 1,
|
2020-09-05 22:16:02 +02:00
|
|
|
IsFavorite: true,
|
2021-07-28 21:06:40 +02:00
|
|
|
Position: 2,
|
2019-12-07 15:30:51 +01:00
|
|
|
Labels: []*Label{
|
2020-12-20 13:41:36 +01:00
|
|
|
label4,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{
|
|
|
|
RelationKindSubtask: {
|
|
|
|
{
|
|
|
|
ID: 29,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #29 with parent task (1)",
|
2019-12-07 23:28:45 +01:00
|
|
|
Index: 14,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
ListID: 1,
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Attachments: []*TaskAttachment{
|
|
|
|
{
|
|
|
|
ID: 1,
|
|
|
|
TaskID: 1,
|
|
|
|
FileID: 1,
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: testCreatedTime,
|
2019-12-07 15:30:51 +01:00
|
|
|
File: &files.File{
|
|
|
|
ID: 1,
|
|
|
|
Name: "test",
|
|
|
|
Size: 100,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1570998791, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: 2,
|
|
|
|
TaskID: 1,
|
|
|
|
FileID: 9999,
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: testCreatedTime,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
2021-04-07 14:44:39 +02:00
|
|
|
{
|
|
|
|
ID: 3,
|
|
|
|
TaskID: 1,
|
|
|
|
FileID: 1,
|
|
|
|
CreatedByID: -2,
|
|
|
|
CreatedBy: linkShareUser2,
|
|
|
|
Created: testCreatedTime,
|
|
|
|
File: &files.File{
|
|
|
|
ID: 1,
|
|
|
|
Name: "test",
|
|
|
|
Size: 100,
|
|
|
|
Created: time.Unix(1570998791, 0).In(loc),
|
|
|
|
CreatedByID: 1,
|
|
|
|
},
|
|
|
|
},
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task2 := &Task{
|
|
|
|
ID: 2,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #2 done",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-2",
|
|
|
|
Index: 2,
|
2019-12-07 15:30:51 +01:00
|
|
|
Done: true,
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 1,
|
2021-07-28 21:06:40 +02:00
|
|
|
Position: 4,
|
2019-12-07 15:30:51 +01:00
|
|
|
Labels: []*Label{
|
2020-12-20 13:41:36 +01:00
|
|
|
label4,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2021-01-31 13:09:14 +01:00
|
|
|
Reminders: []time.Time{
|
|
|
|
time.Unix(1543626824, 0).In(loc),
|
|
|
|
},
|
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task3 := &Task{
|
|
|
|
ID: 3,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #3 high prio",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-3",
|
|
|
|
Index: 3,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
Priority: 100,
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 2,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task4 := &Task{
|
|
|
|
ID: 4,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #4 low prio",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-4",
|
|
|
|
Index: 4,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
Priority: 1,
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 2,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task5 := &Task{
|
|
|
|
ID: 5,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #5 higher due date",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-5",
|
|
|
|
Index: 5,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
|
|
|
DueDate: time.Unix(1543636724, 0).In(loc),
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 2,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task6 := &Task{
|
|
|
|
ID: 6,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #6 lower due date",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-6",
|
|
|
|
Index: 6,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
|
|
|
DueDate: time.Unix(1543616724, 0).In(loc),
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 3,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task7 := &Task{
|
2020-02-08 13:48:49 +01:00
|
|
|
ID: 7,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #7 with start date",
|
2020-02-08 13:48:49 +01:00
|
|
|
Identifier: "test1-7",
|
|
|
|
Index: 7,
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
|
|
|
StartDate: time.Unix(1544600000, 0).In(loc),
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 3,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task8 := &Task{
|
|
|
|
ID: 8,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #8 with end date",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-8",
|
|
|
|
Index: 8,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
|
|
|
EndDate: time.Unix(1544700000, 0).In(loc),
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 3,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task9 := &Task{
|
2020-02-08 13:48:49 +01:00
|
|
|
ID: 9,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #9 with start and end date",
|
2020-02-08 13:48:49 +01:00
|
|
|
Identifier: "test1-9",
|
|
|
|
Index: 9,
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
|
|
|
StartDate: time.Unix(1544600000, 0).In(loc),
|
|
|
|
EndDate: time.Unix(1544700000, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task10 := &Task{
|
|
|
|
ID: 10,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #10 basic",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-10",
|
|
|
|
Index: 10,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task11 := &Task{
|
|
|
|
ID: 11,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #11 basic",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-11",
|
|
|
|
Index: 11,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task12 := &Task{
|
|
|
|
ID: 12,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #12 basic",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-12",
|
|
|
|
Index: 12,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task15 := &Task{
|
|
|
|
ID: 15,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #15",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test6-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 6,
|
2020-09-05 22:16:02 +02:00
|
|
|
IsFavorite: true,
|
2019-12-07 15:30:51 +01:00
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 6,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task16 := &Task{
|
|
|
|
ID: 16,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #16",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test7-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 7,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 7,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task17 := &Task{
|
|
|
|
ID: 17,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #17",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test8-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 8,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 8,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task18 := &Task{
|
|
|
|
ID: 18,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #18",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test9-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 9,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 9,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task19 := &Task{
|
|
|
|
ID: 19,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #19",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test10-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 10,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 10,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task20 := &Task{
|
|
|
|
ID: 20,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #20",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test11-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 11,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 11,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task21 := &Task{
|
|
|
|
ID: 21,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #21",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test12-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 12,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 12,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task22 := &Task{
|
|
|
|
ID: 22,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #22",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test13-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 13,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 13,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task23 := &Task{
|
|
|
|
ID: 23,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #23",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test14-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 14,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 14,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task24 := &Task{
|
|
|
|
ID: 24,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #24",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test15-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 15,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 15,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task25 := &Task{
|
|
|
|
ID: 25,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #25",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test16-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 16,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 16,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task26 := &Task{
|
|
|
|
ID: 26,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #26",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test17-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 6,
|
|
|
|
CreatedBy: user6,
|
|
|
|
ListID: 17,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 17,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task27 := &Task{
|
2020-06-27 19:04:01 +02:00
|
|
|
ID: 27,
|
|
|
|
Title: "task #27 with reminders",
|
|
|
|
Identifier: "test1-12",
|
|
|
|
Index: 12,
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
Reminders: []time.Time{
|
|
|
|
time.Unix(1543626724, 0).In(loc),
|
|
|
|
time.Unix(1543626824, 0).In(loc),
|
|
|
|
},
|
2020-02-08 13:48:49 +01:00
|
|
|
ListID: 1,
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-02-08 13:48:49 +01:00
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task28 := &Task{
|
|
|
|
ID: 28,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #28 with repeat after",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-13",
|
|
|
|
Index: 13,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
|
|
|
RepeatAfter: 3600,
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task29 := &Task{
|
|
|
|
ID: 29,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #29 with parent task (1)",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-14",
|
|
|
|
Index: 14,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{
|
|
|
|
RelationKindParenttask: {
|
|
|
|
{
|
|
|
|
ID: 1,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #1",
|
2019-12-07 15:30:51 +01:00
|
|
|
Description: "Lorem Ipsum",
|
2019-12-07 23:28:45 +01:00
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
ListID: 1,
|
2020-09-05 22:16:02 +02:00
|
|
|
IsFavorite: true,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2020-04-19 09:27:28 +02:00
|
|
|
BucketID: 1,
|
2021-07-28 21:06:40 +02:00
|
|
|
Position: 2,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task30 := &Task{
|
|
|
|
ID: 30,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #30 with assignees",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-15",
|
|
|
|
Index: 15,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
2020-01-26 18:08:06 +01:00
|
|
|
Assignees: []*user.User{
|
2019-12-07 15:30:51 +01:00
|
|
|
user1,
|
|
|
|
user2,
|
|
|
|
},
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task31 := &Task{
|
|
|
|
ID: 31,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #31 with color",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-16",
|
|
|
|
Index: 16,
|
2019-12-07 15:30:51 +01:00
|
|
|
HexColor: "f0f0f0",
|
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task32 := &Task{
|
|
|
|
ID: 32,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #32",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test3-1",
|
|
|
|
Index: 1,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 3,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 21,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
task33 := &Task{
|
|
|
|
ID: 33,
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "task #33 with percent done",
|
2019-12-07 23:28:45 +01:00
|
|
|
Identifier: "test1-17",
|
|
|
|
Index: 17,
|
2019-12-07 15:30:51 +01:00
|
|
|
CreatedByID: 1,
|
|
|
|
CreatedBy: user1,
|
|
|
|
ListID: 1,
|
|
|
|
PercentDone: 0.5,
|
|
|
|
RelatedTasks: map[RelationKind][]*Task{},
|
2020-04-25 22:32:02 +02:00
|
|
|
BucketID: 1,
|
2020-06-27 19:04:01 +02:00
|
|
|
Created: time.Unix(1543626724, 0).In(loc),
|
|
|
|
Updated: time.Unix(1543626724, 0).In(loc),
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type fields struct {
|
2020-04-11 16:20:33 +02:00
|
|
|
ListID int64
|
|
|
|
Lists []*List
|
|
|
|
SortBy []string // Is a string, since this is the place where a query string comes from the user
|
|
|
|
OrderBy []string
|
|
|
|
|
2020-06-27 19:04:01 +02:00
|
|
|
FilterBy []string
|
|
|
|
FilterValue []string
|
|
|
|
FilterComparator []string
|
|
|
|
FilterIncludeNulls bool
|
2020-04-11 16:20:33 +02:00
|
|
|
|
|
|
|
CRUDable web.CRUDable
|
|
|
|
Rights web.Rights
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
search string
|
|
|
|
a web.Auth
|
|
|
|
page int
|
|
|
|
}
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want interface{}
|
|
|
|
wantErr bool
|
|
|
|
}
|
2020-04-11 16:20:33 +02:00
|
|
|
|
|
|
|
defaultArgs := args{
|
|
|
|
search: "",
|
|
|
|
a: &user.User{ID: 1},
|
|
|
|
page: 0,
|
|
|
|
}
|
|
|
|
|
2019-12-07 15:30:51 +01:00
|
|
|
tests := []testcase{
|
|
|
|
{
|
|
|
|
name: "ReadAll Tasks normally",
|
|
|
|
fields: fields{},
|
2020-04-11 16:20:33 +02:00
|
|
|
args: defaultArgs,
|
2019-12-07 15:30:51 +01:00
|
|
|
want: []*Task{
|
|
|
|
task1,
|
|
|
|
task2,
|
|
|
|
task3,
|
|
|
|
task4,
|
|
|
|
task5,
|
|
|
|
task6,
|
|
|
|
task7,
|
|
|
|
task8,
|
|
|
|
task9,
|
|
|
|
task10,
|
|
|
|
task11,
|
|
|
|
task12,
|
|
|
|
task15,
|
|
|
|
task16,
|
|
|
|
task17,
|
|
|
|
task18,
|
|
|
|
task19,
|
|
|
|
task20,
|
|
|
|
task21,
|
|
|
|
task22,
|
|
|
|
task23,
|
|
|
|
task24,
|
|
|
|
task25,
|
|
|
|
task26,
|
|
|
|
task27,
|
|
|
|
task28,
|
|
|
|
task29,
|
|
|
|
task30,
|
|
|
|
task31,
|
|
|
|
task32,
|
|
|
|
task33,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// For more sorting tests see task_collection_sort_test.go
|
|
|
|
name: "ReadAll Tasks sorted by done asc and id desc",
|
|
|
|
fields: fields{
|
|
|
|
SortBy: []string{"done", "id"},
|
|
|
|
OrderBy: []string{"asc", "desc"},
|
|
|
|
},
|
2020-04-11 16:20:33 +02:00
|
|
|
args: defaultArgs,
|
2019-12-07 15:30:51 +01:00
|
|
|
want: []*Task{
|
|
|
|
task33,
|
|
|
|
task32,
|
|
|
|
task31,
|
|
|
|
task30,
|
|
|
|
task29,
|
|
|
|
task28,
|
|
|
|
task27,
|
|
|
|
task26,
|
|
|
|
task25,
|
|
|
|
task24,
|
|
|
|
task23,
|
|
|
|
task22,
|
|
|
|
task21,
|
|
|
|
task20,
|
|
|
|
task19,
|
|
|
|
task18,
|
|
|
|
task17,
|
|
|
|
task16,
|
|
|
|
task15,
|
|
|
|
task12,
|
|
|
|
task11,
|
|
|
|
task10,
|
|
|
|
task9,
|
|
|
|
task8,
|
|
|
|
task7,
|
|
|
|
task6,
|
|
|
|
task5,
|
|
|
|
task4,
|
|
|
|
task3,
|
|
|
|
task1,
|
2019-12-07 17:21:37 +01:00
|
|
|
task2,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ReadAll Tasks with range",
|
|
|
|
fields: fields{
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterBy: []string{"start_date", "end_date"},
|
2020-06-27 19:04:01 +02:00
|
|
|
FilterValue: []string{"2018-12-11T03:46:40+00:00", "2018-12-13T11:20:01+00:00"},
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterComparator: []string{"greater", "less"},
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
2020-04-11 16:20:33 +02:00
|
|
|
args: defaultArgs,
|
2019-12-07 15:30:51 +01:00
|
|
|
want: []*Task{
|
|
|
|
task7,
|
2020-04-11 16:20:33 +02:00
|
|
|
task8,
|
2019-12-07 15:30:51 +01:00
|
|
|
task9,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
2020-04-11 16:20:33 +02:00
|
|
|
name: "ReadAll Tasks with different range",
|
2019-12-07 15:30:51 +01:00
|
|
|
fields: fields{
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterBy: []string{"start_date", "end_date"},
|
2020-06-27 19:04:01 +02:00
|
|
|
FilterValue: []string{"2018-12-13T11:20:00+00:00", "2018-12-16T22:40:00+00:00"},
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterComparator: []string{"greater", "less"},
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
2020-04-11 16:20:33 +02:00
|
|
|
args: defaultArgs,
|
2019-12-07 15:30:51 +01:00
|
|
|
want: []*Task{
|
|
|
|
task8,
|
|
|
|
task9,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
2020-04-11 16:20:33 +02:00
|
|
|
name: "ReadAll Tasks with range with start date only",
|
2019-12-07 15:30:51 +01:00
|
|
|
fields: fields{
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterBy: []string{"start_date"},
|
2020-06-27 19:04:01 +02:00
|
|
|
FilterValue: []string{"2018-12-12T07:33:20+00:00"},
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterComparator: []string{"greater"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ReadAll Tasks with range with start date only and greater equals",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"start_date"},
|
2020-06-27 19:04:01 +02:00
|
|
|
FilterValue: []string{"2018-12-12T07:33:20+00:00"},
|
2020-04-11 16:20:33 +02:00
|
|
|
FilterComparator: []string{"greater_equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task7,
|
|
|
|
task9,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
2020-04-11 16:20:33 +02:00
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "undone tasks only",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"done"},
|
|
|
|
FilterValue: []string{"false"},
|
|
|
|
FilterComparator: []string{"equals"},
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
2020-04-11 16:20:33 +02:00
|
|
|
args: defaultArgs,
|
2019-12-07 15:30:51 +01:00
|
|
|
want: []*Task{
|
2020-04-11 16:20:33 +02:00
|
|
|
task1,
|
|
|
|
// Task 2 is done
|
|
|
|
task3,
|
|
|
|
task4,
|
|
|
|
task5,
|
|
|
|
task6,
|
|
|
|
task7,
|
2019-12-07 15:30:51 +01:00
|
|
|
task8,
|
|
|
|
task9,
|
2020-04-11 16:20:33 +02:00
|
|
|
task10,
|
|
|
|
task11,
|
|
|
|
task12,
|
|
|
|
task15,
|
|
|
|
task16,
|
|
|
|
task17,
|
|
|
|
task18,
|
|
|
|
task19,
|
|
|
|
task20,
|
|
|
|
task21,
|
|
|
|
task22,
|
|
|
|
task23,
|
|
|
|
task24,
|
|
|
|
task25,
|
|
|
|
task26,
|
|
|
|
task27,
|
|
|
|
task28,
|
|
|
|
task29,
|
|
|
|
task30,
|
|
|
|
task31,
|
|
|
|
task32,
|
|
|
|
task33,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "done tasks only",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"done"},
|
|
|
|
FilterValue: []string{"true"},
|
|
|
|
FilterComparator: []string{"equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task2,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "done tasks only - not equals done",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"done"},
|
|
|
|
FilterValue: []string{"false"},
|
|
|
|
FilterComparator: []string{"not_equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task2,
|
2019-12-07 15:30:51 +01:00
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2020-06-27 19:04:01 +02:00
|
|
|
{
|
|
|
|
name: "range with nulls",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"start_date", "end_date"},
|
|
|
|
FilterValue: []string{"2018-12-11T03:46:40+00:00", "2018-12-13T11:20:01+00:00"},
|
|
|
|
FilterComparator: []string{"greater", "less"},
|
|
|
|
FilterIncludeNulls: true,
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task1, // has nil dates
|
|
|
|
task2, // has nil dates
|
|
|
|
task3, // has nil dates
|
|
|
|
task4, // has nil dates
|
|
|
|
task5, // has nil dates
|
|
|
|
task6, // has nil dates
|
|
|
|
task7,
|
|
|
|
task8,
|
|
|
|
task9,
|
|
|
|
task10, // has nil dates
|
|
|
|
task11, // has nil dates
|
|
|
|
task12, // has nil dates
|
|
|
|
task15, // has nil dates
|
|
|
|
task16, // has nil dates
|
|
|
|
task17, // has nil dates
|
|
|
|
task18, // has nil dates
|
|
|
|
task19, // has nil dates
|
|
|
|
task20, // has nil dates
|
|
|
|
task21, // has nil dates
|
|
|
|
task22, // has nil dates
|
|
|
|
task23, // has nil dates
|
|
|
|
task24, // has nil dates
|
|
|
|
task25, // has nil dates
|
|
|
|
task26, // has nil dates
|
|
|
|
task27, // has nil dates
|
|
|
|
task28, // has nil dates
|
|
|
|
task29, // has nil dates
|
|
|
|
task30, // has nil dates
|
|
|
|
task31, // has nil dates
|
|
|
|
task32, // has nil dates
|
|
|
|
task33, // has nil dates
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2020-09-05 22:16:02 +02:00
|
|
|
{
|
|
|
|
name: "favorited tasks",
|
|
|
|
args: defaultArgs,
|
|
|
|
fields: fields{
|
|
|
|
ListID: FavoritesPseudoList.ID,
|
|
|
|
},
|
|
|
|
want: []*Task{
|
|
|
|
task1,
|
|
|
|
task15,
|
|
|
|
// Task 34 is also a favorite, but on a list user 1 has no access to.
|
|
|
|
},
|
|
|
|
},
|
2020-12-19 13:56:55 +01:00
|
|
|
{
|
|
|
|
name: "filtered with like",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"title"},
|
|
|
|
FilterValue: []string{"with"},
|
|
|
|
FilterComparator: []string{"like"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task7,
|
|
|
|
task8,
|
|
|
|
task9,
|
|
|
|
task27,
|
|
|
|
task28,
|
|
|
|
task29,
|
|
|
|
task30,
|
|
|
|
task31,
|
|
|
|
task33,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2020-12-19 16:14:20 +01:00
|
|
|
{
|
|
|
|
name: "filtered reminders",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"reminders", "reminders"},
|
|
|
|
FilterValue: []string{"2018-10-01T00:00:00+00:00", "2018-12-10T00:00:00+00:00"},
|
|
|
|
FilterComparator: []string{"greater", "less"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
2021-01-31 13:09:14 +01:00
|
|
|
task2,
|
2020-12-19 16:14:20 +01:00
|
|
|
task27,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2020-12-19 22:39:11 +01:00
|
|
|
{
|
|
|
|
name: "filter in",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"id"},
|
|
|
|
FilterValue: []string{"1,2,34"}, // Task 34 is forbidden for user 1
|
|
|
|
FilterComparator: []string{"in"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task1,
|
|
|
|
task2,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filter assignees",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"assignees"},
|
|
|
|
FilterValue: []string{"1"},
|
|
|
|
FilterComparator: []string{"equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task30,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filter assignees in",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"assignees"},
|
|
|
|
FilterValue: []string{"1,2"},
|
|
|
|
FilterComparator: []string{"in"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task30,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2020-12-20 13:41:36 +01:00
|
|
|
{
|
|
|
|
name: "filter labels",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"labels"},
|
|
|
|
FilterValue: []string{"4"},
|
|
|
|
FilterComparator: []string{"equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task1,
|
|
|
|
task2,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2020-12-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
name: "filter list",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"list_id"},
|
|
|
|
FilterValue: []string{"6"},
|
|
|
|
FilterComparator: []string{"equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task15,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filter namespace",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"namespace"},
|
|
|
|
FilterValue: []string{"7"},
|
|
|
|
FilterComparator: []string{"equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task21,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filter namespace in",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"namespace"},
|
|
|
|
FilterValue: []string{"7,8"},
|
|
|
|
FilterComparator: []string{"in"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task21,
|
|
|
|
task22,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
2021-03-21 18:48:41 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "filter by index",
|
|
|
|
fields: fields{
|
|
|
|
FilterBy: []string{"index"},
|
|
|
|
FilterValue: []string{"5"},
|
|
|
|
FilterComparator: []string{"equals"},
|
|
|
|
},
|
|
|
|
args: defaultArgs,
|
|
|
|
want: []*Task{
|
|
|
|
task5,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
2021-07-11 14:19:48 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "search for task index",
|
|
|
|
fields: fields{},
|
|
|
|
args: args{
|
|
|
|
search: "number #17",
|
|
|
|
a: &user.User{ID: 1},
|
|
|
|
page: 0,
|
|
|
|
},
|
|
|
|
want: []*Task{
|
|
|
|
task33, // has the index 17
|
|
|
|
},
|
|
|
|
wantErr: false,
|
2020-12-22 00:13:15 +01:00
|
|
|
},
|
2021-07-28 21:06:40 +02:00
|
|
|
{
|
|
|
|
name: "order by position",
|
|
|
|
fields: fields{
|
|
|
|
SortBy: []string{"position", "id"},
|
|
|
|
OrderBy: []string{"asc", "asc"},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
a: &user.User{ID: 1},
|
|
|
|
},
|
|
|
|
want: []*Task{
|
2022-05-30 22:53:58 +02:00
|
|
|
// The only tasks with a position set
|
|
|
|
task1,
|
|
|
|
task2,
|
2021-07-28 21:06:40 +02:00
|
|
|
// the other ones don't have a position set
|
|
|
|
task3,
|
|
|
|
task4,
|
|
|
|
task5,
|
|
|
|
task6,
|
|
|
|
task7,
|
|
|
|
task8,
|
|
|
|
task9,
|
|
|
|
task10,
|
|
|
|
task11,
|
|
|
|
task12,
|
|
|
|
task15,
|
|
|
|
task16,
|
|
|
|
task17,
|
|
|
|
task18,
|
|
|
|
task19,
|
|
|
|
task20,
|
|
|
|
task21,
|
|
|
|
task22,
|
|
|
|
task23,
|
|
|
|
task24,
|
|
|
|
task25,
|
|
|
|
task26,
|
|
|
|
task27,
|
|
|
|
task28,
|
|
|
|
task29,
|
|
|
|
task30,
|
|
|
|
task31,
|
|
|
|
task32,
|
|
|
|
task33,
|
2022-05-30 22:53:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "order by due date",
|
|
|
|
fields: fields{
|
|
|
|
SortBy: []string{"due_date", "id"},
|
|
|
|
OrderBy: []string{"asc", "desc"},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
a: &user.User{ID: 1},
|
|
|
|
},
|
|
|
|
want: []*Task{
|
|
|
|
// The only tasks with a due date
|
|
|
|
task6,
|
|
|
|
task5,
|
|
|
|
// The other ones don't have a due date
|
|
|
|
task33,
|
|
|
|
task32,
|
|
|
|
task31,
|
|
|
|
task30,
|
|
|
|
task29,
|
|
|
|
task28,
|
|
|
|
task27,
|
|
|
|
task26,
|
|
|
|
task25,
|
|
|
|
task24,
|
|
|
|
task23,
|
|
|
|
task22,
|
|
|
|
task21,
|
|
|
|
task20,
|
|
|
|
task19,
|
|
|
|
task18,
|
|
|
|
task17,
|
|
|
|
task16,
|
|
|
|
task15,
|
|
|
|
task12,
|
|
|
|
task11,
|
|
|
|
task10,
|
|
|
|
task9,
|
|
|
|
task8,
|
|
|
|
task7,
|
|
|
|
task4,
|
|
|
|
task3,
|
2021-07-28 21:06:40 +02:00
|
|
|
task2,
|
2022-05-30 22:53:58 +02:00
|
|
|
task1,
|
2021-07-28 21:06:40 +02:00
|
|
|
},
|
2021-11-14 21:03:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "saved filter with sort order",
|
|
|
|
fields: fields{
|
|
|
|
ListID: -2,
|
|
|
|
SortBy: []string{"title", "id"},
|
|
|
|
OrderBy: []string{"desc", "asc"},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
a: &user.User{ID: 1},
|
|
|
|
},
|
|
|
|
want: []*Task{
|
|
|
|
task9,
|
|
|
|
task8,
|
|
|
|
task7,
|
|
|
|
task6,
|
|
|
|
task5,
|
|
|
|
},
|
2021-07-28 21:06:40 +02:00
|
|
|
},
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-01-26 18:08:06 +01:00
|
|
|
db.LoadAndAssertFixtures(t)
|
2020-12-23 16:32:28 +01:00
|
|
|
s := db.NewSession()
|
|
|
|
defer s.Close()
|
2020-01-26 18:08:06 +01:00
|
|
|
|
2019-12-07 15:30:51 +01:00
|
|
|
lt := &TaskCollection{
|
2020-04-11 16:20:33 +02:00
|
|
|
ListID: tt.fields.ListID,
|
|
|
|
SortBy: tt.fields.SortBy,
|
|
|
|
OrderBy: tt.fields.OrderBy,
|
|
|
|
|
2020-06-27 19:04:01 +02:00
|
|
|
FilterBy: tt.fields.FilterBy,
|
|
|
|
FilterValue: tt.fields.FilterValue,
|
|
|
|
FilterComparator: tt.fields.FilterComparator,
|
|
|
|
FilterIncludeNulls: tt.fields.FilterIncludeNulls,
|
2020-04-11 16:20:33 +02:00
|
|
|
|
|
|
|
CRUDable: tt.fields.CRUDable,
|
|
|
|
Rights: tt.fields.Rights,
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
2020-12-23 16:32:28 +01:00
|
|
|
got, _, _, err := lt.ReadAll(s, tt.args.a, tt.args.search, tt.args.page, 50)
|
2019-12-07 15:30:51 +01:00
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("Test %s, Task.ReadAll() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if diff, equal := messagediff.PrettyDiff(got, tt.want); !equal {
|
2020-04-11 16:20:33 +02:00
|
|
|
if len(got.([]*Task)) == 0 && len(tt.want.([]*Task)) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Errorf("Test %s, Task.ReadAll() = %v, want %v, \ndiff: %v", tt.name, got, tt.want, diff)
|
2019-12-07 15:30:51 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|