From 9efa699e7b4ca9e71fc6764acbe0fa449640d49a Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 27 Jul 2021 16:36:03 +0200 Subject: [PATCH] Add more tests --- pkg/db/fixtures/tasks.yml | 2 ++ pkg/models/kanban_test.go | 3 +- pkg/models/task_collection_test.go | 48 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/pkg/db/fixtures/tasks.yml b/pkg/db/fixtures/tasks.yml index 4d944fd1a..ec0abf0bc 100644 --- a/pkg/db/fixtures/tasks.yml +++ b/pkg/db/fixtures/tasks.yml @@ -8,6 +8,7 @@ created: 2018-12-01 01:12:04 updated: 2018-12-01 01:12:04 bucket_id: 1 + position: 2 - id: 2 title: 'task #2 done' done: true @@ -17,6 +18,7 @@ created: 2018-12-01 01:12:04 updated: 2018-12-01 01:12:04 bucket_id: 1 + position: 4 - id: 3 title: 'task #3 high prio' done: false diff --git a/pkg/models/kanban_test.go b/pkg/models/kanban_test.go index 1d41809a0..504c38758 100644 --- a/pkg/models/kanban_test.go +++ b/pkg/models/kanban_test.go @@ -87,7 +87,8 @@ func TestBucket_ReadAll(t *testing.T) { buckets := bucketsInterface.([]*Bucket) assert.Len(t, buckets, 3) - assert.Equal(t, int64(2), buckets[0].Tasks[0].ID) + assert.Equal(t, int64(2), buckets[0].Tasks[1].ID) + assert.Equal(t, int64(33), buckets[0].Tasks[0].ID) }) t.Run("accessed by link share", func(t *testing.T) { db.LoadAndAssertFixtures(t) diff --git a/pkg/models/task_collection_test.go b/pkg/models/task_collection_test.go index 28b70dbd9..845289269 100644 --- a/pkg/models/task_collection_test.go +++ b/pkg/models/task_collection_test.go @@ -90,6 +90,7 @@ func TestTaskCollection_ReadAll(t *testing.T) { ListID: 1, BucketID: 1, IsFavorite: true, + Position: 2, Labels: []*Label{ label4, }, @@ -160,6 +161,7 @@ func TestTaskCollection_ReadAll(t *testing.T) { CreatedBy: user1, ListID: 1, BucketID: 1, + Position: 4, Labels: []*Label{ label4, }, @@ -517,6 +519,7 @@ func TestTaskCollection_ReadAll(t *testing.T) { Created: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc), BucketID: 1, + Position: 2, }, }, }, @@ -1033,6 +1036,51 @@ func TestTaskCollection_ReadAll(t *testing.T) { }, wantErr: false, }, + { + name: "order by position", + fields: fields{ + SortBy: []string{"position", "id"}, + OrderBy: []string{"asc", "asc"}, + }, + args: args{ + a: &user.User{ID: 1}, + }, + want: []*Task{ + // 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, + // The only tasks with a position set + task1, + task2, + }, + }, } for _, tt := range tests {