2018-12-28 22:49:46 +01:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2020-10-11 22:10:03 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-01-26 18:08:06 +01:00
|
|
|
"code.vikunja.io/api/pkg/db"
|
|
|
|
"code.vikunja.io/api/pkg/user"
|
2018-12-28 22:49:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBulkTask_Update(t *testing.T) {
|
|
|
|
type fields struct {
|
2019-08-14 22:19:04 +02:00
|
|
|
IDs []int64
|
|
|
|
Tasks []*Task
|
|
|
|
Task Task
|
2020-01-26 18:08:06 +01:00
|
|
|
User *user.User
|
2018-12-28 22:49:46 +01:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
wantForbidden bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test normal update",
|
|
|
|
fields: fields{
|
|
|
|
IDs: []int64{10, 11, 12},
|
2019-08-14 22:19:04 +02:00
|
|
|
Task: Task{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "bulkupdated",
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
2020-01-26 18:08:06 +01:00
|
|
|
User: &user.User{ID: 1},
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test with one task on different list",
|
|
|
|
fields: fields{
|
|
|
|
IDs: []int64{10, 11, 12, 13},
|
2019-08-14 22:19:04 +02:00
|
|
|
Task: Task{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "bulkupdated",
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
2020-01-26 18:08:06 +01:00
|
|
|
User: &user.User{ID: 1},
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
|
|
|
wantForbidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test without any tasks",
|
|
|
|
fields: fields{
|
|
|
|
IDs: []int64{},
|
2019-08-14 22:19:04 +02:00
|
|
|
Task: Task{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "bulkupdated",
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
2020-01-26 18:08:06 +01:00
|
|
|
User: &user.User{ID: 1},
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
|
|
|
wantForbidden: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
|
2018-12-28 22:49:46 +01:00
|
|
|
bt := &BulkTask{
|
2019-08-14 22:19:04 +02:00
|
|
|
IDs: tt.fields.IDs,
|
|
|
|
Tasks: tt.fields.Tasks,
|
|
|
|
Task: tt.fields.Task,
|
2018-12-28 22:49:46 +01:00
|
|
|
}
|
2020-12-23 16:32:28 +01:00
|
|
|
allowed, _ := bt.CanUpdate(s, tt.fields.User)
|
2018-12-28 22:49:46 +01:00
|
|
|
if !allowed != tt.wantForbidden {
|
|
|
|
t.Errorf("BulkTask.Update() want forbidden, got %v, want %v", allowed, tt.wantForbidden)
|
|
|
|
}
|
2020-12-23 16:32:28 +01:00
|
|
|
if err := bt.Update(s); (err != nil) != tt.wantErr {
|
2018-12-28 22:49:46 +01:00
|
|
|
t.Errorf("BulkTask.Update() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
2020-12-23 16:32:28 +01:00
|
|
|
|
|
|
|
s.Close()
|
2018-12-28 22:49:46 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|