fix(tests): make the tests compile again

This commit is contained in:
kolaente 2022-12-29 22:24:14 +01:00
parent 3c3bf638d6
commit 1defe1a860
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
28 changed files with 170 additions and 814 deletions

View File

@ -1,90 +0,0 @@
- id: 1
title: testnamespace
description: Lorem Ipsum
owner_id: 1
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 2
title: testnamespace2
description: Lorem Ipsum
owner_id: 2
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 3
title: testnamespace3
description: Lorem Ipsum
owner_id: 3
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 6
title: testnamespace6
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 7
title: testnamespace7
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 8
title: testnamespace8
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 9
title: testnamespace9
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 10
title: testnamespace10
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 11
title: testnamespace11
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 12
title: testnamespace12
description: Lorem Ipsum
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 13
title: testnamespace13
description: Lorem Ipsum
owner_id: 7
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 14
title: testnamespace14
description: Lorem Ipsum
owner_id: 7
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 15
title: testnamespace15
description: Lorem Ipsum
owner_id: 13
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 16
title: Archived testnamespace16
owner_id: 1
is_archived: 1
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 17
title: testnamespace17
description: Lorem Ipsum
owner_id: 12
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12

View File

@ -4,7 +4,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test1 identifier: test1
owner_id: 1 owner_id: 1
namespace_id: 1
position: 3 position: 3
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -14,7 +13,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test2 identifier: test2
owner_id: 3 owner_id: 3
namespace_id: 1
position: 2 position: 2
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -24,7 +22,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test3 identifier: test3
owner_id: 3 owner_id: 3
namespace_id: 2
position: 1 position: 1
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -34,7 +31,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test4 identifier: test4
owner_id: 3 owner_id: 3
namespace_id: 3
position: 4 position: 4
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -44,7 +40,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test5 identifier: test5
owner_id: 5 owner_id: 5
namespace_id: 5
position: 5 position: 5
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -54,7 +49,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test6 identifier: test6
owner_id: 6 owner_id: 6
namespace_id: 6
position: 6 position: 6
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -64,7 +58,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test7 identifier: test7
owner_id: 6 owner_id: 6
namespace_id: 6
position: 7 position: 7
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -74,7 +67,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test8 identifier: test8
owner_id: 6 owner_id: 6
namespace_id: 6
position: 8 position: 8
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -84,7 +76,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test9 identifier: test9
owner_id: 6 owner_id: 6
namespace_id: 6
position: 9 position: 9
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -94,7 +85,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test10 identifier: test10
owner_id: 6 owner_id: 6
namespace_id: 6
position: 10 position: 10
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -104,7 +94,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test11 identifier: test11
owner_id: 6 owner_id: 6
namespace_id: 6
position: 11 position: 11
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -114,7 +103,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test12 identifier: test12
owner_id: 6 owner_id: 6
namespace_id: 7
position: 12 position: 12
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -124,7 +112,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test13 identifier: test13
owner_id: 6 owner_id: 6
namespace_id: 8
position: 13 position: 13
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -134,7 +121,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test14 identifier: test14
owner_id: 6 owner_id: 6
namespace_id: 9
position: 14 position: 14
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -144,7 +130,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test15 identifier: test15
owner_id: 6 owner_id: 6
namespace_id: 10
position: 15 position: 15
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -154,7 +139,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test16 identifier: test16
owner_id: 6 owner_id: 6
namespace_id: 11
position: 16 position: 16
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -164,7 +148,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test17 identifier: test17
owner_id: 6 owner_id: 6
namespace_id: 12
position: 17 position: 17
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -176,7 +159,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test18 identifier: test18
owner_id: 7 owner_id: 7
namespace_id: 13
position: 18 position: 18
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -186,7 +168,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test19 identifier: test19
owner_id: 7 owner_id: 7
namespace_id: 14
position: 19 position: 19
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -197,17 +178,15 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test20 identifier: test20
owner_id: 13 owner_id: 13
namespace_id: 15
position: 20 position: 20
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
- -
id: 21 id: 21
title: Test21 archived through namespace title: Test21 archived through parent list
description: Lorem Ipsum description: Lorem Ipsum
identifier: test21 identifier: test21
owner_id: 1 owner_id: 1
namespace_id: 16
position: 21 position: 21
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -217,7 +196,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test22 identifier: test22
owner_id: 1 owner_id: 1
namespace_id: 1
is_archived: 1 is_archived: 1
position: 22 position: 22
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
@ -228,7 +206,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test23 identifier: test23
owner_id: 12 owner_id: 12
namespace_id: 17
position: 23 position: 23
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12
@ -238,7 +215,6 @@
description: Lorem Ipsum description: Lorem Ipsum
identifier: test6 identifier: test6
owner_id: 6 owner_id: 6
namespace_id: 6
position: 7 position: 7
updated: 2018-12-02 15:13:12 updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12 created: 2018-12-01 15:13:12

View File

@ -3,24 +3,14 @@
entity_id: 2 entity_id: 2
user_id: 1 user_id: 1
created: 2021-02-01 15:13:12 created: 2021-02-01 15:13:12
- id: 2
entity_type: 1 # Namespace
entity_id: 6
user_id: 6
created: 2021-02-01 15:13:12
- id: 3 - id: 3
entity_type: 2 # project entity_type: 2 # project
entity_id: 12 # belongs to namespace 7 entity_id: 12 # belongs to parent project 7 TODO
user_id: 6 user_id: 6
created: 2021-02-01 15:13:12 created: 2021-02-01 15:13:12
- id: 4 - id: 4
entity_type: 3 # Task entity_type: 3 # Task
entity_id: 22 # belongs to project 13 which belongs to namespace 8 entity_id: 22 # belongs to project 13 which belongs to namespace 8 TODO
user_id: 6
created: 2021-02-01 15:13:12
- id: 5
entity_type: 1 # Namespace
entity_id: 8
user_id: 6 user_id: 6
created: 2021-02-01 15:13:12 created: 2021-02-01 15:13:12
- id: 6 - id: 6

View File

@ -1,52 +0,0 @@
- id: 1
team_id: 1
namespace_id: 3
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 2
team_id: 2
namespace_id: 3
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 3
team_id: 5
namespace_id: 7
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 4
team_id: 6
namespace_id: 8
right: 1
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 5
team_id: 7
namespace_id: 9
right: 2
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 6
team_id: 11
namespace_id: 14
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 7
team_id: 12
namespace_id: 14
right: 1
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 8
team_id: 13
namespace_id: 14
right: 2
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12

View File

@ -11,15 +11,6 @@
- id: 4 - id: 4
name: testteam4_admin_on_project8 name: testteam4_admin_on_project8
created_by_id: 1 created_by_id: 1
- id: 5
name: testteam2_read_only_on_namespace7
created_by_id: 1
- id: 6
name: testteam3_write_on_namespace8
created_by_id: 1
- id: 7
name: testteam4_admin_on_namespace9
created_by_id: 1
- id: 8 - id: 8
name: testteam8 name: testteam8
created_by_id: 7 created_by_id: 7

View File

@ -1,52 +0,0 @@
- id: 1
user_id: 1
namespace_id: 3
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 2
user_id: 2
namespace_id: 3
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 3
user_id: 1
namespace_id: 10
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 4
user_id: 1
namespace_id: 11
right: 1
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 5
user_id: 1
namespace_id: 12
right: 2
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 6
user_id: 11
namespace_id: 14
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 7
user_id: 12
namespace_id: 14
right: 1
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 8
user_id: 13
namespace_id: 14
right: 2
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12

View File

@ -158,20 +158,20 @@ func TestArchived(t *testing.T) {
t.Run("not editable", func(t *testing.T) { t.Run("not editable", func(t *testing.T) {
_, err := testProjectHandler.testUpdateWithUser(nil, map[string]string{"project": "21"}, `{"title":"TestIpsum","is_archived":true}`) _, err := testProjectHandler.testUpdateWithUser(nil, map[string]string{"project": "21"}, `{"title":"TestIpsum","is_archived":true}`)
assert.Error(t, err) assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNamespaceIsArchived) assertHandlerErrorCode(t, err, models.ErrCodeProjectIsArchived)
}) })
t.Run("no new tasks", func(t *testing.T) { t.Run("no new tasks", func(t *testing.T) {
_, err := testTaskHandler.testCreateWithUser(nil, map[string]string{"project": "21"}, `{"title":"Lorem"}`) _, err := testTaskHandler.testCreateWithUser(nil, map[string]string{"project": "21"}, `{"title":"Lorem"}`)
assert.Error(t, err) assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNamespaceIsArchived) assertHandlerErrorCode(t, err, models.ErrCodeProjectIsArchived)
}) })
t.Run("not unarchivable", func(t *testing.T) { t.Run("not unarchivable", func(t *testing.T) {
_, err := testProjectHandler.testUpdateWithUser(nil, map[string]string{"project": "21"}, `{"title":"LoremIpsum","is_archived":false}`) _, err := testProjectHandler.testUpdateWithUser(nil, map[string]string{"project": "21"}, `{"title":"LoremIpsum","is_archived":false}`)
assert.Error(t, err) assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNamespaceIsArchived) assertHandlerErrorCode(t, err, models.ErrCodeProjectIsArchived)
}) })
taskTests("35", models.ErrCodeNamespaceIsArchived, t) taskTests("35", models.ErrCodeProjectIsArchived, t)
}) })
// The project itself is archived // The project itself is archived
t.Run("archived individually", func(t *testing.T) { t.Run("archived individually", func(t *testing.T) {
@ -186,7 +186,7 @@ func TestArchived(t *testing.T) {
assertHandlerErrorCode(t, err, models.ErrCodeProjectIsArchived) assertHandlerErrorCode(t, err, models.ErrCodeProjectIsArchived)
}) })
t.Run("unarchivable", func(t *testing.T) { t.Run("unarchivable", func(t *testing.T) {
rec, err := testProjectHandler.testUpdateWithUser(nil, map[string]string{"project": "22"}, `{"title":"LoremIpsum","is_archived":false,"namespace_id":1}`) rec, err := testProjectHandler.testUpdateWithUser(nil, map[string]string{"project": "22"}, `{"title":"LoremIpsum","is_archived":false}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"is_archived":false`) assert.Contains(t, rec.Body.String(), `"is_archived":false`)
}) })

View File

@ -273,7 +273,7 @@ func TestLinkSharing(t *testing.T) {
}) })
}) })
// Creating a project should always be forbidden, since users need access to a namespace to create a project // Creating a project should always be forbidden
t.Run("Create", func(t *testing.T) { t.Run("Create", func(t *testing.T) {
t.Run("Nonexisting", func(t *testing.T) { t.Run("Nonexisting", func(t *testing.T) {
_, err := testHandlerProjectReadOnly.testCreateWithLinkShare(nil, map[string]string{"namespace": "999999"}, `{"title":"Lorem"}`) _, err := testHandlerProjectReadOnly.testCreateWithLinkShare(nil, map[string]string{"namespace": "999999"}, `{"title":"Lorem"}`)
@ -806,284 +806,4 @@ func TestLinkSharing(t *testing.T) {
}) })
}) })
}) })
t.Run("Namespace", func(t *testing.T) {
testHandlerNamespaceReadOnly := webHandlerTest{
linkShare: linkshareRead,
strFunc: func() handler.CObject {
return &models.Namespace{}
},
t: t,
}
testHandlerNamespaceWrite := webHandlerTest{
linkShare: linkShareWrite,
strFunc: func() handler.CObject {
return &models.Namespace{}
},
t: t,
}
testHandlerNamespaceAdmin := webHandlerTest{
linkShare: linkShareAdmin,
strFunc: func() handler.CObject {
return &models.Namespace{}
},
t: t,
}
t.Run("ReadAll", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceReadOnly.testReadAllWithLinkShare(nil, map[string]string{"namespace": "1"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrorCodeGenericForbidden)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceWrite.testReadAllWithLinkShare(nil, map[string]string{"namespace": "2"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrorCodeGenericForbidden)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceAdmin.testReadAllWithLinkShare(nil, map[string]string{"namespace": "3"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrorCodeGenericForbidden)
})
})
t.Run("Create", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceReadOnly.testCreateWithLinkShare(nil, nil, `{"title":"LoremIpsum"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceWrite.testCreateWithLinkShare(nil, nil, `{"title":"LoremIpsum"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceAdmin.testCreateWithLinkShare(nil, nil, `{"title":"LoremIpsum"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Update", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceReadOnly.testUpdateWithLinkShare(nil, map[string]string{"namespace": "1"}, `{"title":"LoremIpsum"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceWrite.testUpdateWithLinkShare(nil, map[string]string{"namespace": "2"}, `{"title":"LoremIpsum"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceAdmin.testUpdateWithLinkShare(nil, map[string]string{"namespace": "3"}, `{"title":"LoremIpsum"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Delete", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceReadOnly.testDeleteWithLinkShare(nil, map[string]string{"namespace": "1"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceWrite.testDeleteWithLinkShare(nil, map[string]string{"namespace": "2"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceAdmin.testDeleteWithLinkShare(nil, map[string]string{"namespace": "3"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Right Management", func(t *testing.T) {
t.Run("Users", func(t *testing.T) {
testHandlerNamespaceUserReadOnly := webHandlerTest{
linkShare: linkshareRead,
strFunc: func() handler.CObject {
return &models.NamespaceUser{}
},
t: t,
}
testHandlerNamespaceUserWrite := webHandlerTest{
linkShare: linkShareWrite,
strFunc: func() handler.CObject {
return &models.NamespaceUser{}
},
t: t,
}
testHandlerNamespaceUserAdmin := webHandlerTest{
linkShare: linkShareAdmin,
strFunc: func() handler.CObject {
return &models.NamespaceUser{}
},
t: t,
}
t.Run("ReadAll", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceUserReadOnly.testReadAllWithLinkShare(nil, map[string]string{"namespace": "1"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNeedToHaveNamespaceReadAccess)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceUserWrite.testReadAllWithLinkShare(nil, map[string]string{"namespace": "2"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNeedToHaveNamespaceReadAccess)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceUserAdmin.testReadAllWithLinkShare(nil, map[string]string{"namespace": "3"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNeedToHaveNamespaceReadAccess)
})
})
t.Run("Create", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceUserReadOnly.testCreateWithLinkShare(nil, nil, `{"user_id":"user1"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceUserWrite.testCreateWithLinkShare(nil, nil, `{"user_id":"user1"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceUserAdmin.testCreateWithLinkShare(nil, nil, `{"user_id":"user1"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Update", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceUserReadOnly.testUpdateWithLinkShare(nil, map[string]string{"namespace": "1"}, `{"user_id":"user1"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceUserWrite.testUpdateWithLinkShare(nil, map[string]string{"namespace": "2"}, `{"user_id":"user1"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceUserAdmin.testUpdateWithLinkShare(nil, map[string]string{"namespace": "3"}, `{"user_id":"user1"}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Delete", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceUserReadOnly.testDeleteWithLinkShare(nil, map[string]string{"namespace": "1"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceUserWrite.testDeleteWithLinkShare(nil, map[string]string{"namespace": "2"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceUserAdmin.testDeleteWithLinkShare(nil, map[string]string{"namespace": "3"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
})
t.Run("Teams", func(t *testing.T) {
testHandlerNamespaceTeamReadOnly := webHandlerTest{
linkShare: linkshareRead,
strFunc: func() handler.CObject {
return &models.TeamNamespace{}
},
t: t,
}
testHandlerNamespaceTeamWrite := webHandlerTest{
linkShare: linkShareWrite,
strFunc: func() handler.CObject {
return &models.TeamNamespace{}
},
t: t,
}
testHandlerNamespaceTeamAdmin := webHandlerTest{
linkShare: linkShareAdmin,
strFunc: func() handler.CObject {
return &models.TeamNamespace{}
},
t: t,
}
t.Run("ReadAll", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceTeamReadOnly.testReadAllWithLinkShare(nil, map[string]string{"namespace": "1"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNeedToHaveNamespaceReadAccess)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceTeamWrite.testReadAllWithLinkShare(nil, map[string]string{"namespace": "2"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNeedToHaveNamespaceReadAccess)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceTeamAdmin.testReadAllWithLinkShare(nil, map[string]string{"namespace": "3"})
assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNeedToHaveNamespaceReadAccess)
})
})
t.Run("Create", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceTeamReadOnly.testCreateWithLinkShare(nil, map[string]string{"namespace": "1"}, `{"team_id":1}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceTeamWrite.testCreateWithLinkShare(nil, map[string]string{"namespace": "2"}, `{"team_id":1}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceTeamAdmin.testCreateWithLinkShare(nil, map[string]string{"namespace": "3"}, `{"team_id":1}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Update", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceTeamReadOnly.testUpdateWithLinkShare(nil, map[string]string{"namespace": "1"}, `{"team_id":1}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceTeamWrite.testUpdateWithLinkShare(nil, map[string]string{"namespace": "2"}, `{"team_id":1}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceTeamAdmin.testUpdateWithLinkShare(nil, map[string]string{"namespace": "3"}, `{"team_id":1}`)
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
t.Run("Delete", func(t *testing.T) {
t.Run("Shared readonly", func(t *testing.T) {
_, err := testHandlerNamespaceTeamReadOnly.testDeleteWithLinkShare(nil, map[string]string{"namespace": "1"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared write", func(t *testing.T) {
_, err := testHandlerNamespaceTeamWrite.testDeleteWithLinkShare(nil, map[string]string{"namespace": "2"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
t.Run("Shared admin", func(t *testing.T) {
_, err := testHandlerNamespaceTeamAdmin.testDeleteWithLinkShare(nil, map[string]string{"namespace": "3"})
assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
})
})
})
})
})
} }

View File

@ -41,9 +41,9 @@ func TestProject(t *testing.T) {
assert.Contains(t, rec.Body.String(), `Test1`) assert.Contains(t, rec.Body.String(), `Test1`)
assert.NotContains(t, rec.Body.String(), `Test2"`) assert.NotContains(t, rec.Body.String(), `Test2"`)
assert.Contains(t, rec.Body.String(), `Test3`) // Shared directly via users_project assert.Contains(t, rec.Body.String(), `Test3`) // Shared directly via users_project
assert.Contains(t, rec.Body.String(), `Test4`) // Shared via namespace assert.Contains(t, rec.Body.String(), `Test4`) // Shared via parent project
assert.NotContains(t, rec.Body.String(), `Test5`) assert.NotContains(t, rec.Body.String(), `Test5`)
assert.NotContains(t, rec.Body.String(), `Test21`) // Archived through namespace assert.NotContains(t, rec.Body.String(), `Test21`) // Archived through parent project
assert.NotContains(t, rec.Body.String(), `Test22`) // Archived directly assert.NotContains(t, rec.Body.String(), `Test22`) // Archived directly
}) })
t.Run("Search", func(t *testing.T) { t.Run("Search", func(t *testing.T) {
@ -61,9 +61,9 @@ func TestProject(t *testing.T) {
assert.Contains(t, rec.Body.String(), `Test1`) assert.Contains(t, rec.Body.String(), `Test1`)
assert.NotContains(t, rec.Body.String(), `Test2"`) assert.NotContains(t, rec.Body.String(), `Test2"`)
assert.Contains(t, rec.Body.String(), `Test3`) // Shared directly via users_project assert.Contains(t, rec.Body.String(), `Test3`) // Shared directly via users_project
assert.Contains(t, rec.Body.String(), `Test4`) // Shared via namespace assert.Contains(t, rec.Body.String(), `Test4`) // Shared via project
assert.NotContains(t, rec.Body.String(), `Test5`) assert.NotContains(t, rec.Body.String(), `Test5`)
assert.Contains(t, rec.Body.String(), `Test21`) // Archived through namespace assert.Contains(t, rec.Body.String(), `Test21`) // Archived through project
assert.Contains(t, rec.Body.String(), `Test22`) // Archived directly assert.Contains(t, rec.Body.String(), `Test22`) // Archived directly
}) })
}) })
@ -171,7 +171,7 @@ func TestProject(t *testing.T) {
t.Run("Update", func(t *testing.T) { t.Run("Update", func(t *testing.T) {
t.Run("Normal", func(t *testing.T) { t.Run("Normal", func(t *testing.T) {
// Check the project was loaded successfully afterwards, see testReadOneWithUser // Check the project was loaded successfully afterwards, see testReadOneWithUser
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "1"}, `{"title":"TestLoremIpsum","namespace_id":1}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "1"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
// The description should not be updated but returned correctly // The description should not be updated but returned correctly
@ -183,7 +183,7 @@ func TestProject(t *testing.T) {
assertHandlerErrorCode(t, err, models.ErrCodeProjectDoesNotExist) assertHandlerErrorCode(t, err, models.ErrCodeProjectDoesNotExist)
}) })
t.Run("Normal with updating the description", func(t *testing.T) { t.Run("Normal with updating the description", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "1"}, `{"title":"TestLoremIpsum","description":"Lorem Ipsum dolor sit amet","namespace_id":1}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "1"}, `{"title":"TestLoremIpsum","description":"Lorem Ipsum dolor sit amet"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
assert.Contains(t, rec.Body.String(), `"description":"Lorem Ipsum dolor sit amet`) assert.Contains(t, rec.Body.String(), `"description":"Lorem Ipsum dolor sit amet`)
@ -211,12 +211,12 @@ func TestProject(t *testing.T) {
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via Team write", func(t *testing.T) { t.Run("Shared Via Team write", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "7"}, `{"title":"TestLoremIpsum","namespace_id":6}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "7"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
t.Run("Shared Via Team admin", func(t *testing.T) { t.Run("Shared Via Team admin", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "8"}, `{"title":"TestLoremIpsum","namespace_id":6}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "8"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
@ -227,12 +227,12 @@ func TestProject(t *testing.T) {
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via User write", func(t *testing.T) { t.Run("Shared Via User write", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "10"}, `{"title":"TestLoremIpsum","namespace_id":6}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "10"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
t.Run("Shared Via User admin", func(t *testing.T) { t.Run("Shared Via User admin", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "11"}, `{"title":"TestLoremIpsum","namespace_id":6}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "11"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
@ -243,12 +243,12 @@ func TestProject(t *testing.T) {
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { t.Run("Shared Via NamespaceTeam write", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "13"}, `{"title":"TestLoremIpsum","namespace_id":8}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "13"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "14"}, `{"title":"TestLoremIpsum","namespace_id":9}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "14"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
@ -259,12 +259,12 @@ func TestProject(t *testing.T) {
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via NamespaceUser write", func(t *testing.T) { t.Run("Shared Via NamespaceUser write", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "16"}, `{"title":"TestLoremIpsum","namespace_id":11}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "16"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
t.Run("Shared Via NamespaceUser admin", func(t *testing.T) { t.Run("Shared Via NamespaceUser admin", func(t *testing.T) {
rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "17"}, `{"title":"TestLoremIpsum","namespace_id":12}`) rec, err := testHandler.testUpdateWithUser(nil, map[string]string{"project": "17"}, `{"title":"TestLoremIpsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`) assert.Contains(t, rec.Body.String(), `"title":"TestLoremIpsum"`)
}) })
@ -356,7 +356,7 @@ func TestProject(t *testing.T) {
t.Run("Create", func(t *testing.T) { t.Run("Create", func(t *testing.T) {
t.Run("Normal", func(t *testing.T) { t.Run("Normal", func(t *testing.T) {
// Check the project was loaded successfully after update, see testReadOneWithUser // Check the project was loaded successfully after update, see testReadOneWithUser
rec, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "1"}, `{"title":"Lorem"}`) rec, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"Lorem"`) assert.Contains(t, rec.Body.String(), `"title":"Lorem"`)
assert.Contains(t, rec.Body.String(), `"description":""`) assert.Contains(t, rec.Body.String(), `"description":""`)
@ -364,44 +364,42 @@ func TestProject(t *testing.T) {
assert.NotContains(t, rec.Body.String(), `"tasks":`) assert.NotContains(t, rec.Body.String(), `"tasks":`)
}) })
t.Run("Normal with description", func(t *testing.T) { t.Run("Normal with description", func(t *testing.T) {
rec, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "1"}, `{"title":"Lorem","description":"Lorem Ipsum"}`) rec, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem","description":"Lorem Ipsum"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"Lorem"`) assert.Contains(t, rec.Body.String(), `"title":"Lorem"`)
assert.Contains(t, rec.Body.String(), `"description":"Lorem Ipsum"`) assert.Contains(t, rec.Body.String(), `"description":"Lorem Ipsum"`)
assert.Contains(t, rec.Body.String(), `"owner":{"id":1`) assert.Contains(t, rec.Body.String(), `"owner":{"id":1`)
assert.NotContains(t, rec.Body.String(), `"tasks":`) assert.NotContains(t, rec.Body.String(), `"tasks":`)
}) })
t.Run("Nonexisting Namespace", func(t *testing.T) { t.Run("Nonexisting parent project", func(t *testing.T) {
_, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "999999"}, `{"title":"Lorem"}`) _, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem","parent_project_id":99999}`)
assert.Error(t, err) assert.Error(t, err)
assertHandlerErrorCode(t, err, models.ErrCodeNamespaceDoesNotExist) assertHandlerErrorCode(t, err, models.ErrCodeProjectDoesNotExist)
}) })
t.Run("Empty title", func(t *testing.T) { t.Run("Empty title", func(t *testing.T) {
_, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "1"}, `{"title":""}`) _, err := testHandler.testCreateWithUser(nil, nil, `{"title":""}`)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message.(models.ValidationHTTPError).InvalidFields, "title: non zero value required") assert.Contains(t, err.(*echo.HTTPError).Message.(models.ValidationHTTPError).InvalidFields, "title: non zero value required")
}) })
t.Run("Title too long", func(t *testing.T) { t.Run("Title too long", func(t *testing.T) {
_, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "1"}, `{"title":"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea taki"}`) _, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea taki"}`)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message.(models.ValidationHTTPError).InvalidFields[0], "does not validate as runelength(1|250)") assert.Contains(t, err.(*echo.HTTPError).Message.(models.ValidationHTTPError).InvalidFields[0], "does not validate as runelength(1|250)")
}) })
t.Run("Rights check", func(t *testing.T) { t.Run("Rights check", func(t *testing.T) {
t.Run("Forbidden", func(t *testing.T) { t.Run("Forbidden", func(t *testing.T) {
// Owned by user13 // Owned by user13
_, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "15"}, `{"title":"Lorem"}`) _, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) { t.Run("Shared Via NamespaceTeam readonly", func(t *testing.T) {
_, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "7"}, `{"title":"Lorem"}`) _, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via NamespaceTeam write", func(t *testing.T) { t.Run("Shared Via NamespaceTeam write", func(t *testing.T) {
rec, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "8"}, `{"title":"Lorem"}`) rec, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"Lorem"`) assert.Contains(t, rec.Body.String(), `"title":"Lorem"`)
assert.Contains(t, rec.Body.String(), `"description":""`) assert.Contains(t, rec.Body.String(), `"description":""`)
@ -409,7 +407,7 @@ func TestProject(t *testing.T) {
assert.NotContains(t, rec.Body.String(), `"tasks":`) assert.NotContains(t, rec.Body.String(), `"tasks":`)
}) })
t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) { t.Run("Shared Via NamespaceTeam admin", func(t *testing.T) {
rec, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "9"}, `{"title":"Lorem"}`) rec, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"Lorem"`) assert.Contains(t, rec.Body.String(), `"title":"Lorem"`)
assert.Contains(t, rec.Body.String(), `"description":""`) assert.Contains(t, rec.Body.String(), `"description":""`)
@ -418,12 +416,12 @@ func TestProject(t *testing.T) {
}) })
t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) { t.Run("Shared Via NamespaceUser readonly", func(t *testing.T) {
_, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "10"}, `{"title":"Lorem"}`) _, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`) assert.Contains(t, err.(*echo.HTTPError).Message, `Forbidden`)
}) })
t.Run("Shared Via NamespaceUser write", func(t *testing.T) { t.Run("Shared Via NamespaceUser write", func(t *testing.T) {
rec, err := testHandler.testCreateWithUser(nil, map[string]string{"namespace": "11"}, `{"title":"Lorem"}`) rec, err := testHandler.testCreateWithUser(nil, nil, `{"title":"Lorem"}`)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, rec.Body.String(), `"title":"Lorem"`) assert.Contains(t, rec.Body.String(), `"title":"Lorem"`)
assert.Contains(t, rec.Body.String(), `"description":""`) assert.Contains(t, rec.Body.String(), `"description":""`)

View File

@ -143,7 +143,7 @@ func TestLabelTask_ReadAll(t *testing.T) {
return return
} }
if (err != nil) && tt.wantErr && !tt.errType(err) { if (err != nil) && tt.wantErr && !tt.errType(err) {
t.Errorf("LabelTask.ReadAll() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) t.Errorf("LabelTask.ReadAll() Wrong error type! Error = %v, want = %v, got = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name(), err)
} }
if diff, equal := messagediff.PrettyDiff(gotLabels, tt.wantLabels); !equal { if diff, equal := messagediff.PrettyDiff(gotLabels, tt.wantLabels); !equal {
t.Errorf("LabelTask.ReadAll() = %v, want %v, diff: %v", l, tt.wantLabels, diff) t.Errorf("LabelTask.ReadAll() = %v, want %v, diff: %v", l, tt.wantLabels, diff)

View File

@ -39,30 +39,29 @@ func TestProject_CreateOrUpdate(t *testing.T) {
project := Project{ project := Project{
Title: "test", Title: "test",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 1,
} }
err := project.Create(s, usr) err := project.Create(s, usr)
assert.NoError(t, err) assert.NoError(t, err)
err = s.Commit() err = s.Commit()
assert.NoError(t, err) assert.NoError(t, err)
db.AssertExists(t, "projects", map[string]interface{}{ db.AssertExists(t, "projects", map[string]interface{}{
"id": project.ID, "id": project.ID,
"title": project.Title, "title": project.Title,
"description": project.Description, "description": project.Description,
"namespace_id": project.NamespaceID, "parent_project_id": 0,
}, false) }, false)
}) })
t.Run("nonexistant namespace", func(t *testing.T) { t.Run("nonexistant parent project", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
project := Project{ project := Project{
Title: "test", Title: "test",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 999999, ParentProjectID: 999999,
} }
err := project.Create(s, usr) err := project.Create(s, usr)
assert.Error(t, err) assert.Error(t, err)
assert.True(t, IsErrNamespaceDoesNotExist(err)) assert.True(t, IsErrProjectDoesNotExist(err))
_ = s.Close() _ = s.Close()
}) })
t.Run("nonexistant owner", func(t *testing.T) { t.Run("nonexistant owner", func(t *testing.T) {
@ -72,7 +71,6 @@ func TestProject_CreateOrUpdate(t *testing.T) {
project := Project{ project := Project{
Title: "test", Title: "test",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 1,
} }
err := project.Create(s, usr) err := project.Create(s, usr)
assert.Error(t, err) assert.Error(t, err)
@ -86,7 +84,6 @@ func TestProject_CreateOrUpdate(t *testing.T) {
Title: "test", Title: "test",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
Identifier: "test1", Identifier: "test1",
NamespaceID: 1,
} }
err := project.Create(s, usr) err := project.Create(s, usr)
assert.Error(t, err) assert.Error(t, err)
@ -99,17 +96,15 @@ func TestProject_CreateOrUpdate(t *testing.T) {
project := Project{ project := Project{
Title: "приффки фсем", Title: "приффки фсем",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 1,
} }
err := project.Create(s, usr) err := project.Create(s, usr)
assert.NoError(t, err) assert.NoError(t, err)
err = s.Commit() err = s.Commit()
assert.NoError(t, err) assert.NoError(t, err)
db.AssertExists(t, "projects", map[string]interface{}{ db.AssertExists(t, "projects", map[string]interface{}{
"id": project.ID, "id": project.ID,
"title": project.Title, "title": project.Title,
"description": project.Description, "description": project.Description,
"namespace_id": project.NamespaceID,
}, false) }, false)
}) })
}) })
@ -122,7 +117,6 @@ func TestProject_CreateOrUpdate(t *testing.T) {
ID: 1, ID: 1,
Title: "test", Title: "test",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 1,
} }
project.Description = "Lorem Ipsum dolor sit amet." project.Description = "Lorem Ipsum dolor sit amet."
err := project.Update(s, usr) err := project.Update(s, usr)
@ -130,19 +124,17 @@ func TestProject_CreateOrUpdate(t *testing.T) {
err = s.Commit() err = s.Commit()
assert.NoError(t, err) assert.NoError(t, err)
db.AssertExists(t, "projects", map[string]interface{}{ db.AssertExists(t, "projects", map[string]interface{}{
"id": project.ID, "id": project.ID,
"title": project.Title, "title": project.Title,
"description": project.Description, "description": project.Description,
"namespace_id": project.NamespaceID,
}, false) }, false)
}) })
t.Run("nonexistant", func(t *testing.T) { t.Run("nonexistant", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
project := Project{ project := Project{
ID: 99999999, ID: 99999999,
Title: "test", Title: "test",
NamespaceID: 1,
} }
err := project.Update(s, usr) err := project.Update(s, usr)
assert.Error(t, err) assert.Error(t, err)
@ -157,14 +149,13 @@ func TestProject_CreateOrUpdate(t *testing.T) {
Title: "test", Title: "test",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
Identifier: "test1", Identifier: "test1",
NamespaceID: 1,
} }
err := project.Create(s, usr) err := project.Create(s, usr)
assert.Error(t, err) assert.Error(t, err)
assert.True(t, IsErrProjectIdentifierIsNotUnique(err)) assert.True(t, IsErrProjectIdentifierIsNotUnique(err))
_ = s.Close() _ = 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) { t.Run("own", func(t *testing.T) {
usr := &user.User{ usr := &user.User{
ID: 6, ID: 6,
@ -175,10 +166,10 @@ func TestProject_CreateOrUpdate(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
project := Project{ project := Project{
ID: 6, ID: 6,
Title: "Test6", Title: "Test6",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 7, // from 6 ParentProjectID: 7, // from 6
} }
can, err := project.CanUpdate(s, usr) can, err := project.CanUpdate(s, usr)
assert.NoError(t, err) assert.NoError(t, err)
@ -188,41 +179,26 @@ func TestProject_CreateOrUpdate(t *testing.T) {
err = s.Commit() err = s.Commit()
assert.NoError(t, err) assert.NoError(t, err)
db.AssertExists(t, "projects", map[string]interface{}{ db.AssertExists(t, "projects", map[string]interface{}{
"id": project.ID, "id": project.ID,
"title": project.Title, "title": project.Title,
"description": project.Description, "description": project.Description,
"namespace_id": project.NamespaceID, "parent_project_id": project.ParentProjectID,
}, false) }, 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) { t.Run("others", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
project := Project{ project := Project{
ID: 1, ID: 1,
Title: "Test1", Title: "Test1",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: 2, // from 1 ParentProjectID: 2, // from 1
} }
can, _ := project.CanUpdate(s, usr) 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() _ = s.Close()
}) })
t.Run("pseudo namespace", func(t *testing.T) { t.Run("pseudo project", func(t *testing.T) {
usr := &user.User{ usr := &user.User{
ID: 6, ID: 6,
Username: "user6", Username: "user6",
@ -232,14 +208,14 @@ func TestProject_CreateOrUpdate(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
project := Project{ project := Project{
ID: 6, ID: 6,
Title: "Test6", Title: "Test6",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
NamespaceID: -1, ParentProjectID: -1,
} }
err := project.Update(s, usr) err := project.Update(s, usr)
assert.Error(t, err) assert.Error(t, err)
assert.True(t, IsErrProjectCannotBelongToAPseudoNamespace(err)) assert.True(t, IsErrProjectCannotBelongToAPseudoParentProject(err))
}) })
}) })
}) })
@ -261,15 +237,18 @@ func TestProject_Delete(t *testing.T) {
} }
func TestProject_ReadAll(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) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
// Get all projects for our namespace projects := []*Project{}
projects, err := GetProjectsByNamespaceID(s, 1, &user.User{}) _, _, err := getAllProjectsForUser(s, 1, nil, &projectOptions{}, &projects, 0)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, len(projects), 2) assert.Equal(t, 10, len(projects))
_ = s.Close() _ = 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) { t.Run("all projects for user", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
@ -280,10 +259,10 @@ func TestProject_ReadAll(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, reflect.TypeOf(projects3).Kind(), reflect.Slice) assert.Equal(t, reflect.TypeOf(projects3).Kind(), reflect.Slice)
ls := projects3.([]*Project) 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(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(1), ls[1].ID)
assert.Equal(t, int64(4), ls[2].ID) assert.Equal(t, int64(6), ls[2].ID)
_ = s.Close() _ = s.Close()
}) })
t.Run("projects for nonexistant user", func(t *testing.T) { t.Run("projects for nonexistant user", func(t *testing.T) {

View File

@ -37,8 +37,7 @@ func TestProjectDuplicate(t *testing.T) {
} }
l := &ProjectDuplicate{ l := &ProjectDuplicate{
ProjectID: 1, ProjectID: 1,
NamespaceID: 1,
} }
can, err := l.CanCreate(s, u) can, err := l.CanCreate(s, u)
assert.NoError(t, err) assert.NoError(t, err)

View File

@ -216,8 +216,6 @@ func (p *Project) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bool
)) ))
} }
// TODO: parents
type allProjectRights struct { type allProjectRights struct {
UserProject *ProjectUser `xorm:"extends"` UserProject *ProjectUser `xorm:"extends"`
TeamProject *TeamProject `xorm:"extends"` TeamProject *TeamProject `xorm:"extends"`

View File

@ -56,18 +56,6 @@ func TestTeamProject_ReadAll(t *testing.T) {
assert.True(t, IsErrProjectDoesNotExist(err)) assert.True(t, IsErrProjectDoesNotExist(err))
_ = s.Close() _ = s.Close()
}) })
t.Run("namespace owner", func(t *testing.T) {
tl := TeamProject{
TeamID: 1,
ProjectID: 2,
Right: RightAdmin,
}
db.LoadAndAssertFixtures(t)
s := db.NewSession()
_, _, _, err := tl.ReadAll(s, u, "", 1, 50)
assert.NoError(t, err)
_ = s.Close()
})
t.Run("no access", func(t *testing.T) { t.Run("no access", func(t *testing.T) {
tl := TeamProject{ tl := TeamProject{
TeamID: 1, TeamID: 1,

View File

@ -52,14 +52,14 @@ func TestProjectUser_Create(t *testing.T) {
errType func(err error) bool errType func(err error) bool
}{ }{
{ {
name: "ProjectUsers Create normally", name: "ListUsers Create normally",
fields: fields{ fields: fields{
Username: "user1", Username: "user1",
ProjectID: 2, ProjectID: 2,
}, },
}, },
{ {
name: "ProjectUsers Create for duplicate", name: "ListUsers Create for duplicate",
fields: fields{ fields: fields{
Username: "user1", Username: "user1",
ProjectID: 3, ProjectID: 3,
@ -68,7 +68,7 @@ func TestProjectUser_Create(t *testing.T) {
errType: IsErrUserAlreadyHasAccess, errType: IsErrUserAlreadyHasAccess,
}, },
{ {
name: "ProjectUsers Create with invalid right", name: "ListUsers Create with invalid right",
fields: fields{ fields: fields{
Username: "user1", Username: "user1",
ProjectID: 2, ProjectID: 2,
@ -78,7 +78,7 @@ func TestProjectUser_Create(t *testing.T) {
errType: IsErrInvalidRight, errType: IsErrInvalidRight,
}, },
{ {
name: "ProjectUsers Create with inexisting project", name: "ListUsers Create with inexisting project",
fields: fields{ fields: fields{
Username: "user1", Username: "user1",
ProjectID: 2000, ProjectID: 2000,
@ -87,7 +87,7 @@ func TestProjectUser_Create(t *testing.T) {
errType: IsErrProjectDoesNotExist, errType: IsErrProjectDoesNotExist,
}, },
{ {
name: "ProjectUsers Create with inexisting user", name: "ListUsers Create with inexisting user",
fields: fields{ fields: fields{
Username: "user500", Username: "user500",
ProjectID: 2, ProjectID: 2,
@ -96,7 +96,7 @@ func TestProjectUser_Create(t *testing.T) {
errType: user.IsErrUserDoesNotExist, errType: user.IsErrUserDoesNotExist,
}, },
{ {
name: "ProjectUsers Create with the owner as shared user", name: "ListUsers Create with the owner as shared user",
fields: fields{ fields: fields{
Username: "user1", Username: "user1",
ProjectID: 1, ProjectID: 1,

View File

@ -25,10 +25,6 @@ import (
) )
func TestSubscriptionGetTypeFromString(t *testing.T) { func TestSubscriptionGetTypeFromString(t *testing.T) {
t.Run("namespace", func(t *testing.T) {
entityType := getEntityTypeFromString("namespace")
assert.Equal(t, SubscriptionEntityType(SubscriptionEntityNamespace), entityType)
})
t.Run("project", func(t *testing.T) { t.Run("project", func(t *testing.T) {
entityType := getEntityTypeFromString("project") entityType := getEntityTypeFromString("project")
assert.Equal(t, SubscriptionEntityType(SubscriptionEntityProject), entityType) assert.Equal(t, SubscriptionEntityType(SubscriptionEntityProject), entityType)
@ -88,22 +84,6 @@ func TestSubscription_Create(t *testing.T) {
assert.Error(t, err) assert.Error(t, err)
assert.False(t, can) assert.False(t, can)
}) })
t.Run("noneixsting namespace", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
sb := &Subscription{
Entity: "namespace",
EntityID: 99999999,
UserID: u.ID,
}
can, err := sb.CanCreate(s, u)
assert.Error(t, err)
assert.True(t, IsErrNamespaceDoesNotExist(err))
assert.False(t, can)
})
t.Run("noneixsting project", func(t *testing.T) { t.Run("noneixsting project", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
@ -136,21 +116,6 @@ func TestSubscription_Create(t *testing.T) {
assert.True(t, IsErrTaskDoesNotExist(err)) assert.True(t, IsErrTaskDoesNotExist(err))
assert.False(t, can) assert.False(t, can)
}) })
t.Run("no rights to see namespace", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
sb := &Subscription{
Entity: "namespace",
EntityID: 6,
UserID: u.ID,
}
can, err := sb.CanCreate(s, u)
assert.NoError(t, err)
assert.False(t, can)
})
t.Run("no rights to see project", func(t *testing.T) { t.Run("no rights to see project", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
@ -268,16 +233,6 @@ func TestSubscriptionGet(t *testing.T) {
u := &user.User{ID: 6} u := &user.User{ID: 6}
t.Run("test each individually", func(t *testing.T) { t.Run("test each individually", func(t *testing.T) {
t.Run("namespace", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
sub, err := GetSubscription(s, SubscriptionEntityNamespace, 6, u)
assert.NoError(t, err)
assert.NotNil(t, sub)
assert.Equal(t, int64(2), sub.ID)
})
t.Run("project", func(t *testing.T) { t.Run("project", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
@ -300,27 +255,27 @@ func TestSubscriptionGet(t *testing.T) {
}) })
}) })
t.Run("inherited", func(t *testing.T) { t.Run("inherited", func(t *testing.T) {
t.Run("project from namespace", func(t *testing.T) { t.Run("project from parent", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
// Project 6 belongs to namespace 6 where user 6 has subscribed to // Project 6 belongs to project 6 where user 6 has subscribed to
sub, err := GetSubscription(s, SubscriptionEntityProject, 6, u) sub, err := GetSubscription(s, SubscriptionEntityProject, 6, u)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, sub) assert.NotNil(t, sub)
assert.Equal(t, int64(2), sub.ID) // assert.Equal(t, int64(2), sub.ID) // TODO
}) })
t.Run("task from namespace", func(t *testing.T) { t.Run("task from parent", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
// Task 20 belongs to project 11 which belongs to namespace 6 where the user has subscribed // Task 20 belongs to project 11 which belongs to project 6 where the user has subscribed
sub, err := GetSubscription(s, SubscriptionEntityTask, 20, u) sub, err := GetSubscription(s, SubscriptionEntityTask, 20, u)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, sub) assert.NotNil(t, sub)
assert.Equal(t, int64(2), sub.ID) // assert.Equal(t, int64(2), sub.ID) TODO
}) })
t.Run("task from project", func(t *testing.T) { t.Run("task from project", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)

View File

@ -1054,33 +1054,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
}, },
wantErr: false, wantErr: false,
}, },
{ // TODO filter parent project?
name: "filter namespace",
fields: fields{
FilterBy: []string{"namespace"},
FilterValue: []string{"7"},
FilterComparator: []string{"equals"},
},
args: defaultArgs,
want: []*Task{
task21,
},
wantErr: false,
},
{
name: "filter namespace in",
fields: fields{
FilterBy: []string{"namespace"},
FilterValue: []string{"7,8"},
FilterComparator: []string{"in"},
},
args: defaultArgs,
want: []*Task{
task21,
task22,
},
wantErr: false,
},
{ {
name: "filter by index", name: "filter by index",
fields: fields{ fields: fields{

View File

@ -58,16 +58,6 @@ func TestTeam_CanDoSomething(t *testing.T) {
}, },
want: map[string]bool{"CanCreate": true, "IsAdmin": true, "CanRead": true, "CanDelete": true, "CanUpdate": true}, want: map[string]bool{"CanCreate": true, "IsAdmin": true, "CanRead": true, "CanDelete": true, "CanUpdate": true},
}, },
{
name: "CanDoSomething for a nonexistant namespace",
fields: fields{
ID: 300,
},
args: args{
a: &user.User{ID: 1},
},
want: map[string]bool{"CanCreate": true, "IsAdmin": false, "CanRead": false, "CanDelete": false, "CanUpdate": false},
},
{ {
name: "CanDoSomething where the user does not have the rights", name: "CanDoSomething where the user does not have the rights",
fields: fields{ fields: fields{

View File

@ -110,7 +110,7 @@ func TestTeam_ReadAll(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, reflect.TypeOf(teams).Kind(), reflect.Slice) assert.Equal(t, reflect.TypeOf(teams).Kind(), reflect.Slice)
ts := reflect.ValueOf(teams) ts := reflect.ValueOf(teams)
assert.Equal(t, 8, ts.Len()) assert.Equal(t, 5, ts.Len())
}) })
t.Run("search", func(t *testing.T) { t.Run("search", func(t *testing.T) {
s := db.NewSession() s := db.NewSession()

View File

@ -46,7 +46,7 @@ func TestDeleteUser(t *testing.T) {
db.AssertExists(t, "projects", map[string]interface{}{"id": 10}, false) db.AssertExists(t, "projects", map[string]interface{}{"id": 10}, false)
db.AssertExists(t, "projects", map[string]interface{}{"id": 11}, false) db.AssertExists(t, "projects", map[string]interface{}{"id": 11}, false)
}) })
t.Run("user with no namespaces", func(t *testing.T) { t.Run("user with no projects", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
@ -56,6 +56,6 @@ func TestDeleteUser(t *testing.T) {
err := DeleteUser(s, u) err := DeleteUser(s, u)
assert.NoError(t, err) assert.NoError(t, err)
// No assertions for deleted projects and namespaces since that user doesn't have any // No assertions for deleted projects since that user doesn't have any
}) })
} }

View File

@ -24,7 +24,7 @@ import (
"gopkg.in/d4l3k/messagediff.v1" "gopkg.in/d4l3k/messagediff.v1"
) )
func TestProjectUsersFromProject(t *testing.T) { func TestListUsersFromProject(t *testing.T) {
testuser1 := &user.User{ testuser1 := &user.User{
ID: 1, ID: 1,
Username: "user1", Username: "user1",
@ -205,13 +205,13 @@ func TestProjectUsersFromProject(t *testing.T) {
testuser7, // Owner testuser7, // Owner
testuser8, // Shared Via NamespaceTeam readonly testuser8, // Shared Via Parent Project Team readonly
testuser9, // Shared Via NamespaceTeam write testuser9, // Shared Via Parent Project Team write
testuser10, // Shared Via NamespaceTeam admin testuser10, // Shared Via Parent Project Team admin
testuser11, // Shared Via NamespaceUser readonly testuser11, // Shared Via Parent Project User readonly
testuser12, // Shared Via NamespaceUser write testuser12, // Shared Via Parent Project User write
testuser13, // Shared Via NamespaceUser admin testuser13, // Shared Via Parent Project User admin
}, },
}, },
{ {

View File

@ -32,13 +32,13 @@ func TestInsertFromStructure(t *testing.T) {
} }
t.Run("normal", func(t *testing.T) { t.Run("normal", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
testStructure := []*models.NamespaceWithProjectsAndTasks{ testStructure := []*models.ProjectWithTasksAndBuckets{
{ {
Namespace: models.Namespace{ Project: models.Project{
Title: "Test1", Title: "Test1",
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
}, },
Projects: []*models.ProjectWithTasksAndBuckets{ ChildProjects: []*models.ProjectWithTasksAndBuckets{
{ {
Project: models.Project{ Project: models.Project{
Title: "Testproject1", Title: "Testproject1",
@ -129,23 +129,19 @@ func TestInsertFromStructure(t *testing.T) {
} }
err := InsertFromStructure(testStructure, u) err := InsertFromStructure(testStructure, u)
assert.NoError(t, err) assert.NoError(t, err)
db.AssertExists(t, "namespaces", map[string]interface{}{
"title": testStructure[0].Namespace.Title,
"description": testStructure[0].Namespace.Description,
}, false)
db.AssertExists(t, "projects", map[string]interface{}{ db.AssertExists(t, "projects", map[string]interface{}{
"title": testStructure[0].Projects[0].Title, "title": testStructure[0].ChildProjects[0].Title,
"description": testStructure[0].Projects[0].Description, "description": testStructure[0].ChildProjects[0].Description,
}, false) }, false)
db.AssertExists(t, "tasks", map[string]interface{}{ db.AssertExists(t, "tasks", map[string]interface{}{
"title": testStructure[0].Projects[0].Tasks[5].Title, "title": testStructure[0].ChildProjects[0].Tasks[5].Title,
"bucket_id": testStructure[0].Projects[0].Buckets[0].ID, "bucket_id": testStructure[0].ChildProjects[0].Buckets[0].ID,
}, false) }, false)
db.AssertMissing(t, "tasks", map[string]interface{}{ db.AssertMissing(t, "tasks", map[string]interface{}{
"title": testStructure[0].Projects[0].Tasks[6].Title, "title": testStructure[0].ChildProjects[0].Tasks[6].Title,
"bucket_id": 1111, // No task with that bucket should exist "bucket_id": 1111, // No task with that bucket should exist
}) })
assert.NotEqual(t, 0, testStructure[0].Projects[0].Tasks[0].BucketID) // Should get the default bucket assert.NotEqual(t, 0, testStructure[0].ChildProjects[0].Tasks[0].BucketID) // Should get the default bucket
assert.NotEqual(t, 0, testStructure[0].Projects[0].Tasks[6].BucketID) // Should get the default bucket assert.NotEqual(t, 0, testStructure[0].ChildProjects[0].Tasks[6].BucketID) // Should get the default bucket
}) })
} }

View File

@ -102,12 +102,12 @@ func TestConverting(t *testing.T) {
}, },
} }
expectedHierachie := []*models.NamespaceWithProjectsAndTasks{ expectedHierachie := []*models.ProjectWithTasksAndBuckets{
{ {
Namespace: models.Namespace{ Project: models.Project{
Title: "Migrated from Microsoft Todo", Title: "Migrated from Microsoft Todo",
}, },
Projects: []*models.ProjectWithTasksAndBuckets{ ChildProjects: []*models.ProjectWithTasksAndBuckets{
{ {
Project: models.Project{ Project: models.Project{
Title: "Project 1", Title: "Project 1",

View File

@ -84,29 +84,29 @@ func TestConvertTicktickTasksToVikunja(t *testing.T) {
vikunjaTasks := convertTickTickToVikunja(tickTickTasks) vikunjaTasks := convertTickTickToVikunja(tickTickTasks)
assert.Len(t, vikunjaTasks, 1) assert.Len(t, vikunjaTasks, 1)
assert.Len(t, vikunjaTasks[0].Projects, 2) assert.Len(t, vikunjaTasks[0].ChildProjects, 2)
assert.Len(t, vikunjaTasks[0].Projects[0].Tasks, 3) assert.Len(t, vikunjaTasks[0].ChildProjects[0].Tasks, 3)
assert.Equal(t, vikunjaTasks[0].Projects[0].Title, tickTickTasks[0].ProjectName) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Title, tickTickTasks[0].ProjectName)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Title, tickTickTasks[0].Title) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Title, tickTickTasks[0].Title)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Description, tickTickTasks[0].Content) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Description, tickTickTasks[0].Content)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].StartDate, tickTickTasks[0].StartDate) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].StartDate, tickTickTasks[0].StartDate)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].EndDate, tickTickTasks[0].DueDate) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].EndDate, tickTickTasks[0].DueDate)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].DueDate, tickTickTasks[0].DueDate) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].DueDate, tickTickTasks[0].DueDate)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Labels, []*models.Label{ assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Labels, []*models.Label{
{Title: "label1"}, {Title: "label1"},
{Title: "label2"}, {Title: "label2"},
}) })
//assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Reminders, tickTickTasks[0].) // TODO //assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Reminders, tickTickTasks[0].) // TODO
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Position, tickTickTasks[0].Order) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Position, tickTickTasks[0].Order)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Done, false) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Done, false)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[1].Title, tickTickTasks[1].Title) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[1].Title, tickTickTasks[1].Title)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[1].Position, tickTickTasks[1].Order) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[1].Position, tickTickTasks[1].Order)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[1].Done, true) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[1].Done, true)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[1].DoneAt, tickTickTasks[1].CompletedTime) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[1].DoneAt, tickTickTasks[1].CompletedTime)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[1].RelatedTasks, models.RelatedTaskMap{ assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[1].RelatedTasks, models.RelatedTaskMap{
models.RelationKindParenttask: []*models.Task{ models.RelationKindParenttask: []*models.Task{
{ {
ID: tickTickTasks[1].ParentID, ID: tickTickTasks[1].ParentID,
@ -114,23 +114,23 @@ func TestConvertTicktickTasksToVikunja(t *testing.T) {
}, },
}) })
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].Title, tickTickTasks[2].Title) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].Title, tickTickTasks[2].Title)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].Description, tickTickTasks[2].Content) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].Description, tickTickTasks[2].Content)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].StartDate, tickTickTasks[2].StartDate) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].StartDate, tickTickTasks[2].StartDate)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].EndDate, tickTickTasks[2].DueDate) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].EndDate, tickTickTasks[2].DueDate)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].DueDate, tickTickTasks[2].DueDate) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].DueDate, tickTickTasks[2].DueDate)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].Labels, []*models.Label{ assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].Labels, []*models.Label{
{Title: "label1"}, {Title: "label1"},
{Title: "label2"}, {Title: "label2"},
{Title: "other label"}, {Title: "other label"},
}) })
//assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[0].Reminders, tickTickTasks[0].) // TODO //assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[0].Reminders, tickTickTasks[0].) // TODO
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].Position, tickTickTasks[2].Order) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].Position, tickTickTasks[2].Order)
assert.Equal(t, vikunjaTasks[0].Projects[0].Tasks[2].Done, false) assert.Equal(t, vikunjaTasks[0].ChildProjects[0].Tasks[2].Done, false)
assert.Len(t, vikunjaTasks[0].Projects[1].Tasks, 1) assert.Len(t, vikunjaTasks[0].ChildProjects[1].Tasks, 1)
assert.Equal(t, vikunjaTasks[0].Projects[1].Title, tickTickTasks[3].ProjectName) assert.Equal(t, vikunjaTasks[0].ChildProjects[1].Title, tickTickTasks[3].ProjectName)
assert.Equal(t, vikunjaTasks[0].Projects[1].Tasks[0].Title, tickTickTasks[3].Title) assert.Equal(t, vikunjaTasks[0].ChildProjects[1].Tasks[0].Title, tickTickTasks[3].Title)
assert.Equal(t, vikunjaTasks[0].Projects[1].Tasks[0].Position, tickTickTasks[3].Order) assert.Equal(t, vikunjaTasks[0].ChildProjects[1].Tasks[0].Position, tickTickTasks[3].Order)
} }

View File

@ -373,12 +373,12 @@ func TestConvertTodoistToVikunja(t *testing.T) {
}, },
} }
expectedHierachie := []*models.NamespaceWithProjectsAndTasks{ expectedHierachie := []*models.ProjectWithTasksAndBuckets{
{ {
Namespace: models.Namespace{ Project: models.Project{
Title: "Migrated from todoist", Title: "Migrated from todoist",
}, },
Projects: []*models.ProjectWithTasksAndBuckets{ ChildProjects: []*models.ProjectWithTasksAndBuckets{
{ {
Project: models.Project{ Project: models.Project{
Title: "Project1", Title: "Project1",

View File

@ -44,7 +44,7 @@ func TestConvertTrelloToVikunja(t *testing.T) {
Name: "TestBoard", Name: "TestBoard",
Desc: "This is a description", Desc: "This is a description",
Closed: false, Closed: false,
Projects: []*trello.Project{ Lists: []*trello.List{
{ {
Name: "Test Project 1", Name: "Test Project 1",
Cards: []*trello.Card{ Cards: []*trello.Card{
@ -77,7 +77,7 @@ func TestConvertTrelloToVikunja(t *testing.T) {
{ {
Name: "Test Card 2", Name: "Test Card 2",
Pos: 124, Pos: 124,
Checkprojects: []*trello.Checkproject{ Checklists: []*trello.Checklist{
{ {
Name: "Checkproject 1", Name: "Checkproject 1",
CheckItems: []trello.CheckItem{ CheckItems: []trello.CheckItem{
@ -157,7 +157,7 @@ func TestConvertTrelloToVikunja(t *testing.T) {
{ {
Name: "TestBoard 2", Name: "TestBoard 2",
Closed: false, Closed: false,
Projects: []*trello.Project{ Lists: []*trello.List{
{ {
Name: "Test Project 4", Name: "Test Project 4",
Cards: []*trello.Card{ Cards: []*trello.Card{
@ -172,7 +172,7 @@ func TestConvertTrelloToVikunja(t *testing.T) {
{ {
Name: "TestBoard Archived", Name: "TestBoard Archived",
Closed: true, Closed: true,
Projects: []*trello.Project{ Lists: []*trello.List{
{ {
Name: "Test Project 5", Name: "Test Project 5",
Cards: []*trello.Card{ Cards: []*trello.Card{
@ -187,12 +187,12 @@ func TestConvertTrelloToVikunja(t *testing.T) {
} }
trelloData[0].Prefs.BackgroundImage = "https://vikunja.io/testimage.jpg" // Using an image which we are hosting, so it'll still be up trelloData[0].Prefs.BackgroundImage = "https://vikunja.io/testimage.jpg" // Using an image which we are hosting, so it'll still be up
expectedHierachie := []*models.NamespaceWithProjectsAndTasks{ expectedHierachie := []*models.ProjectWithTasksAndBuckets{
{ {
Namespace: models.Namespace{ Project: models.Project{
Title: "Imported from Trello", Title: "Imported from Trello",
}, },
Projects: []*models.ProjectWithTasksAndBuckets{ ChildProjects: []*models.ProjectWithTasksAndBuckets{
{ {
Project: models.Project{ Project: models.Project{
Title: "TestBoard", Title: "TestBoard",

View File

@ -44,10 +44,6 @@ func TestVikunjaFileMigrator_Migrate(t *testing.T) {
err = m.Migrate(u, f, s.Size()) err = m.Migrate(u, f, s.Size())
assert.NoError(t, err) assert.NoError(t, err)
db.AssertExists(t, "namespaces", map[string]interface{}{
"title": "test",
"owner_id": u.ID,
}, false)
db.AssertExists(t, "projects", map[string]interface{}{ db.AssertExists(t, "projects", map[string]interface{}{
"title": "Test project", "title": "Test project",
"owner_id": u.ID, "owner_id": u.ID,

View File

@ -358,13 +358,13 @@ func TestUpdateUserPassword(t *testing.T) {
}) })
} }
func TestProjectUsers(t *testing.T) { func TestListUsers(t *testing.T) {
t.Run("normal", func(t *testing.T) { t.Run("normal", func(t *testing.T) {
db.LoadAndAssertFixtures(t) db.LoadAndAssertFixtures(t)
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "user1", nil) all, err := ListUsers(s, "user1", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, len(all) > 0) assert.True(t, len(all) > 0)
assert.Equal(t, all[0].Username, "user1") assert.Equal(t, all[0].Username, "user1")
@ -374,7 +374,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "uSEr1", nil) all, err := ListUsers(s, "uSEr1", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, len(all) > 0) assert.True(t, len(all) > 0)
assert.Equal(t, all[0].Username, "user1") assert.Equal(t, all[0].Username, "user1")
@ -393,7 +393,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "", nil) all, err := ListUsers(s, "", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 0) assert.Len(t, all, 0)
}) })
@ -402,7 +402,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "user1@example.com", nil) all, err := ListUsers(s, "user1@example.com", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 0) assert.Len(t, all, 0)
db.AssertExists(t, "users", map[string]interface{}{ db.AssertExists(t, "users", map[string]interface{}{
@ -415,7 +415,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "one else", nil) all, err := ListUsers(s, "one else", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 0) assert.Len(t, all, 0)
db.AssertExists(t, "users", map[string]interface{}{ db.AssertExists(t, "users", map[string]interface{}{
@ -428,7 +428,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "user7@example.com", nil) all, err := ListUsers(s, "user7@example.com", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 1) assert.Len(t, all, 1)
assert.Equal(t, int64(7), all[0].ID) assert.Equal(t, int64(7), all[0].ID)
@ -442,7 +442,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "with space", nil) all, err := ListUsers(s, "with space", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 1) assert.Len(t, all, 1)
assert.Equal(t, int64(12), all[0].ID) assert.Equal(t, int64(12), all[0].ID)
@ -470,7 +470,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "user7", nil) all, err := ListUsers(s, "user7", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 1) assert.Len(t, all, 1)
assert.Equal(t, int64(7), all[0].ID) assert.Equal(t, int64(7), all[0].ID)
@ -483,7 +483,7 @@ func TestProjectUsers(t *testing.T) {
s := db.NewSession() s := db.NewSession()
defer s.Close() defer s.Close()
all, err := ProjectUsers(s, "user", nil) all, err := ListUsers(s, "user", nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, all, 0) assert.Len(t, all, 0)
db.AssertExists(t, "users", map[string]interface{}{ db.AssertExists(t, "users", map[string]interface{}{