Skip to content

Commit

Permalink
more test cases, notes on possible future tests
Browse files Browse the repository at this point in the history
  • Loading branch information
do4gr committed Feb 4, 2019
1 parent 36dfdb9 commit 63132c4
Showing 1 changed file with 107 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@ import org.scalatest.{FlatSpec, Matchers}
class CombiningDifferentNestedMutationsSpec extends FlatSpec with Matchers with ApiSpecBase with SchemaBase {
override def runOnlyForCapabilities: Set[ConnectorCapability] = Set(JoinRelationLinksCapability)
//hardcoded execution order
// nestedCreates
// nestedUpdates
// nestedUpserts
// nestedDeletes
// nestedConnects
// nestedSets
// nestedDisconnects
// nestedUpdateManys
// nestedDeleteManys

//create -> delete
//create -> connect
//create -> set
//create -> disconnect
//connect -> updateMany
//update -> deleteMany
//connect -> disconnect
//disconnect -> deleteMany
// nestedCreates
// nestedUpdates
// nestedUpserts
// nestedDeletes
// nestedConnects
// nestedSets
// nestedDisconnects
// nestedUpdateManys
// nestedDeleteManys
// this could be extended to more combinations and to different schemata
// the error behavior would be interesting to test, which error is returned, does rollback work

"A create followed by an update" should "work" in {
val project = SchemaDsl.fromString() { schemaPMToCM }
Expand Down Expand Up @@ -124,6 +117,54 @@ class CombiningDifferentNestedMutationsSpec extends FlatSpec with Matchers with
"""{"data":{"children":[{"c":"c1","parentsOpt":[{"p":"p1"}]},{"c":"c2","parentsOpt":[{"p":"p1"}]},{"c":"c4","parentsOpt":[{"p":"p1"}]}]}}""")
}

"A create followed by a set" should "work" in {
val project = SchemaDsl.fromString() { schemaPMToCM }
database.setup(project)

val res = server.query(
"""mutation {
| createParent(data: {
| p: "p1"
| childrenOpt: {
| create: [{c: "c1"},{c: "c2"}]
| }
| }){
| childrenOpt{
| c
| }
| }
|}""".stripMargin,
project
)

res.toString should be("""{"data":{"createParent":{"childrenOpt":[{"c":"c1"},{"c":"c2"}]}}}""")

val res2 = server.query(
"""mutation {
| updateParent(
| where:{p: "p1"}
| data: {
| childrenOpt: {
| create: [{c: "c3"},{c: "c4"}],
| set: [{c: "c3"}]
| }
| }){
| childrenOpt{
| c
| }
| }
|}""".stripMargin,
project
)

res2.toString should be("""{"data":{"updateParent":{"childrenOpt":[{"c":"c3"}]}}}""")

ifConnectorIsActive { dataResolver(project).countByTable("_ChildToParent").await should be(1) }

server.query(s"""query{children{c, parentsOpt{p}}}""", project).toString should be(
"""{"data":{"children":[{"c":"c1","parentsOpt":[]},{"c":"c2","parentsOpt":[]},{"c":"c3","parentsOpt":[{"p":"p1"}]},{"c":"c4","parentsOpt":[]}]}}""")
}

"A create followed by an upsert" should "work" in {
val project = SchemaDsl.fromString() { schemaPMToCM }
database.setup(project)
Expand Down Expand Up @@ -178,4 +219,52 @@ class CombiningDifferentNestedMutationsSpec extends FlatSpec with Matchers with
"""{"data":{"children":[{"c":"c1","parentsOpt":[{"p":"p1"}]},{"c":"c2","parentsOpt":[{"p":"p1"}]},{"c":"cUpdated","parentsOpt":[{"p":"p1"}]},{"c":"c4","parentsOpt":[{"p":"p1"}]},{"c":"cNew","parentsOpt":[{"p":"p1"}]}]}}""")
}

"A create followed by a disconnect" should "work" in {
val project = SchemaDsl.fromString() { schemaPMToCM }
database.setup(project)

val res = server.query(
"""mutation {
| createParent(data: {
| p: "p1"
| childrenOpt: {
| create: [{c: "c1"},{c: "c2"}]
| }
| }){
| childrenOpt{
| c
| }
| }
|}""".stripMargin,
project
)

res.toString should be("""{"data":{"createParent":{"childrenOpt":[{"c":"c1"},{"c":"c2"}]}}}""")

val res2 = server.query(
"""mutation {
| updateParent(
| where:{p: "p1"}
| data: {
| childrenOpt: {
| create: [{c: "c3"},{c: "c4"}],
| disconnect: [{c: "c3"}]
| }
| }){
| childrenOpt{
| c
| }
| }
|}""".stripMargin,
project
)

res2.toString should be("""{"data":{"updateParent":{"childrenOpt":[{"c":"c1"},{"c":"c2"},{"c":"c4"}]}}}""")

ifConnectorIsActive { dataResolver(project).countByTable("_ChildToParent").await should be(3) }

server.query(s"""query{children{c, parentsOpt{p}}}""", project).toString should be(
"""{"data":{"children":[{"c":"c1","parentsOpt":[{"p":"p1"}]},{"c":"c2","parentsOpt":[{"p":"p1"}]},{"c":"c3","parentsOpt":[]},{"c":"c4","parentsOpt":[{"p":"p1"}]}]}}""")
}

}

0 comments on commit 63132c4

Please sign in to comment.