Add test for creating and fix
This commit is contained in:
parent
0f95a667df
commit
9d17ec4cb3
|
@ -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
|
||||
|
|
|
@ -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 := ¤tTasks{}
|
||||
_, 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}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue