vikunja-api/pkg/models/bulk_task_test.go

74 lines
1.4 KiB
Go
Raw Normal View History

2018-12-28 22:49:46 +01:00
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
2018-12-28 22:49:46 +01:00
"testing"
)
func TestBulkTask_Update(t *testing.T) {
type fields struct {
2019-08-14 22:19:04 +02:00
IDs []int64
Tasks []*Task
Task Task
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{
Title: "bulkupdated",
2018-12-28 22:49:46 +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{
Title: "bulkupdated",
2018-12-28 22:49:46 +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{
Title: "bulkupdated",
2018-12-28 22:49:46 +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) {
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)
}
})
}
}