fix(tests): make the tests compile again
This commit is contained in:
@ -40,30 +40,29 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
project := Project{
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 1,
|
||||
}
|
||||
err := project.Create(s, usr)
|
||||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "projects", map[string]interface{}{
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
"namespace_id": project.NamespaceID,
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
"parent_project_id": 0,
|
||||
}, false)
|
||||
})
|
||||
t.Run("nonexistant namespace", func(t *testing.T) {
|
||||
t.Run("nonexistant parent project", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
project := Project{
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 999999,
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
ParentProjectID: 999999,
|
||||
}
|
||||
err := project.Create(s, usr)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrNamespaceDoesNotExist(err))
|
||||
assert.True(t, IsErrProjectDoesNotExist(err))
|
||||
_ = s.Close()
|
||||
})
|
||||
t.Run("nonexistant owner", func(t *testing.T) {
|
||||
@ -73,7 +72,6 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
project := Project{
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 1,
|
||||
}
|
||||
err := project.Create(s, usr)
|
||||
assert.Error(t, err)
|
||||
@ -87,7 +85,6 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
Identifier: "test1",
|
||||
NamespaceID: 1,
|
||||
}
|
||||
err := project.Create(s, usr)
|
||||
assert.Error(t, err)
|
||||
@ -100,17 +97,15 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
project := Project{
|
||||
Title: "приффки фсем",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 1,
|
||||
}
|
||||
err := project.Create(s, usr)
|
||||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "projects", map[string]interface{}{
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
"namespace_id": project.NamespaceID,
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
}, false)
|
||||
})
|
||||
})
|
||||
@ -123,7 +118,6 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
ID: 1,
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 1,
|
||||
}
|
||||
project.Description = "Lorem Ipsum dolor sit amet."
|
||||
err := project.Update(s, usr)
|
||||
@ -131,19 +125,17 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "projects", map[string]interface{}{
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
"namespace_id": project.NamespaceID,
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
}, false)
|
||||
})
|
||||
t.Run("nonexistant", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
project := Project{
|
||||
ID: 99999999,
|
||||
Title: "test",
|
||||
NamespaceID: 1,
|
||||
ID: 99999999,
|
||||
Title: "test",
|
||||
}
|
||||
err := project.Update(s, usr)
|
||||
assert.Error(t, err)
|
||||
@ -158,14 +150,13 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
Title: "test",
|
||||
Description: "Lorem Ipsum",
|
||||
Identifier: "test1",
|
||||
NamespaceID: 1,
|
||||
}
|
||||
err := project.Create(s, usr)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrProjectIdentifierIsNotUnique(err))
|
||||
_ = s.Close()
|
||||
})
|
||||
t.Run("change namespace", func(t *testing.T) {
|
||||
t.Run("change parent project", func(t *testing.T) {
|
||||
t.Run("own", func(t *testing.T) {
|
||||
usr := &user.User{
|
||||
ID: 6,
|
||||
@ -176,10 +167,10 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
project := Project{
|
||||
ID: 6,
|
||||
Title: "Test6",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 7, // from 6
|
||||
ID: 6,
|
||||
Title: "Test6",
|
||||
Description: "Lorem Ipsum",
|
||||
ParentProjectID: 7, // from 6
|
||||
}
|
||||
can, err := project.CanUpdate(s, usr)
|
||||
assert.NoError(t, err)
|
||||
@ -189,41 +180,26 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "projects", map[string]interface{}{
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
"namespace_id": project.NamespaceID,
|
||||
"id": project.ID,
|
||||
"title": project.Title,
|
||||
"description": project.Description,
|
||||
"parent_project_id": project.ParentProjectID,
|
||||
}, false)
|
||||
})
|
||||
// FIXME: The check for whether the namespace is archived is missing in namespace.CanWrite
|
||||
// t.Run("archived own", func(t *testing.T) {
|
||||
// db.LoadAndAssertFixtures(t)
|
||||
// s := db.NewSession()
|
||||
// project := Project{
|
||||
// ID: 1,
|
||||
// Title: "Test1",
|
||||
// Description: "Lorem Ipsum",
|
||||
// NamespaceID: 16, // from 1
|
||||
// }
|
||||
// can, err := project.CanUpdate(s, usr)
|
||||
// assert.NoError(t, err)
|
||||
// assert.False(t, can) // namespace is archived and thus not writeable
|
||||
// _ = s.Close()
|
||||
// })
|
||||
t.Run("others", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
project := Project{
|
||||
ID: 1,
|
||||
Title: "Test1",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: 2, // from 1
|
||||
ID: 1,
|
||||
Title: "Test1",
|
||||
Description: "Lorem Ipsum",
|
||||
ParentProjectID: 2, // from 1
|
||||
}
|
||||
can, _ := project.CanUpdate(s, usr)
|
||||
assert.False(t, can) // namespace is not writeable by us
|
||||
assert.False(t, can) // project is not writeable by us
|
||||
_ = s.Close()
|
||||
})
|
||||
t.Run("pseudo namespace", func(t *testing.T) {
|
||||
t.Run("pseudo project", func(t *testing.T) {
|
||||
usr := &user.User{
|
||||
ID: 6,
|
||||
Username: "user6",
|
||||
@ -233,14 +209,14 @@ func TestProject_CreateOrUpdate(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
project := Project{
|
||||
ID: 6,
|
||||
Title: "Test6",
|
||||
Description: "Lorem Ipsum",
|
||||
NamespaceID: -1,
|
||||
ID: 6,
|
||||
Title: "Test6",
|
||||
Description: "Lorem Ipsum",
|
||||
ParentProjectID: -1,
|
||||
}
|
||||
err := project.Update(s, usr)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrProjectCannotBelongToAPseudoNamespace(err))
|
||||
assert.True(t, IsErrProjectCannotBelongToAPseudoParentProject(err))
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -321,15 +297,18 @@ func TestProject_DeleteBackgroundFileIfExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProject_ReadAll(t *testing.T) {
|
||||
t.Run("all in namespace", func(t *testing.T) {
|
||||
t.Run("all", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
// Get all projects for our namespace
|
||||
projects, err := GetProjectsByNamespaceID(s, 1, &user.User{})
|
||||
projects := []*Project{}
|
||||
_, _, err := getAllProjectsForUser(s, 1, nil, &projectOptions{}, &projects, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(projects), 2)
|
||||
assert.Equal(t, 10, len(projects))
|
||||
_ = s.Close()
|
||||
})
|
||||
t.Run("only child projects for one project", func(t *testing.T) {
|
||||
// TODO
|
||||
})
|
||||
t.Run("all projects for user", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
@ -340,10 +319,10 @@ func TestProject_ReadAll(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, reflect.TypeOf(projects3).Kind(), reflect.Slice)
|
||||
ls := projects3.([]*Project)
|
||||
assert.Equal(t, 16, len(ls))
|
||||
assert.Equal(t, 10, len(ls))
|
||||
assert.Equal(t, int64(3), ls[0].ID) // Project 3 has a position of 1 and should be sorted first
|
||||
assert.Equal(t, int64(1), ls[1].ID)
|
||||
assert.Equal(t, int64(4), ls[2].ID)
|
||||
assert.Equal(t, int64(6), ls[2].ID)
|
||||
_ = s.Close()
|
||||
})
|
||||
t.Run("projects for nonexistant user", func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user