-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathActiveProjectDaoTest.scala
104 lines (91 loc) · 3.25 KB
/
ActiveProjectDaoTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package models.dao
import models.project.ActiveProject
import org.scalacheck.Gen
import testutils.fixture.{ActiveProjectFixture, AnswerFixture, UserFixture}
import testutils.generator.ActiveProjectGenerator
/**
* Test for activeProject DAO.
*/
class ActiveProjectDaoTest
extends BaseDaoTest
with ActiveProjectFixture
with ActiveProjectGenerator
with AnswerFixture {
private val dao = inject[ActiveProjectDao]
"get" should {
"return active projects by specific criteria" in {
forAll(Gen.option(Gen.choose(0L, 3L))) { id =>
val activeProjects = wait(dao.getList(id))
val expectedActiveProjects = ActiveProjectFixture.values.filter(u => id.forall(_ == u.id))
activeProjects.total mustBe expectedActiveProjects.length
activeProjects.data must contain theSameElementsAs expectedActiveProjects
}
}
"return active projects filtered by user" in {
forAll(Gen.option(Gen.oneOf(UserFixture.values.map(_.id)))) { userId =>
val activeProjects = wait(dao.getList(optUserId = userId))
val expectedActiveProjects = ActiveProjectFixture.values
.filter { p =>
userId.forall(uid =>
AnswerFixture.values
.filter(_.userFromId == uid)
.map(_.activeProjectId)
.contains(p.id)
)
}
activeProjects.data must contain theSameElementsAs expectedActiveProjects
}
}
}
"create" should {
"create active project" in {
forAll { activeProject: ActiveProject =>
val created = wait(dao.create(activeProject))
val activeProjectFromDb = wait(dao.getList(optId = Some(created.id))).data.headOption
activeProjectFromDb mustBe defined
created mustBe activeProjectFromDb.get
}
}
}
"isAuditor" should {
"return true if user is auditor of the projects" in {
forAll(
Gen.oneOf(UserFixture.values.map(_.id)),
Gen.oneOf(ActiveProjectFixture.values.map(_.id))
) { (userId, apId) =>
val isAuditor = wait(dao.isAuditor(apId, userId))
val expectedIsAuditor =
ActiveProjectFixture.auditorValues.exists(x => x.userId == userId && x.projectId == apId)
isAuditor mustBe expectedIsAuditor
}
}
}
"addAuditor" should {
"add auditor to project" in {
forAll(
Gen.oneOf(UserFixture.values.map(_.id)),
Gen.oneOf(ActiveProjectFixture.values.map(_.id))
) { (userId, apId) =>
val isAuditor = wait(dao.isAuditor(apId, userId))
if (!isAuditor) {
wait(dao.addAuditor(apId, userId))
val newIsAuditor = wait(dao.isAuditor(apId, userId))
newIsAuditor mustBe true
}
}
}
}
}