Add test for creating and fix

This commit is contained in:
kolaente 2020-09-04 13:37:31 +02:00
parent 0f95a667df
commit 9d17ec4cb3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 16 additions and 8 deletions

View File

@ -8,6 +8,7 @@
title: testbucket2
list_id: 1
created_by_id: 1
limit: 3
created: 2020-04-18 21:13:52
updated: 2020-04-18 21:13:52
- id: 3

View File

@ -625,18 +625,13 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
// Check the limit
if bucket.Limit > 0 {
type currentTasks struct {
Count int64
}
taskCount := &currentTasks{}
_, err = s.
Table("tasks").
taskCount, err := s.
Where("bucket_id = ?", bucket.ID).
Count(taskCount)
Count(&Task{})
if err != nil {
return err
}
if taskCount.Count >= bucket.Limit {
if taskCount >= bucket.Limit {
return ErrBucketLimitExceeded{TaskID: t.ID, BucketID: bucket.ID, Limit: bucket.Limit}
}
}

View File

@ -85,6 +85,18 @@ func TestTask_Create(t *testing.T) {
assert.Error(t, err)
assert.True(t, user.IsErrUserDoesNotExist(err))
})
t.Run("full bucket", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
task := &Task{
Title: "Lorem",
Description: "Lorem Ipsum Dolor",
ListID: 1,
BucketID: 2, // Bucket 2 already has 3 tasks and a limit of 3
}
err := task.Create(usr)
assert.Error(t, err)
assert.True(t, IsErrBucketLimitExceeded(err))
})
}
func TestTask_Update(t *testing.T) {