Skip to content

Commit 386827e

Browse files
test/Add basic user invitation tests
1 parent d930479 commit 386827e

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package code.api.v4_0_0
2+
3+
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
4+
import code.api.util.APIUtil.OAuth._
5+
import code.api.util.ApiRole.{CanCreateUserInvitation, CanGetUserInvitation}
6+
import code.api.util.ErrorMessages.{CannotGetUserInvitation, UserHasMissingRoles, UserNotLoggedIn}
7+
import code.api.v4_0_0.OBPAPI4_0_0.Implementations4_0_0
8+
import com.github.dwickern.macros.NameOf.nameOf
9+
import com.openbankproject.commons.model.ErrorMessage
10+
import com.openbankproject.commons.util.ApiVersion
11+
import net.liftweb.json.Serialization.write
12+
import org.scalatest.Tag
13+
14+
class UserInvitationTest extends V400ServerSetup {
15+
/**
16+
* Test tags
17+
* Example: To run tests with tag "getPermissions":
18+
* mvn test -D tagsToInclude
19+
*
20+
* This is made possible by the scalatest maven plugin
21+
*/
22+
object VersionOfApi extends Tag(ApiVersion.v4_0_0.toString)
23+
object ApiEndpoint1 extends Tag(nameOf(Implementations4_0_0.createUserInvitation))
24+
object ApiEndpoint2 extends Tag(nameOf(Implementations4_0_0.getUserInvitationAnonymous))
25+
object ApiEndpoint3 extends Tag(nameOf(Implementations4_0_0.getUserInvitation))
26+
object ApiEndpoint4 extends Tag(nameOf(Implementations4_0_0.getUserInvitations))
27+
28+
29+
feature(s"test $ApiEndpoint1 version $VersionOfApi - Unauthorized access") {
30+
scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) {
31+
When("We make a request v4.0.0")
32+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitation").POST
33+
val postJson = SwaggerDefinitionsJSON.userInvitationPostJsonV400
34+
val response400 = makePostRequest(request400, write(postJson))
35+
Then("We should get a 401")
36+
response400.code should equal(401)
37+
response400.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
38+
}
39+
}
40+
feature(s"test $ApiEndpoint1 version $VersionOfApi - Authorized access") {
41+
scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) {
42+
When("We make a request v4.0.0")
43+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitation").POST <@(user1)
44+
val postJson = SwaggerDefinitionsJSON.userInvitationPostJsonV400
45+
val response400 = makePostRequest(request400, write(postJson))
46+
Then("error should be " + UserHasMissingRoles + CanCreateUserInvitation)
47+
response400.code should equal(403)
48+
response400.body.extract[ErrorMessage].message should startWith(UserHasMissingRoles + CanCreateUserInvitation)
49+
}
50+
}
51+
52+
53+
feature(s"test $ApiEndpoint2 version $VersionOfApi - Authorized access") {
54+
scenario("We will call the endpoint without user credentials", ApiEndpoint2, VersionOfApi) {
55+
When("We make a request v4.0.0")
56+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitations").POST <@(user1)
57+
val postJson = PostUserInvitationAnonymousJsonV400(secret_key = 0L)
58+
val response400 = makePostRequest(request400, write(postJson))
59+
Then("error should be " + CannotGetUserInvitation)
60+
response400.code should equal(404)
61+
response400.body.extract[ErrorMessage].message should be(CannotGetUserInvitation)
62+
}
63+
}
64+
65+
feature(s"test $ApiEndpoint3 version $VersionOfApi - Unauthorized access") {
66+
scenario("We will call the endpoint without user credentials", ApiEndpoint3, VersionOfApi) {
67+
When("We make a request v4.0.0")
68+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitations" / "secret-link").GET
69+
val response400 = makeGetRequest(request400)
70+
Then("We should get a 401")
71+
response400.code should equal(401)
72+
response400.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
73+
}
74+
}
75+
feature(s"test $ApiEndpoint3 version $VersionOfApi - Authorized access") {
76+
scenario("We will call the endpoint without user credentials", ApiEndpoint3, VersionOfApi) {
77+
When("We make a request v4.0.0")
78+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitations" / "secret-link").GET <@(user1)
79+
val response400 = makeGetRequest(request400)
80+
Then("error should be " + UserHasMissingRoles + CanGetUserInvitation)
81+
response400.code should equal(403)
82+
response400.body.extract[ErrorMessage].message should startWith(UserHasMissingRoles + CanGetUserInvitation)
83+
}
84+
}
85+
86+
feature(s"test $ApiEndpoint4 version $VersionOfApi - Unauthorized access") {
87+
scenario("We will call the endpoint without user credentials", ApiEndpoint4, VersionOfApi) {
88+
When("We make a request v4.0.0")
89+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitations").GET
90+
val response400 = makeGetRequest(request400)
91+
Then("We should get a 401")
92+
response400.code should equal(401)
93+
response400.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
94+
}
95+
}
96+
feature(s"test $ApiEndpoint4 version $VersionOfApi - Authorized access") {
97+
scenario("We will call the endpoint without user credentials", ApiEndpoint4, VersionOfApi) {
98+
When("We make a request v4.0.0")
99+
val request400 = (v4_0_0_Request / "banks" / testBankId1.value / "user-invitations").GET <@(user1)
100+
val response400 = makeGetRequest(request400)
101+
Then("error should be " + UserHasMissingRoles + CanGetUserInvitation)
102+
response400.code should equal(403)
103+
response400.body.extract[ErrorMessage].message should startWith(UserHasMissingRoles + CanGetUserInvitation)
104+
}
105+
}
106+
107+
108+
}

0 commit comments

Comments
 (0)