Skip to content

Commit

Permalink
Added Movies TCK Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Mar 12, 2019
1 parent 23b5201 commit 6525401
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 31 deletions.
4 changes: 2 additions & 2 deletions readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ curl -XPOST http://localhost:4567/graphql -d'{"query":"{person {name}}"}'
* aliases
* inline and named fragments
* auto-generate queries
* @cypher for fields
* auto-generate mutations

=== Next

* auto-generate mutations
* sorting (nested)
* interfaces
* input types
* @cypher for fields
* unions
* scalars
* date(time), spatial
Expand Down
30 changes: 4 additions & 26 deletions src/test/kotlin/org/neo4j/graphql/MovieSchemaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,11 @@ class MovieSchemaTest {
))
}

/*
@Test fun `testsimple Cypher query`() { val graphQLQuery = """{ Movie(title: "River Runs Through It, A") { title } }""", expectedCypherQuery = """MATCH (movie:Movie {title:${"$"}title}) RETURN movie { .title } AS movie SKIP ${"$"}offset""";
testTranslation(graphQLQuery, expectedCypherQuery, mapOf(
"title" to "River Runs Through It, A",
"first" to -1,
"offset" to 0
))
}
fun `testSimple skip limit`() {
val graphQLQuery = """{
Movie("title" to "River Runs Through It, A", first: 1, offset: 0) {
title
year
}
}
"""val expectedCypherQuery =
"""MATCH (movie:Movie {title:${"$"}title}) RETURN movie { .title , .year } AS movie SKIP ${"$"}offset LIMIT ${"$"}first""";
testTranslation(graphQLQuery, expectedCypherQuery, mapOf(
"title" to "River Runs Through It, A",
first: 1,
"offset" to 0
))
}
@Test fun testTck() {
TckTest(schema).testTck("movie-test.md",0, false)
}

/*
fun `testCypher projection skip limit`() {
val graphQLQuery = """{
Movie(title: "River Runs Through It, A") {
Expand Down
7 changes: 4 additions & 3 deletions src/test/kotlin/org/neo4j/graphql/TckTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,25 @@ class TckTest(val schema:String) {
return testData
}

public fun testTck(fileName: String, expectedFailures: Int) {
public fun testTck(fileName: String, expectedFailures: Int, fail:Boolean = false) {
val pairs = loadQueryPairsFrom(fileName)
val failed = pairs.map {
try {
assertQuery(schema, it.first, it.second, it.third); null
} catch (ae: Throwable) {
ae.message
if (fail) throw ae else ae.message
}
}
.filterNotNull()
failed.forEach(::println)
println("""Succeeded in "$fileName": ${pairs.size - failed.size} of ${pairs.size}""")
Assert.assertEquals("${failed.size} failed of ${pairs.size}", expectedFailures, failed.size)
}

companion object {
fun assertQuery(schema:String, query: String, expected: String, params : Map<String,Any?> = emptyMap()) {
val result = Translator(SchemaBuilder.buildSchema(schema)).translate(query).first()
Assert.assertEquals(expected, result.query)
Assert.assertEquals(expected.replace(Regex("\\s+")," "), result.query)
Assert.assertTrue("${params} IN ${result.params}", result.params.entries.containsAll(params.entries))
}
}
Expand Down
89 changes: 89 additions & 0 deletions src/test/resources/movie-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
## Filter Test TCK


### Schema
```schema
```

### Basic Test

```graphql
{ Movie(title: "River Runs Through It, A") { title } }
```
```params
{"movieTitle":"River Runs Through It, A"}
```
```cypher
MATCH (movie:Movie)
WHERE movie.title = $movieTitle
RETURN movie { .title } AS movie
```

### Testing Paging

```graphql
{
Movie("title" to "River Runs Through It, A", first: 1, offset: 0) {
title
year
}
}
```

```params
{"movieTitle": "River Runs Through It, A", "first": 1, "offset": 0}
```

```cypher
MATCH (movie:Movie)
WHERE movie.title = $movieTitle
RETURN movie { .title , .year } AS movie
SKIP $offset LIMIT $first
```

### Testing Projection

```graphql
{
Movie(title: "River Runs Through It, A") {
title
actors {
name
}
}
}
```

```params
{"movieTitle": "River Runs Through It, A"}
```

```cypher
MATCH (movie:Movie)
WHERE movie.title = $movieTitle
RETURN movie { .title,actors:[(movie)<-[:ACTED_IN]-(movieActors:Actor) | movieActors { .name }] } AS movie
```

### Testing Projection with sub-paging

```graphql
{
Movie(title: "River Runs Through It, A") {
title
actors(first:3) {
name
}
}
}
```
#### todo ,"actorsFirst":3
```params
{"movieTitle": "River Runs Through It, A"}
```

```cypher
MATCH (movie:Movie)
WHERE movie.title = $movieTitle
RETURN movie { .title,actors:[(movie)<-[:ACTED_IN]-(movieActors:Actor) | movieActors { .name }][0..3] } AS movie
```

0 comments on commit 6525401

Please sign in to comment.