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) require.NoError(t, err)
db.AssertMissing(t, "project_views", map[string]interface{}{ db.AssertMissing(t, "project_views", map[string]interface{}{
"id": 4, "id": b.ProjectViewID,
"done_bucket_id": 3, "done_bucket_id": 0,
}) })
}) })
} }

View File

@ -53,8 +53,25 @@ func TestProject_CreateOrUpdate(t *testing.T) {
"description": project.Description, "description": project.Description,
"parent_project_id": 0, "parent_project_id": 0,
}, false) }, false)
db.AssertExists(t, "buckets", map[string]interface{}{ db.AssertExists(t, "project_views", map[string]interface{}{
"project_id": project.ID, "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) }, false)
}) })
t.Run("nonexistant parent project", func(t *testing.T) { t.Run("nonexistant parent project", func(t *testing.T) {

View File

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

View File

@ -95,9 +95,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedByID: 1, CreatedByID: 1,
CreatedBy: user1, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
BucketID: 1,
IsFavorite: true, IsFavorite: true,
Position: 2,
Reactions: ReactionMap{ Reactions: ReactionMap{
"👋": []*user.User{user1}, "👋": []*user.User{user1},
}, },
@ -112,7 +110,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 14, Index: 14,
CreatedByID: 1, CreatedByID: 1,
ProjectID: 1, ProjectID: 1,
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedByID: 1,
CreatedBy: user1, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
BucketID: 1,
Position: 4,
Labels: []*Label{ Labels: []*Label{
label4, label4,
}, },
@ -199,7 +194,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
Priority: 100, Priority: 100,
BucketID: 2,
} }
task4 := &Task{ task4 := &Task{
ID: 4, ID: 4,
@ -213,7 +207,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
Priority: 1, Priority: 1,
BucketID: 2,
} }
task5 := &Task{ task5 := &Task{
ID: 5, ID: 5,
@ -227,7 +220,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
DueDate: time.Unix(1543636724, 0).In(loc), DueDate: time.Unix(1543636724, 0).In(loc),
BucketID: 2,
} }
task6 := &Task{ task6 := &Task{
ID: 6, ID: 6,
@ -241,7 +233,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
DueDate: time.Unix(1543616724, 0).In(loc), DueDate: time.Unix(1543616724, 0).In(loc),
BucketID: 3,
} }
task7 := &Task{ task7 := &Task{
ID: 7, ID: 7,
@ -255,7 +246,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
StartDate: time.Unix(1544600000, 0).In(loc), StartDate: time.Unix(1544600000, 0).In(loc),
BucketID: 3,
} }
task8 := &Task{ task8 := &Task{
ID: 8, ID: 8,
@ -269,7 +259,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
EndDate: time.Unix(1544700000, 0).In(loc), EndDate: time.Unix(1544700000, 0).In(loc),
BucketID: 3,
} }
task9 := &Task{ task9 := &Task{
ID: 9, ID: 9,
@ -280,7 +269,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
StartDate: time.Unix(1544600000, 0).In(loc), StartDate: time.Unix(1544600000, 0).In(loc),
@ -295,7 +283,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, ProjectID: 6,
IsFavorite: true, IsFavorite: true,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 6,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 7, ProjectID: 7,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 7,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 8, ProjectID: 8,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 8,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 9, ProjectID: 9,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 9,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 10, ProjectID: 10,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 10,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 11, ProjectID: 11,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 11,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 32, // parent project is shared to user 1 via direct share ProjectID: 32, // parent project is shared to user 1 via direct share
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 12,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 33, ProjectID: 33,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 36,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 34, ProjectID: 34,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 37,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 15, // parent project is shared to user 1 via team ProjectID: 15, // parent project is shared to user 1 via team
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 15,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 16, ProjectID: 16,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 16,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user6,
ProjectID: 17, ProjectID: 17,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 17,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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), StartDate: time.Unix(1543616724, 0).In(loc),
ProjectID: 1, ProjectID: 1,
BucketID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
RepeatAfter: 3600, RepeatAfter: 3600,
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
} }
@ -546,12 +517,9 @@ func TestTaskCollection_ReadAll(t *testing.T) {
IsFavorite: true, IsFavorite: true,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
} }
@ -568,7 +536,6 @@ func TestTaskCollection_ReadAll(t *testing.T) {
user2, user2,
}, },
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user1,
ProjectID: 1, ProjectID: 1,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, CreatedBy: user1,
ProjectID: 3, ProjectID: 3,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 21,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, ProjectID: 1,
PercentDone: 0.5, PercentDone: 0.5,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 1,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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, IsFavorite: true,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
BucketID: 1,
Position: 2,
}, },
{ {
ID: 1, ID: 1,
@ -652,12 +614,9 @@ func TestTaskCollection_ReadAll(t *testing.T) {
IsFavorite: true, IsFavorite: true,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: 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), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
} }
@ -669,13 +628,13 @@ func TestTaskCollection_ReadAll(t *testing.T) {
CreatedBy: user1, CreatedBy: user1,
ProjectID: 25, ProjectID: 25,
RelatedTasks: map[RelationKind][]*Task{}, RelatedTasks: map[RelationKind][]*Task{},
BucketID: 0,
Created: time.Unix(1543626724, 0).In(loc), Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc), Updated: time.Unix(1543626724, 0).In(loc),
} }
type fields struct { type fields struct {
ProjectID int64 ProjectID int64
ProjectViewID int64
Projects []*Project Projects []*Project
SortBy []string // Is a string, since this is the place where a query string comes from the user SortBy []string // Is a string, since this is the place where a query string comes from the user
OrderBy []string OrderBy []string
@ -705,6 +664,13 @@ func TestTaskCollection_ReadAll(t *testing.T) {
page: 0, page: 0,
} }
taskWithPosition := func(task *Task, position float64) *Task {
newTask := &Task{}
*newTask = *task
newTask.Position = position
return newTask
}
tests := []testcase{ tests := []testcase{
{ {
name: "ReadAll Tasks normally", name: "ReadAll Tasks normally",
@ -1260,14 +1226,16 @@ func TestTaskCollection_ReadAll(t *testing.T) {
fields: fields{ fields: fields{
SortBy: []string{"position", "id"}, SortBy: []string{"position", "id"},
OrderBy: []string{"asc", "asc"}, OrderBy: []string{"asc", "asc"},
ProjectViewID: 1,
ProjectID: 1,
}, },
args: args{ args: args{
a: &user.User{ID: 1}, a: &user.User{ID: 1},
}, },
want: []*Task{ want: []*Task{
// The only tasks with a position set // The only tasks with a position set
task1, taskWithPosition(task1, 2),
task2, taskWithPosition(task2, 4),
// the other ones don't have a position set // the other ones don't have a position set
task3, task3,
task4, task4,
@ -1279,27 +1247,24 @@ func TestTaskCollection_ReadAll(t *testing.T) {
task10, task10,
task11, task11,
task12, task12,
task15, //task15,
task16, //task16,
task17, //task17,
task18, //task18,
task19, //task19,
task20, //task20,
task21, //task21,
task22, //task22,
task23, //task23,
task24, //task24,
task25, //task25,
task26, //task26,
task27, task27,
task28, task28,
task29, task29,
task30, task30,
task31, task31,
task32,
task33, task33,
task35,
task39,
}, },
}, },
{ {
@ -1415,6 +1380,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
lt := &TaskCollection{ lt := &TaskCollection{
ProjectID: tt.fields.ProjectID, ProjectID: tt.fields.ProjectID,
ProjectViewID: tt.fields.ProjectViewID,
SortBy: tt.fields.SortBy, SortBy: tt.fields.SortBy,
OrderBy: tt.fields.OrderBy, OrderBy: tt.fields.OrderBy,

View File

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