Skip to content

Commit 727c3cd

Browse files
pclowesviaductbot
authored andcommitted
Add test coverage for custom checkers
Github-Change-Id: 943765 GitOrigin-RevId: 822cdf22b9e8d3c7f9f7b6b11ae1ddcf6040bdce
1 parent 4d0d8bf commit 727c3cd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

engine/runtime/src/test/kotlin/viaduct/engine/runtime/AccessCheckExecutionTest.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
88
import org.junit.jupiter.api.Assumptions.assumeTrue
99
import org.junit.jupiter.api.Test
1010
import viaduct.engine.api.EngineObjectData
11+
import viaduct.engine.api.mocks.MockEngineObjectData
1112
import viaduct.engine.api.mocks.MockTenantModuleBootstrapper
1213
import viaduct.engine.api.mocks.mkEngineObjectData
1314
import viaduct.engine.api.mocks.mkSchemaWithWiring
@@ -591,6 +592,46 @@ class AccessCheckExecutionTest {
591592
}
592593
}
593594

595+
@Test
596+
fun `type check with rss - access checks skipped`() {
597+
MockTenantModuleBootstrapper(schema) {
598+
field("Query" to "baz") {
599+
resolver {
600+
fn { _, _, _, _, ctx -> ctx.createNodeEngineObjectData("1", bazType) }
601+
}
602+
}
603+
field("Baz" to "y") {
604+
resolver {
605+
objectSelections("x")
606+
fn { _, obj, _, _, _ -> obj.fetch("x").toString() }
607+
}
608+
checker {
609+
// Verifies that the access check for y shouldn't be applied
610+
// during fetch, otherwise the error would be "y checker failed"
611+
fn { _, _ -> throw RuntimeException("y checker failed") }
612+
}
613+
}
614+
type("Baz") {
615+
nodeUnbatchedExecutor { id, _, _ ->
616+
MockEngineObjectData(bazType, mapOf("id" to id, "x" to id.toInt(), "y" to id))
617+
}
618+
checker {
619+
objectSelections("key", "fragment _ on Baz { y }")
620+
621+
fn { _, objectDataMap ->
622+
if (objectDataMap["key"]!!.fetch("y") == "1") {
623+
return@fn Unit
624+
}
625+
}
626+
}
627+
}
628+
}.runFeatureTest {
629+
val result = viaduct.runQuery("{ baz { id } }")
630+
assertEquals(mapOf("baz" to mapOf("id" to "1")), result.getData())
631+
assertEquals(0, result.errors.size)
632+
}
633+
}
634+
594635
@Test
595636
fun `type checks with rss for list of objects - fail one of them`() {
596637
MockTenantModuleBootstrapper(schema) {

0 commit comments

Comments
 (0)