This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4793 from prisma/MongoDeleteManyBug
Mongo Delete Many Bug
- Loading branch information
Showing
3 changed files
with
93 additions
and
7 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
79 changes: 79 additions & 0 deletions
79
server/servers/api/src/test/scala/com/prisma/api/mutations/embedded/DeleteManyBugSpec.scala
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.prisma.api.mutations.embedded | ||
|
||
import com.prisma.api.ApiSpecBase | ||
import com.prisma.shared.models.ConnectorCapability.EmbeddedTypesCapability | ||
import com.prisma.shared.models.Project | ||
import com.prisma.shared.schema_dsl.SchemaDsl | ||
import org.scalatest.{FlatSpec, Matchers} | ||
|
||
class DeleteManyBugSpec extends FlatSpec with Matchers with ApiSpecBase { | ||
override def runOnlyForCapabilities = Set(EmbeddedTypesCapability) | ||
|
||
val schema = | ||
"""type User { | ||
| id: ID! @id | ||
| name: String! @unique | ||
| balances: [Balance!]! | ||
|} | ||
| | ||
|type Balance @embedded { | ||
| currency: String! | ||
| platform: String! | ||
| amount: Float! | ||
|}""" | ||
|
||
lazy val project: Project = SchemaDsl.fromStringV11() { schema } | ||
|
||
override protected def beforeAll(): Unit = { | ||
super.beforeAll() | ||
database.setup(project) | ||
} | ||
|
||
override def beforeEach(): Unit = database.truncateProjectTables(project) | ||
|
||
"The delete many Mutation" should "delete the items matching the where relation filter" in { | ||
|
||
server.query( | ||
s"""mutation { | ||
| createUser( | ||
| data: { | ||
| name: "user" | ||
| balances: { | ||
| create: [ | ||
| {platform: "OnlineWallet", currency: "BTC", amount: 1} | ||
| {platform: "PaperWallet", currency: "BTC", amount: 1} | ||
| {platform: "OnlineWallet", currency: "ETH", amount: 1} | ||
| ] | ||
| } | ||
| } | ||
| ) { | ||
| id | ||
| } | ||
|} | ||
""", | ||
project | ||
) | ||
|
||
val res = server.query( | ||
s"""mutation { | ||
| updateUser( | ||
| data: { balances: { deleteMany: { platform: "PaperWallet", currency: "BTC" } } } | ||
| where: { name: "user" } | ||
| ) { | ||
| name | ||
| balances { | ||
| platform | ||
| currency | ||
| } | ||
| } | ||
|} | ||
""", | ||
project | ||
) | ||
|
||
res.toString should be( | ||
"""{"data":{"updateUser":{"name":"user","balances":[{"platform":"OnlineWallet","currency":"BTC"},{"platform":"OnlineWallet","currency":"ETH"}]}}}""") | ||
|
||
} | ||
|
||
} |