fix(views): test assertions

This commit is contained in:
kolaente 2024-03-18 23:09:17 +01:00
parent 9075a45cb8
commit 409f9a0cc6
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 102 additions and 103 deletions

View File

@ -220,8 +220,8 @@ func TestBucket_Delete(t *testing.T) {
require.NoError(t, err)
db.AssertMissing(t, "project_views", map[string]interface{}{
"id": 4,
"done_bucket_id": 3,
"id": b.ProjectViewID,
"done_bucket_id": 0,
})
})
}

View File

@ -53,8 +53,25 @@ func TestProject_CreateOrUpdate(t *testing.T) {
"description": project.Description,
"parent_project_id": 0,
}, false)
db.AssertExists(t, "buckets", map[string]interface{}{
db.AssertExists(t, "project_views", map[string]interface{}{
"project_id": project.ID,
"view_kind": ProjectViewKindList,
}, false)
db.AssertExists(t, "project_views", map[string]interface{}{
"project_id": project.ID,
"view_kind": ProjectViewKindGantt,
}, false)
db.AssertExists(t, "project_views", map[string]interface{}{
"project_id": project.ID,
"view_kind": ProjectViewKindTable,
}, false)
db.AssertExists(t, "project_views", map[string]interface{}{
"project_id": project.ID,
"view_kind": ProjectViewKindKanban,
"bucket_configuration_mode": BucketConfigurationModeManual,
}, false)
db.AssertExists(t, "buckets", map[string]interface{}{
"project_view_id": project.ID * 4, // FIXME: Dirty hack to get the project view id
}, false)
})
t.Run("nonexistant parent project", func(t *testing.T) {

View File

@ -61,7 +61,6 @@ func TestSortParamValidation(t *testing.T) {
taskPropertyUID,
taskPropertyCreated,
taskPropertyUpdated,
taskPropertyPosition,
} {
t.Run(test, func(t *testing.T) {
s := &sortParam{

View File

@ -95,9 +95,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedByID: 1,
CreatedBy: user1,
ProjectID: 1,
BucketID: 1,
IsFavorite: true,
Position: 2,
Reactions: ReactionMap{
"👋": []*user.User{user1},
},
@ -112,7 +110,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 14,
CreatedByID: 1,
ProjectID: 1,
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
},
@ -170,8 +167,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedByID: 1,
CreatedBy: user1,
ProjectID: 1,
BucketID: 1,
Position: 4,
Labels: []*Label{
label4,
},
@ -199,7 +194,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
Priority: 100,
BucketID: 2,
}
task4 := &Task{
ID: 4,
@ -213,7 +207,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
Priority: 1,
BucketID: 2,
}
task5 := &Task{
ID: 5,
@ -227,7 +220,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
DueDate: time.Unix(1543636724, 0).In(loc),
BucketID: 2,
}
task6 := &Task{
ID: 6,
@ -241,7 +233,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
DueDate: time.Unix(1543616724, 0).In(loc),
BucketID: 3,
}
task7 := &Task{
ID: 7,
@ -255,7 +246,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
StartDate: time.Unix(1544600000, 0).In(loc),
BucketID: 3,
}
task8 := &Task{
ID: 8,
@ -269,7 +259,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
EndDate: time.Unix(1544700000, 0).In(loc),
BucketID: 3,
}
task9 := &Task{
ID: 9,
@ -280,7 +269,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
StartDate: time.Unix(1544600000, 0).In(loc),
@ -295,7 +283,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -308,7 +295,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -321,7 +307,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -335,7 +320,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
ProjectID: 6,
IsFavorite: true,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 6,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -348,7 +332,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 7,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 7,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -361,7 +344,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 8,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 8,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -374,7 +356,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 9,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 9,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -387,7 +368,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 10,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 10,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -400,7 +380,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 11,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 11,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -413,7 +392,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 32, // parent project is shared to user 1 via direct share
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 12,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -426,7 +404,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 33,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 36,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -439,7 +416,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 34,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 37,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -452,7 +428,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 15, // parent project is shared to user 1 via team
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 15,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -465,7 +440,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 16,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 16,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -478,7 +452,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user6,
ProjectID: 17,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 17,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -507,7 +480,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
},
StartDate: time.Unix(1543616724, 0).In(loc),
ProjectID: 1,
BucketID: 1,
RelatedTasks: map[RelationKind][]*Task{},
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
@ -522,7 +494,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{},
RepeatAfter: 3600,
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -546,14 +517,11 @@ func TestTaskCollection_ReadAll(t *testing.T) {
IsFavorite: true,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
BucketID: 1,
Position: 2,
},
},
},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
task30 := &Task{
ID: 30,
@ -568,7 +536,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
user2,
},
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -582,7 +549,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -595,7 +561,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 3,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 21,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -609,7 +574,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
ProjectID: 1,
PercentDone: 0.5,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -639,8 +603,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
IsFavorite: true,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
BucketID: 1,
Position: 2,
},
{
ID: 1,
@ -652,14 +614,11 @@ func TestTaskCollection_ReadAll(t *testing.T) {
IsFavorite: true,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
BucketID: 1,
Position: 2,
},
},
},
BucketID: 19,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
task39 := &Task{
ID: 39,
@ -669,16 +628,16 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1,
ProjectID: 25,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 0,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
type fields struct {
ProjectID int64
Projects []*Project
SortBy []string // Is a string, since this is the place where a query string comes from the user
OrderBy []string
ProjectID int64
ProjectViewID int64
Projects []*Project
SortBy []string // Is a string, since this is the place where a query string comes from the user
OrderBy []string
FilterIncludeNulls bool
Filter string
@ -705,6 +664,13 @@ func TestTaskCollection_ReadAll(t *testing.T) {
page: 0,
}
taskWithPosition := func(task *Task, position float64) *Task {
newTask := &Task{}
*newTask = *task
newTask.Position = position
return newTask
}
tests := []testcase{
{
name: "ReadAll Tasks normally",
@ -1258,16 +1224,18 @@ func TestTaskCollection_ReadAll(t *testing.T) {
{
name: "order by position",
fields: fields{
SortBy: []string{"position", "id"},
OrderBy: []string{"asc", "asc"},
SortBy: []string{"position", "id"},
OrderBy: []string{"asc", "asc"},
ProjectViewID: 1,
ProjectID: 1,
},
args: args{
a: &user.User{ID: 1},
},
want: []*Task{
// The only tasks with a position set
task1,
task2,
taskWithPosition(task1, 2),
taskWithPosition(task2, 4),
// the other ones don't have a position set
task3,
task4,
@ -1279,27 +1247,24 @@ func TestTaskCollection_ReadAll(t *testing.T) {
task10,
task11,
task12,
task15,
task16,
task17,
task18,
task19,
task20,
task21,
task22,
task23,
task24,
task25,
task26,
//task15,
//task16,
//task17,
//task18,
//task19,
//task20,
//task21,
//task22,
//task23,
//task24,
//task25,
//task26,
task27,
task28,
task29,
task30,
task31,
task32,
task33,
task35,
task39,
},
},
{
@ -1414,9 +1379,10 @@ func TestTaskCollection_ReadAll(t *testing.T) {
defer s.Close()
lt := &TaskCollection{
ProjectID: tt.fields.ProjectID,
SortBy: tt.fields.SortBy,
OrderBy: tt.fields.OrderBy,
ProjectID: tt.fields.ProjectID,
ProjectViewID: tt.fields.ProjectViewID,
SortBy: tt.fields.SortBy,
OrderBy: tt.fields.OrderBy,
FilterIncludeNulls: tt.fields.FilterIncludeNulls,

View File

@ -55,8 +55,6 @@ func TestTask_Create(t *testing.T) {
// Assert getting a new index
assert.NotEmpty(t, task.Index)
assert.Equal(t, int64(18), task.Index)
// Assert moving it into the default bucket
assert.Equal(t, int64(1), task.BucketID)
err = s.Commit()
require.NoError(t, err)
@ -66,7 +64,10 @@ func TestTask_Create(t *testing.T) {
"description": "Lorem Ipsum Dolor",
"project_id": 1,
"created_by_id": 1,
"bucket_id": 1,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": task.ID,
"bucket_id": 1,
}, false)
events.AssertDispatched(t, &TaskCreatedEvent{})
@ -183,8 +184,8 @@ func TestTask_Create(t *testing.T) {
}
err := task.Create(s, usr)
require.NoError(t, err)
db.AssertExists(t, "tasks", map[string]interface{}{
"id": task.ID,
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": task.ID,
"bucket_id": 22, // default bucket of project 6 but with a position of 2
}, false)
})
@ -276,7 +277,7 @@ func TestTask_Update(t *testing.T) {
}
err := task.Update(s, u)
require.Error(t, err)
assert.True(t, IsErrBucketDoesNotBelongToProject(err))
assert.True(t, IsErrBucketDoesNotExist(err))
})
t.Run("moving a task to the done bucket", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
@ -296,11 +297,12 @@ func TestTask_Update(t *testing.T) {
assert.True(t, task.Done)
db.AssertExists(t, "tasks", map[string]interface{}{
"id": 1,
"done": true,
"title": "test",
"project_id": 1,
"bucket_id": 3,
"id": 1,
"done": true,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": 1,
"bucket_id": 3,
}, false)
})
t.Run("moving a repeating task to the done bucket", func(t *testing.T) {
@ -320,14 +322,15 @@ func TestTask_Update(t *testing.T) {
err = s.Commit()
require.NoError(t, err)
assert.False(t, task.Done)
assert.Equal(t, int64(1), task.BucketID) // Bucket should not be updated
assert.Equal(t, int64(3), task.BucketID)
db.AssertExists(t, "tasks", map[string]interface{}{
"id": 28,
"done": false,
"title": "test updated",
"project_id": 1,
"bucket_id": 1,
"id": 1,
"done": false,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": 1,
"bucket_id": 1,
}, false)
})
t.Run("default bucket when moving a task between projects", func(t *testing.T) {
@ -344,7 +347,11 @@ func TestTask_Update(t *testing.T) {
err = s.Commit()
require.NoError(t, err)
assert.Equal(t, int64(40), task.BucketID) // bucket 40 is the default bucket on project 2
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": task.ID,
// bucket 40 is the default bucket on project 2
"bucket_id": 40,
}, false)
})
t.Run("marking a task as done should move it to the done bucket", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
@ -360,11 +367,13 @@ func TestTask_Update(t *testing.T) {
err = s.Commit()
require.NoError(t, err)
assert.True(t, task.Done)
assert.Equal(t, int64(3), task.BucketID)
db.AssertExists(t, "tasks", map[string]interface{}{
"id": 1,
"done": true,
"id": 1,
"done": true,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": 1,
"bucket_id": 3,
}, false)
})
@ -385,7 +394,10 @@ func TestTask_Update(t *testing.T) {
db.AssertExists(t, "tasks", map[string]interface{}{
"id": 1,
"project_id": 2,
"bucket_id": 40,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": 1,
"bucket_id": 40,
}, false)
})
t.Run("move done task to another project with a done bucket", func(t *testing.T) {
@ -404,11 +416,14 @@ func TestTask_Update(t *testing.T) {
require.NoError(t, err)
db.AssertExists(t, "tasks", map[string]interface{}{
"id": 2,
"id": task.ID,
"project_id": 2,
"bucket_id": 4, // 4 is the done bucket
"done": true,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": task.ID,
"bucket_id": 4, // 4 is the done bucket
}, false)
})
t.Run("repeating tasks should not be moved to the done bucket", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
@ -425,11 +440,13 @@ func TestTask_Update(t *testing.T) {
err = s.Commit()
require.NoError(t, err)
assert.False(t, task.Done)
assert.Equal(t, int64(1), task.BucketID)
db.AssertExists(t, "tasks", map[string]interface{}{
"id": 28,
"done": false,
"id": 28,
"done": false,
}, false)
db.AssertExists(t, "task_buckets", map[string]interface{}{
"task_id": 28,
"bucket_id": 1,
}, false)
})