Skip to content

Commit ec38928

Browse files
committed
make tests dry
1 parent 5814d72 commit ec38928

File tree

2 files changed

+82
-105
lines changed

2 files changed

+82
-105
lines changed

server/servers/api/src/test/scala/com/prisma/api/queries/MultiItemConnectionQuerySpec.scala

Lines changed: 45 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.prisma.api.queries
22

3-
import com.prisma.{IgnoreMongo, IgnoreMySql, IgnorePostgres, IgnoreSQLite}
4-
import com.prisma.api.ApiSpecBase
3+
import com.prisma.api.{ApiSpecBase, TestDataModels}
54
import com.prisma.shared.schema_dsl.SchemaDsl
65
import org.scalatest.{FlatSpec, Matchers}
76

@@ -111,88 +110,55 @@ class MultiItemConnectionQuerySpec extends FlatSpec with Matchers with ApiSpecBa
111110
.toString should equal("""{"data":{"todoesConnection":{"edges":[{"node":{"title":"Hello World!"}}]}}}""")
112111
}
113112

114-
"the connection query" should "work when using cursors on Mongo" taggedAs (IgnoreMySql, IgnorePostgres, IgnoreSQLite) in {
115-
116-
val project2 = SchemaDsl.fromStringV11() {
117-
"""type User {
118-
| id: ID! @id
119-
| name: String
120-
| following: [User!]! @relation(name: "UserToFollow", link: INLINE)
121-
| followers: [User!]! @relation(name: "UserToFollow")
122-
|}""".stripMargin
113+
"the connection query" should "work when using cursors when not on Mongo" in {
114+
val datamodels = {
115+
val dm1 =
116+
"""type User {
117+
id: ID! @id
118+
name: String
119+
following: [User!]! @relation(name: "UserToFollow", link: INLINE)
120+
followers: [User!]! @relation(name: "UserToFollow")
121+
}"""
122+
123+
val dm2 =
124+
"""type User {
125+
| id: ID! @id
126+
| name: String
127+
| following: [User!]! @relation(name: "UserToFollow", link: TABLE)
128+
| followers: [User!]! @relation(name: "UserToFollow")
129+
|}"""
130+
131+
TestDataModels(mongo = Vector(dm1), sql = Vector(dm2))
123132
}
133+
datamodels.testV11 { project =>
134+
val a = server.query(s"""mutation{createUser(data:{name: "a", followers:{create:[{name:"b"}, {name:"c"}, {name:"x"}]}}){id}}""", project)
135+
val d = server.query(s"""mutation{createUser(data:{name: "d", followers:{create:[{name:"e"}, {name:"f"}, {name:"x"}]}}){id}}""", project)
136+
val g = server.query(s"""mutation{createUser(data:{name: "g", followers:{create:[{name:"h"}, {name:"i"}, {name:"x"}]}}){id}}""", project)
137+
val k = server.query(s"""mutation{createUser(data:{name: "k", followers:{create:[{name:"l"}, {name:"m"}, {name:"x"}]}}){id}}""", project)
124138

125-
database.setup(project2)
126-
127-
val a = server.query(s"""mutation{createUser(data:{name: "a", followers:{create:[{name:"b"}, {name:"c"}, {name:"x"}]}}){id}}""", project2)
128-
val d = server.query(s"""mutation{createUser(data:{name: "d", followers:{create:[{name:"e"}, {name:"f"}, {name:"x"}]}}){id}}""", project2)
129-
val g = server.query(s"""mutation{createUser(data:{name: "g", followers:{create:[{name:"h"}, {name:"i"}, {name:"x"}]}}){id}}""", project2)
130-
val k = server.query(s"""mutation{createUser(data:{name: "k", followers:{create:[{name:"l"}, {name:"m"}, {name:"x"}]}}){id}}""", project2)
131-
132-
val result = server.query(
133-
s"""{
134-
| usersConnection(where: {
135-
| followers_some: {
136-
| name: "x"
137-
| },
138-
| }, first: 2, after: "${a.pathAsString("data.createUser.id")}") {
139-
| aggregate {
140-
| count
141-
| }
142-
| edges {
143-
| node {
144-
| name
145-
| }
146-
| }
147-
| }
148-
|}""".stripMargin,
149-
project2
150-
)
151-
152-
result.toString should be("""{"data":{"usersConnection":{"aggregate":{"count":2},"edges":[{"node":{"name":"d"}},{"node":{"name":"g"}}]}}}""")
153-
154-
}
139+
val result = server.query(
140+
s"""{
141+
| usersConnection(where: {
142+
| followers_some: {
143+
| name: "x"
144+
| },
145+
| }, first: 2, after: "${a.pathAsString("data.createUser.id")}") {
146+
| aggregate {
147+
| count
148+
| }
149+
| edges {
150+
| node {
151+
| name
152+
| }
153+
| }
154+
| }
155+
|}""".stripMargin,
156+
project
157+
)
155158

156-
"the connection query" should "work when using cursors when not on Mongo" taggedAs (IgnoreMongo) in {
159+
result.toString should be("""{"data":{"usersConnection":{"aggregate":{"count":2},"edges":[{"node":{"name":"d"}},{"node":{"name":"g"}}]}}}""")
157160

158-
val project2 = SchemaDsl.fromStringV11() {
159-
"""type User {
160-
| id: ID! @id
161-
| name: String
162-
| following: [User!]! @relation(name: "UserToFollow", link: TABLE)
163-
| followers: [User!]! @relation(name: "UserToFollow")
164-
|}""".stripMargin
165161
}
166-
167-
database.setup(project2)
168-
169-
val a = server.query(s"""mutation{createUser(data:{name: "a", followers:{create:[{name:"b"}, {name:"c"}, {name:"x"}]}}){id}}""", project2)
170-
val d = server.query(s"""mutation{createUser(data:{name: "d", followers:{create:[{name:"e"}, {name:"f"}, {name:"x"}]}}){id}}""", project2)
171-
val g = server.query(s"""mutation{createUser(data:{name: "g", followers:{create:[{name:"h"}, {name:"i"}, {name:"x"}]}}){id}}""", project2)
172-
val k = server.query(s"""mutation{createUser(data:{name: "k", followers:{create:[{name:"l"}, {name:"m"}, {name:"x"}]}}){id}}""", project2)
173-
174-
val result = server.query(
175-
s"""{
176-
| usersConnection(where: {
177-
| followers_some: {
178-
| name: "x"
179-
| },
180-
| }, first: 2, after: "${a.pathAsString("data.createUser.id")}") {
181-
| aggregate {
182-
| count
183-
| }
184-
| edges {
185-
| node {
186-
| name
187-
| }
188-
| }
189-
| }
190-
|}""".stripMargin,
191-
project2
192-
)
193-
194-
result.toString should be("""{"data":{"usersConnection":{"aggregate":{"count":2},"edges":[{"node":{"name":"d"}},{"node":{"name":"g"}}]}}}""")
195-
196162
}
197163

198164
}
Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
11
package com.prisma.api.queries
22

3-
import com.prisma.api.ApiSpecBase
4-
import com.prisma.shared.schema_dsl.SchemaDsl
3+
import com.prisma.api.{ApiSpecBase, TestDataModels}
54
import org.scalatest.{FlatSpec, Matchers}
65

76
class RelationFilterOrderingSpec extends FlatSpec with Matchers with ApiSpecBase {
87

9-
"Using relational filters" should "return items in the specified order" in {
10-
11-
val project = SchemaDsl.fromStringV11() {
12-
"""type Blog {
13-
| id: ID! @id
14-
| title: String!
15-
| score: Int!
16-
| labels: [Label!]! @relation(name: "BlogLabels", link: INLINE)
17-
|}
18-
|type Label {
19-
| id: ID! @id
20-
| text: String! @unique
21-
|}"""
22-
}
23-
24-
database.setup(project)
8+
val datamodels = {
9+
val dm1 = """type Blog {
10+
id: ID! @id
11+
title: String!
12+
score: Int!
13+
labels: [Label!]! @relation(name: "BlogLabels", link: INLINE)
14+
}
15+
type Label {
16+
id: ID! @id
17+
text: String! @unique
18+
}"""
19+
20+
val dm2 = """type Blog {
21+
id: ID! @id
22+
title: String!
23+
score: Int!
24+
labels: [Label!]! @relation(name: "BlogLabels", link: TABLE)
25+
}
26+
type Label {
27+
id: ID! @id
28+
text: String! @unique
29+
}"""
30+
31+
TestDataModels(mongo = Vector(dm1), sql = Vector(dm2))
32+
}
2533

26-
server.query(s"""mutation {createLabel(data: {text: "x"}) {text }}""", project)
34+
"Using relational filters" should "return items in the specified order" in {
35+
datamodels.testV11 { project =>
36+
server.query(s"""mutation {createLabel(data: {text: "x"}) {text }}""", project)
2737

28-
server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 10,labels: {connect: {text: "x"}}}) {title}}""", project)
29-
server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 20,labels: {connect: {text: "x"}}}) {title}}""", project)
30-
server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 30,labels: {connect: {text: "x"}}}) {title}}""", project)
38+
server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 10,labels: {connect: {text: "x"}}}) {title}}""", project)
39+
server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 20,labels: {connect: {text: "x"}}}) {title}}""", project)
40+
server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 30,labels: {connect: {text: "x"}}}) {title}}""", project)
3141

32-
val res1 = server.query("""query {blogs(first: 2, orderBy: score_DESC) {title, score}}""", project)
42+
val res1 = server.query("""query {blogs(first: 2, orderBy: score_DESC) {title, score}}""", project)
3343

34-
res1.toString should be("""{"data":{"blogs":[{"title":"blog_1","score":30},{"title":"blog_1","score":20}]}}""")
44+
res1.toString should be("""{"data":{"blogs":[{"title":"blog_1","score":30},{"title":"blog_1","score":20}]}}""")
3545

36-
val res2 = server.query("""query {blogs (first: 2, orderBy: score_DESC, where:{labels_some: {text: "x"}}) {title, score}}""", project)
37-
res2.toString should be("""{"data":{"blogs":[{"title":"blog_1","score":30},{"title":"blog_1","score":20}]}}""")
46+
val res2 = server.query("""query {blogs (first: 2, orderBy: score_DESC, where:{labels_some: {text: "x"}}) {title, score}}""", project)
47+
res2.toString should be("""{"data":{"blogs":[{"title":"blog_1","score":30},{"title":"blog_1","score":20}]}}""")
3848

49+
}
3950
}
4051
}

0 commit comments

Comments
 (0)