11package 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.*
84import org.hamcrest.CoreMatchers.equalTo
95import org.hamcrest.MatcherAssert.assertThat
106import 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