Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit efa9d88

Browse files
committed
Added AccessRule tests for PropertyDSL
1 parent 6b32b89 commit efa9d88

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/test/kotlin/com/github/pgutkowski/kgraphql/access/AccessRulesTest.kt

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.github.pgutkowski.kgraphql.access
22

3-
import com.github.pgutkowski.kgraphql.context
4-
import com.github.pgutkowski.kgraphql.defaultSchema
5-
import com.github.pgutkowski.kgraphql.deserialize
6-
import com.github.pgutkowski.kgraphql.expect
7-
import com.github.pgutkowski.kgraphql.extract
3+
import com.github.pgutkowski.kgraphql.*
84
import org.hamcrest.CoreMatchers.equalTo
95
import org.hamcrest.MatcherAssert.assertThat
106
import org.junit.Test
@@ -24,10 +20,16 @@ class AccessRulesTest {
2420
}
2521

2622
type<Player>{
23+
val accessRuleBlock = { player: Player, _: Context ->
24+
if (player.name != "BONNER") IllegalAccessException("ILLEGAL ACCESS") else null
25+
}
26+
2727
property(Player::id){
28-
accessRule { player, _ ->
29-
if(player.name != "BONNER") IllegalAccessException("ILLEGAL ACCESS") else null
30-
}
28+
accessRule(accessRuleBlock)
29+
}
30+
property<String>("item") {
31+
accessRule(accessRuleBlock)
32+
resolver { "item" }
3133
}
3234
}
3335
}
@@ -44,13 +46,28 @@ class AccessRulesTest {
4446

4547
@Test
4648
fun `reject when not matching`(){
47-
expect<IllegalAccessException> {
49+
expect<IllegalAccessException>("") {
4850
deserialize (
4951
schema.execute("{ black_mamba {id} }", context { +"LAKERS" })
5052
).extract<String>("data/black_mamba/id")
5153
}
5254
}
5355

56+
@Test
57+
fun `allow property resolver access rule`() {
58+
assertThat(
59+
deserialize(schema.execute("{white_mamba {item}}")).extract<String>("data/white_mamba/item"),
60+
equalTo("item")
61+
)
62+
}
63+
64+
@Test
65+
fun `reject property resolver access rule`() {
66+
expect<IllegalAccessException>("ILLEGAL ACCESS") {
67+
schema.execute("{black_mamba {item}}", context { +"LAKERS" })
68+
}
69+
}
70+
5471
//TODO: MORE TESTS
5572

5673
}

0 commit comments

Comments
 (0)