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)
|
|
|
|
|
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
|
|
|
}
|
2019-03-24 13:35:50 +01:00
|
|
|
allowed, _ := bt.CanUpdate(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)
|
|
|
|
}
|
|
|
|
if err := bt.Update(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("BulkTask.Update() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|