Add real buckets for tasks which don't have one (#446)
Add docs for error code Add moving new tasks into the default bucket when none was provided Add moving tasks in default bucket when deleting one Fix tests again Add test for removing a bucket Fix tests Prevent removing the last bucket Remove the empty pseudo bucket Add migration to create a new bucket for each list (and put all tasks in it Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/446
This commit is contained in:
@ -38,30 +38,55 @@ func TestBucket_ReadAll(t *testing.T) {
|
||||
assert.Equal(t, testuser.ID, buckets[0].CreatedBy.ID)
|
||||
assert.Equal(t, testuser.ID, buckets[1].CreatedBy.ID)
|
||||
assert.Equal(t, testuser.ID, buckets[2].CreatedBy.ID)
|
||||
assert.Equal(t, testuser.ID, buckets[3].CreatedBy.ID)
|
||||
|
||||
// Assert our three test buckets + one for all tasks without a bucket
|
||||
assert.Len(t, buckets, 4)
|
||||
// Assert our three test buckets
|
||||
assert.Len(t, buckets, 3)
|
||||
|
||||
// Assert all tasks are in the right bucket
|
||||
assert.Len(t, buckets[0].Tasks, 10)
|
||||
assert.Len(t, buckets[1].Tasks, 2)
|
||||
assert.Len(t, buckets[0].Tasks, 12)
|
||||
assert.Len(t, buckets[1].Tasks, 3)
|
||||
assert.Len(t, buckets[2].Tasks, 3)
|
||||
assert.Len(t, buckets[3].Tasks, 3)
|
||||
|
||||
// Assert we have bucket 0, 1, 2, 3 but not 4 (that belongs to a different list)
|
||||
assert.Equal(t, int64(1), buckets[1].ID)
|
||||
assert.Equal(t, int64(2), buckets[2].ID)
|
||||
assert.Equal(t, int64(3), buckets[3].ID)
|
||||
assert.Equal(t, int64(1), buckets[0].ID)
|
||||
assert.Equal(t, int64(2), buckets[1].ID)
|
||||
assert.Equal(t, int64(3), buckets[2].ID)
|
||||
|
||||
// Kinda assert all tasks are in the right buckets
|
||||
assert.Equal(t, int64(0), buckets[0].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(1), buckets[1].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(1), buckets[1].Tasks[1].BucketID)
|
||||
assert.Equal(t, int64(2), buckets[2].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(2), buckets[2].Tasks[1].BucketID)
|
||||
assert.Equal(t, int64(2), buckets[2].Tasks[2].BucketID)
|
||||
assert.Equal(t, int64(3), buckets[3].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(3), buckets[3].Tasks[1].BucketID)
|
||||
assert.Equal(t, int64(3), buckets[3].Tasks[2].BucketID)
|
||||
assert.Equal(t, int64(1), buckets[0].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(1), buckets[0].Tasks[1].BucketID)
|
||||
assert.Equal(t, int64(2), buckets[1].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(2), buckets[1].Tasks[1].BucketID)
|
||||
assert.Equal(t, int64(2), buckets[1].Tasks[2].BucketID)
|
||||
assert.Equal(t, int64(3), buckets[2].Tasks[0].BucketID)
|
||||
assert.Equal(t, int64(3), buckets[2].Tasks[1].BucketID)
|
||||
assert.Equal(t, int64(3), buckets[2].Tasks[2].BucketID)
|
||||
}
|
||||
|
||||
func TestBucket_Delete(t *testing.T) {
|
||||
t.Run("normal", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
b := &Bucket{
|
||||
ID: 2, // The second bucket only has 3 tasks
|
||||
ListID: 1,
|
||||
}
|
||||
err := b.Delete()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Assert all tasks have been moved to bucket 1 as that one is the first
|
||||
tasks := []*Task{}
|
||||
err = x.Where("bucket_id = ?", 1).Find(&tasks)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, tasks, 15)
|
||||
})
|
||||
t.Run("last bucket in list", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
b := &Bucket{
|
||||
ID: 34,
|
||||
ListID: 18,
|
||||
}
|
||||
err := b.Delete()
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrCannotRemoveLastBucket(err))
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user