Skip to content

Commit

Permalink
chore(deps): update engines to 4.6.0-4.bc452eb701d4709e75729888e0ea0f…
Browse files Browse the repository at this point in the history
…53c19775d1 (#15885)

* chore(deps): update engines to 4.6.0-4.bc452eb701d4709e75729888e0ea0f53c19775d1

* fix: relationMode tests for 1:1 and 1:n relations

* test: fix other NoAction tests

* fix: relationMode tests for n:m relations

Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>
Co-authored-by: jkomyno <skiabo97@gmail.com>
  • Loading branch information
3 people committed Oct 19, 2022
1 parent 814b9a9 commit ebee8a7
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 371 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
}
},
"dependencies": {
"@prisma/engines-version": "4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452"
"@prisma/engines-version": "4.6.0-4.bc452eb701d4709e75729888e0ea0f53c19775d1"
},
"sideEffects": false
}
158 changes: 35 additions & 123 deletions packages/client/tests/functional/relationMode/tests_1-to-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ testMatrix.setupTestSuite(
},
)

// prisma - Restrict
testIf(isRelationMode_prisma && onUpdate === 'Restrict')(
'relationMode=prisma - Restrict - [updateMany] parent id with non-existing id should throw',
// prisma - Restrict / NoAction
testIf(isRelationMode_prisma && ['Restrict', 'NoAction'].includes(onUpdate))(
'relationMode=prisma - Restrict, NoAction - [updateMany] parent id with non-existing id should throw',
async () => {
await expect(
prisma[userModel].updateMany({
Expand Down Expand Up @@ -605,62 +605,6 @@ testMatrix.setupTestSuite(
})

describeIf(['NoAction'].includes(onUpdate))('onUpdate: NoAction', () => {
// prisma - NoAction
testIf(isRelationMode_prisma)(
'relationMode=prisma - NoAction - [update] parent id with non-existing id should suceed',
async () => {
await prisma[userModel].update({
where: { id: '1' },
data: {
id: '3',
},
})

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '2',
enabled: null,
},
{
id: '3',
enabled: null,
},
])
},
)

// prisma - NoAction
testIf(isRelationMode_prisma)(
'relationMode=prisma - NoAction - [updateMany] parent id with non-existing id should succeed',
async () => {
await prisma[userModel].updateMany({
where: { id: '1' },
data: {
id: '3',
},
})

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '2',
enabled: null,
},
{
id: '3',
enabled: null,
},
])
},
)

test('[updateMany] parent id with existing id should throw', async () => {
await expect(
prisma[userModel].updateMany({
Expand All @@ -676,14 +620,8 @@ testMatrix.setupTestSuite(
[Providers.SQLSERVER]: 'Unique constraint failed on the constraint: `dbo.UserOneToOne`',
[Providers.SQLITE]: 'Unique constraint failed on the fields: (`id`)',
},
prisma: {
[Providers.POSTGRESQL]: 'Unique constraint failed on the fields: (`id`)',
[Providers.COCKROACHDB]: 'Unique constraint failed on the fields: (`id`)',
// relationMode.tests_1-to-1 (provider=mysql, id=String @id, relationMode=prisma, referentialActions={onUpdateNoAction,onDeleteNoAction}) › 1:1 mandatory (explicit) › [update] › mutate id › onUpdate: NoAction › [updateMany] parent id with existing id should throw
[Providers.MYSQL]: 'Unique constraint failed on the constraint: `PRIMARY`',
[Providers.SQLSERVER]: 'Unique constraint failed on the constraint: `dbo.UserOneToOne`',
[Providers.SQLITE]: 'Unique constraint failed on the fields: (`id`)',
},
prisma:
"The change you are trying to make would violate the required relation 'ProfileOneToOneToUserOneToOne' between the `ProfileOneToOne` and `UserOneToOne` models",
}),
)

Expand Down Expand Up @@ -730,13 +668,13 @@ testMatrix.setupTestSuite(
'Foreign key constraint failed on the field: `userId`'
: // DEFAULT
/*
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError {
code: 1761,
message: \"Foreign key constraint for table 'UserOneToOne', record '2' would lead to a duplicate entry in table 'ProfileOneToOne',
key 'ProfileOneToOne_userId_key'\",
state: \"23000\" })) })
*/
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError {
code: 1761,
message: \"Foreign key constraint for table 'UserOneToOne', record '2' would lead to a duplicate entry in table 'ProfileOneToOne',
key 'ProfileOneToOne_userId_key'\",
state: \"23000\" })) })
*/
// Note: in CI we run with --lower_case_table_names=1
`Foreign key constraint for table 'useronetoone', record '2' would lead to a duplicate entry in table 'profileonetoone'`,
[Providers.SQLSERVER]: 'Unique constraint failed on the constraint: `dbo.UserOneToOne`',
Expand Down Expand Up @@ -862,13 +800,13 @@ testMatrix.setupTestSuite(
'Foreign key constraint failed on the field: `userId`'
: // DEFAULT
/*
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError {
code: 1761,
message: \"Foreign key constraint for table 'UserOneToOne', record '2' would lead to a duplicate entry in table 'ProfileOneToOne',
key 'ProfileOneToOne_userId_key'\",
state: \"23000\" })) })"
*/
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError {
code: 1761,
message: \"Foreign key constraint for table 'UserOneToOne', record '2' would lead to a duplicate entry in table 'ProfileOneToOne',
key 'ProfileOneToOne_userId_key'\",
state: \"23000\" })) })"
*/
// Note: in CI we run with --lower_case_table_names=1
`Foreign key constraint for table 'useronetoone', record '2' would lead to a duplicate entry in table 'profileonetoone'`,
[Providers.SQLSERVER]: 'Unique constraint failed on the constraint: `dbo.UserOneToOne`',
Expand Down Expand Up @@ -1159,9 +1097,11 @@ testMatrix.setupTestSuite(
'Foreign key constraint failed on the field: `ProfileOneToOne_userId_fkey (index)`',
[Providers.SQLITE]: 'Foreign key constraint failed on the field: `foreign key`',
},
prisma:
"The change you are trying to make would violate the required relation 'ProfileOneToOneToUserOneToOne' between the `ProfileOneToOne` and `UserOneToOne` models",
})
// foreignKeys
testIf(isRelationMode_foreignKeys)('relationMode=foreignKeys - [delete] parent should throw', async () => {

test('[delete] parent should throw', async () => {
await expect(
prisma[userModel].delete({
where: { id: '1' },
Expand All @@ -1183,52 +1123,24 @@ testMatrix.setupTestSuite(
},
])
})
testIf(isRelationMode_foreignKeys)(
'relationMode=foreignKeys - [deleteMany] parents should throw',
async () => {
await expect(prisma[userModel].deleteMany()).rejects.toThrowError(expectedError)

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '1',
enabled: null,
},
{
id: '2',
enabled: null,
},
])
},
)

// prisma
testIf(isRelationMode_prisma)('relationMode=prisma - [delete] parent should succeed', async () => {
await prisma[userModel].delete({
where: { id: '1' },
}),
expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '2',
enabled: null,
},
])
})
testIf(isRelationMode_prisma)('relationMode=prisma - [deleteMany] parents should succeed', async () => {
await prisma[userModel].deleteMany()
test('[deleteMany] parents should throw', async () => {
await expect(prisma[userModel].deleteMany()).rejects.toThrowError(expectedError)

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([])
).toEqual([
{
id: '1',
enabled: null,
},
{
id: '2',
enabled: null,
},
])
})
})

Expand Down
140 changes: 34 additions & 106 deletions packages/client/tests/functional/relationMode/tests_1-to-n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,8 @@ testMatrix.setupTestSuite(
[Providers.SQLSERVER]: 'Unique constraint failed on the constraint: `dbo.UserOneToMany`',
[Providers.SQLITE]: 'Unique constraint failed on the fields: (`id`)',
},
prisma: {
[Providers.POSTGRESQL]: 'Unique constraint failed on the fields: (`id`)',
[Providers.COCKROACHDB]: 'Unique constraint failed on the fields: (`id`)',
[Providers.MYSQL]: 'Unique constraint failed on the constraint: `PRIMARY`',
[Providers.SQLSERVER]: 'Unique constraint failed on the constraint: `dbo.UserOneToMany`',
[Providers.SQLITE]: 'Unique constraint failed on the fields: (`id`)',
},
prisma:
"The change you are trying to make would violate the required relation 'PostOneToManyToUserOneToMany' between the `PostOneToMany` and `UserOneToMany` models.",
}),
)

Expand Down Expand Up @@ -856,11 +851,7 @@ testMatrix.setupTestSuite(
"The change you are trying to make would violate the required relation 'PostOneToManyToUserOneToMany' between the `PostOneToMany` and `UserOneToMany` models.",
})

// foreignKeys
testIf(isRelationMode_foreignKeys)('relationMode=foreignKeys - [delete] parent should throw', async () => {
// this throws because "postModel" has a mandatory relation with "userModel", hence
// we have a "onDelete: Restrict" situation by default

test('[delete] parent should throw', async () => {
await expect(
prisma[userModel].delete({
where: { id: '1' },
Expand All @@ -882,114 +873,51 @@ testMatrix.setupTestSuite(
},
])
})
testIf(isRelationMode_foreignKeys)(
'relationMode=foreignKeys - [deleteMany] parents should throw',
async () => {
await prisma[postModel].delete({
where: { id: '1-post-a' },
})

expect(
await prisma[postModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '1-post-b',
authorId: '1',
},
{
id: '2-post-a',
authorId: '2',
},
{
id: '2-post-b',
authorId: '2',
},
])

await expect(
prisma[userModel].delete({
where: { id: '1' },
}),
).rejects.toThrowError(expectedError)
test('[deleteMany] parents should throw', async () => {
await prisma[postModel].delete({
where: { id: '1-post-a' },
})

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '1',
enabled: null,
},
{
id: '2',
enabled: null,
},
])
},
)
expect(
await prisma[postModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '1-post-b',
authorId: '1',
},
{
id: '2-post-a',
authorId: '2',
},
{
id: '2-post-b',
authorId: '2',
},
])

// prisma
testIf(isRelationMode_prisma)('relationMode=prisma - [delete] parent should succeed', async () => {
await prisma[userModel].delete({
where: { id: '1' },
})
await expect(
prisma[userModel].delete({
where: { id: '1' },
}),
).rejects.toThrowError(expectedError)

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '1',
enabled: null,
},
{
id: '2',
enabled: null,
},
])
})
testIf(isRelationMode_prisma)(
'relationMode=prisma - a subset of children and then [delete] parent should succeed',
async () => {
await prisma[postModel].delete({
where: { id: '1-post-a' },
})

expect(
await prisma[postModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '1-post-b',
authorId: '1',
},
{
id: '2-post-a',
authorId: '2',
},
{
id: '2-post-b',
authorId: '2',
},
])

await prisma[userModel].delete({
where: { id: '1' },
})

expect(
await prisma[userModel].findMany({
orderBy: { id: 'asc' },
}),
).toEqual([
{
id: '2',
enabled: null,
},
])
},
)

// Only test for foreignKeys
testIf(isRelationMode_foreignKeys && (isPostgreSQL || isSQLite))(
Expand Down

0 comments on commit ebee8a7

Please sign in to comment.