-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Spek version * Fix print wrong escaped character, Fix #4 * Rewrite the GraphQLPrintSpek for preetty print test * Bump hotfix version * Update build status link
- Loading branch information
Verachad Wongsawangtham
authored
Mar 24, 2017
1 parent
747ca09
commit ff19228
Showing
6 changed files
with
174 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,56 +9,80 @@ import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.describe | ||
import org.jetbrains.spek.api.dsl.given | ||
import org.jetbrains.spek.api.dsl.it | ||
import org.junit.platform.runner.JUnitPlatform | ||
import org.junit.runner.RunWith | ||
import org.jetbrains.spek.api.dsl.on | ||
|
||
@RunWith(JUnitPlatform::class) | ||
class GraphQLPrintSpek : Spek({ | ||
|
||
describe("Argument print function") { | ||
given("id as argument and value as 1") { | ||
val node = Argument(mapOf("id" to 1)) | ||
it("should print (id: 1)") { | ||
assertThat(node.print(false, 0), equalTo("(id: 1)")) | ||
on("print pretty") { | ||
it("should print (id: 1)") { | ||
assertThat(node.print(true, 0), equalTo("(id: 1)")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print (id: 1)") { | ||
assertThat(node.print(false, 0), equalTo("(id: 1)")) | ||
} | ||
} | ||
} | ||
given("id and title as arguments and value as 1 and Kraph") { | ||
val node = Argument(mapOf("id" to 1, "title" to "Kraph")) | ||
it("should print (id: 1, title: \\\"Kraph\\\")") { | ||
assertThat(node.print(false, 0), equalTo("(id: 1, title: \\\"Kraph\\\")")) | ||
on("print pretty") { | ||
it("should print (id: 1, title: \"Kraph\")") { | ||
assertThat(node.print(true, 0), equalTo("(id: 1, title: \"Kraph\")")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print (id: 1, title: \\\"Kraph\\\")") { | ||
assertThat(node.print(false, 0), equalTo("(id: 1, title: \\\"Kraph\\\")")) | ||
} | ||
} | ||
} | ||
given("id and title as arguments and value as 1 and Kraph with pretty format enabled") { | ||
val node = Argument(mapOf("id" to 1, "title" to "Kraph")) | ||
it("should print (id: 1, title: \"Kraph\")") { | ||
assertThat(node.print(true, 0), equalTo("(id: 1, title: \"Kraph\")")) | ||
given("an array of string as argument") { | ||
val node = Argument(mapOf("titles" to listOf("title1", "title2"))) | ||
on("print pretty") { | ||
it("should print (titles: [\"title1\", \"title2\"]") { | ||
assertThat(node.print(true, 0), equalTo("(titles: [\"title1\", \"title2\"])")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print (titles: [\\\"title1\\\", \\\"title2\\\"]") { | ||
assertThat(node.print(false, 0), equalTo("(titles: [\\\"title1\\\", \\\"title2\\\"])")) | ||
} | ||
} | ||
} | ||
} | ||
describe("SelectionSet print function") { | ||
given("two fields; id and title") { | ||
val fields = listOf(Field("id"), Field("title")) | ||
val node = SelectionSet(fields) | ||
it("should print {id title}") { | ||
assertThat(node.print(false, 0), equalTo("{\\nid\\ntitle\\n}")) | ||
on("print pretty") { | ||
it("should print {\n id\n title\n}") { | ||
assertThat(node.print(true, 0), equalTo("{\n id\n title\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print {id title}") { | ||
assertThat(node.print(false, 0), equalTo("{\\nid\\ntitle\\n}")) | ||
} | ||
} | ||
} | ||
given("three fields; id, title, and assignee which contains name and email") { | ||
val assigneeSet = SelectionSet(listOf(Field("name"), Field("email"))) | ||
val assigneeField = Field("assignee", selectionSet = assigneeSet) | ||
val fields = listOf(Field("id"), Field("title"), assigneeField) | ||
val node = SelectionSet(fields) | ||
it("should print {id title assignee {name email}}") { | ||
assertThat(node.print(false, 0), equalTo("{\\nid\\ntitle\\nassignee {\\nname\\nemail\\n}\\n}")) | ||
on("print pretty") { | ||
it("should print {\n id\n title\n assignee {\n name\n email\n }\n}") { | ||
assertThat(node.print(true, 0), equalTo("{\n id\n title\n assignee {\n name\n email\n }\n}")) | ||
} | ||
} | ||
} | ||
given("three fields; id, title, and assignee which contains name and email with pretty format enabled") { | ||
val assigneeSet = SelectionSet(listOf(Field("name"), Field("email"))) | ||
val assigneeField = Field("assignee", selectionSet = assigneeSet) | ||
val fields = listOf(Field("id"), Field("title"), assigneeField) | ||
val node = SelectionSet(fields) | ||
it("should print {id title assignee {name email}} with pretty format") { | ||
assertThat(node.print(true, 0), equalTo("{\n id\n title\n assignee {\n name\n email\n }\n}")) | ||
on("print normal") { | ||
it("should print {\\nid\\ntitle\\nassignee {\\nname\\nemail\\n}\\n}") { | ||
assertThat(node.print(false, 0), equalTo("{\\nid\\ntitle\\nassignee {\\nname\\nemail\\n}\\n}")) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -67,75 +91,145 @@ class GraphQLPrintSpek : Spek({ | |
val argNode = InputArgument(mapOf("email" to "[email protected]", "password" to "abcd1234")) | ||
val setNode = SelectionSet(listOf(Field("id"), Field("token"))) | ||
val node = Mutation("registerUser", argNode, setNode) | ||
it("should print registerUser(input: {email: \\\"[email protected]\\\", password: \\\"abcd1234\\\"}){ id token }") { | ||
assertThat(node.print(false, 0), equalTo("registerUser(input: { email: \\\"[email protected]\\\", password: \\\"abcd1234\\\" }) {\\nid\\ntoken\\n}")) | ||
on("print pretty") { | ||
it("should print registerUser(input: { email: \"[email protected]\", password: \"abcd1234\" }){\n id\n token\n}") { | ||
assertThat(node.print(true, 0), equalTo("registerUser(input: { email: \"[email protected]\", password: \"abcd1234\" }) {\n id\n token\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print registerUser(input: { email: \\\"[email protected]\\\", password: \\\"abcd1234\\\" }){ id token }") { | ||
assertThat(node.print(false, 0), equalTo("registerUser(input: { email: \\\"[email protected]\\\", password: \\\"abcd1234\\\" }) {\\nid\\ntoken\\n}")) | ||
} | ||
} | ||
} | ||
} | ||
describe("Field print function") { | ||
given("name id") { | ||
val node = Field("id") | ||
it("should print id") { | ||
assertThat(node.print(false, 0), equalTo("id")) | ||
on("print pretty") { | ||
it("should print id") { | ||
assertThat(node.print(true, 0), equalTo("id")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print id") { | ||
assertThat(node.print(false, 0), equalTo("id")) | ||
} | ||
} | ||
} | ||
given("name avatarSize and size argument with value as 20") { | ||
val argNode = Argument(mapOf("size" to 20)) | ||
val node = Field("avatarSize", arguments = argNode) | ||
it("should print avatarSize(size: 20)") { | ||
assertThat(node.print(false, 0), equalTo("avatarSize(size: 20)")) | ||
on("print pretty") { | ||
it("should print avatarSize(size: 20)") { | ||
assertThat(node.print(true, 0), equalTo("avatarSize(size: 20)")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print avatarSize(size: 20)") { | ||
assertThat(node.print(false, 0), equalTo("avatarSize(size: 20)")) | ||
} | ||
} | ||
} | ||
given("name assignee that contains name and email") { | ||
val setNode = SelectionSet(listOf(Field("name"), Field("email"))) | ||
val node = Field("assignee", selectionSet = setNode) | ||
it("should print assignee { name email }") { | ||
assertThat(node.print(false, 0), equalTo("assignee {\\nname\\nemail\\n}")) | ||
on("print pretty") { | ||
it("should print assignee {\n name\n email\n}") { | ||
assertThat(node.print(true, 0), equalTo("assignee {\n name\n email\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print assignee {\\nname\\nemail\\n}") { | ||
assertThat(node.print(false, 0), equalTo("assignee {\\nname\\nemail\\n}")) | ||
} | ||
} | ||
} | ||
given("name user and id argument with value as 10 and contains name and email") { | ||
val argNode = Argument(mapOf("id" to 10)) | ||
val setNode = SelectionSet(listOf(Field("name"), Field("email"))) | ||
val node = Field("user", argNode, setNode) | ||
it("should print user(id: 10){ name email }") { | ||
assertThat(node.print(false, 0), equalTo("user(id: 10) {\\nname\\nemail\\n}")) | ||
on("print pretty") { | ||
it("should print user(id: 10) {\n name\n email\n") { | ||
assertThat(node.print(true, 0), equalTo("user(id: 10) {\n name\n email\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print user(id: 10) {\\nname\\nemail\\n}") { | ||
assertThat(node.print(false, 0), equalTo("user(id: 10) {\\nname\\nemail\\n}")) | ||
} | ||
} | ||
} | ||
} | ||
describe("Operation print function") { | ||
given("query type and field named id") { | ||
val node = Operation(OperationType.QUERY, SelectionSet(listOf(Field("id")))) | ||
it("should print query { id }") { | ||
assertThat(node.print(false, 0), equalTo("query {\\nid\\n}")) | ||
on("print pretty") { | ||
it("should print query {\n id\n}") { | ||
assertThat(node.print(true, 0), equalTo("query {\n id\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print query {\\nid\\n}") { | ||
assertThat(node.print(false, 0), equalTo("query {\\nid\\n}")) | ||
} | ||
} | ||
} | ||
given("query type with name \"getTask\" and field id") { | ||
val node = Operation(OperationType.QUERY, name = "getTask", selectionSet = SelectionSet(listOf(Field("id")))) | ||
it("should print query getTask { id }") { | ||
assertThat(node.print(false, 0), equalTo("query getTask {\\nid\\n}")) | ||
on("print pretty") { | ||
it("should print query getTask {\n id\n}") { | ||
assertThat(node.print(true, 0), equalTo("query getTask {\n id\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print query getTask {\\nid\\n}") { | ||
assertThat(node.print(false, 0), equalTo("query getTask {\\nid\\n}")) | ||
} | ||
} | ||
} | ||
given("query type with name \"getTask\" and id(1234) as argument and field title") { | ||
val argNode = Argument(mapOf("id" to 1234)) | ||
val node = Operation(OperationType.QUERY, name = "getTask", arguments = argNode, selectionSet= SelectionSet(listOf(Field("title")))) | ||
it("should print query getTask(id: 1234) { title }") { | ||
assertThat(node.print(false, 0), equalTo("query getTask(id: 1234) {\\ntitle\\n}")) | ||
on("print pretty") { | ||
it("should print query getTask(id: 1234) {\n title\n}") { | ||
assertThat(node.print(true, 0), equalTo("query getTask(id: 1234) {\n title\n}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print query getTask(id: 1234) {\\ntitle\\n}") { | ||
assertThat(node.print(false, 0), equalTo("query getTask(id: 1234) {\\ntitle\\n}")) | ||
} | ||
} | ||
} | ||
} | ||
describe("Document print function") { | ||
given("document with simple query") { | ||
val queryNode = Operation(OperationType.QUERY, selectionSet = SelectionSet(listOf(Field("id")))) | ||
val node = Document(queryNode) | ||
it("should print document {\"query\":\"query { id }\", \"variables\": null, \"operationName\": null}") { | ||
assertThat(node.print(false, 0), equalTo("{\"query\": \"query {\\nid\\n}\", \"variables\": null, \"operationName\": null}")) | ||
on("print pretty") { | ||
it("should print document {\"query\":\"query { id }\", \"variables\": null, \"operationName\": null}") { | ||
assertThat(node.print(true, 0), equalTo("{\"query\": \"query {\n id\n}\", \"variables\": null, \"operationName\": null}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print document {\"query\":\"query { id }\", \"variables\": null, \"operationName\": null}") { | ||
assertThat(node.print(false, 0), equalTo("{\"query\": \"query {\\nid\\n}\", \"variables\": null, \"operationName\": null}")) | ||
} | ||
} | ||
} | ||
given("document with query named getAllTasks") { | ||
val queryNode = Operation(OperationType.QUERY, name = "getAllTasks", selectionSet = SelectionSet(listOf(Field("id")))) | ||
val node = Document(queryNode) | ||
it("should print document {\"query\":\"query getAllTasks { id }\", \"variables\": null, \"operationName\": \"getAllTasks\"}") { | ||
assertThat(node.print(false, 0), equalTo("{\"query\": \"query getAllTasks {\\nid\\n}\", \"variables\": null, \"operationName\": \"getAllTasks\"}")) | ||
on("print pretty") { | ||
it("should print document {\"query\":\"query getAllTasks { id }\", \"variables\": null, \"operationName\": \"getAllTasks\"}") { | ||
assertThat(node.print(true, 0), equalTo("{\"query\": \"query getAllTasks {\n id\n}\", \"variables\": null, \"operationName\": \"getAllTasks\"}")) | ||
} | ||
} | ||
on("print normal") { | ||
it("should print document {\"query\":\"query getAllTasks { id }\", \"variables\": null, \"operationName\": \"getAllTasks\"}") { | ||
assertThat(node.print(false, 0), equalTo("{\"query\": \"query getAllTasks {\\nid\\n}\", \"variables\": null, \"operationName\": \"getAllTasks\"}")) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters