Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: simple test for referentialAction cascade with and without flag (…
- Loading branch information
Showing
18 changed files
with
851 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ages/client/src/__tests__/integration/errors/default-onDelete-cascade-mysql/schema.prisma
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,34 @@ | ||
datasource db { | ||
provider = "mysql" | ||
url = env("TEST_MYSQL_URI") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
author User @relation(fields: [authorId], references: [id]) | ||
authorId Int | ||
} | ||
|
||
model Profile { | ||
id Int @id @default(autoincrement()) | ||
bio String? | ||
user User @relation(fields: [userId], references: [id]) | ||
userId Int @unique | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
profile Profile? | ||
} |
76 changes: 76 additions & 0 deletions
76
src/packages/client/src/__tests__/integration/errors/default-onDelete-cascade-mysql/test.ts
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,76 @@ | ||
import path from 'path' | ||
import { generateTestClient } from '../../../../utils/getTestClient' | ||
import { tearDownMysql } from '../../../../utils/setupMysql' | ||
import { migrateDb } from '../../__helpers__/migrateDb' | ||
|
||
let prisma | ||
const baseUri = process.env.TEST_MYSQL_URI | ||
|
||
describe('default-onDelete-cascade(mysql)', () => { | ||
beforeAll(async () => { | ||
process.env.TEST_MYSQL_URI += '-default-onDelete-Cascade' | ||
await tearDownMysql(process.env.TEST_MYSQL_URI!) | ||
await migrateDb({ | ||
connectionString: process.env.TEST_MYSQL_URI!, | ||
schemaPath: path.join(__dirname, 'schema.prisma'), | ||
}) | ||
await generateTestClient() | ||
const { PrismaClient } = require('./node_modules/@prisma/client') | ||
prisma = new PrismaClient() | ||
}) | ||
|
||
afterAll(async () => { | ||
await prisma.post.deleteMany() | ||
await prisma.profile.deleteMany() | ||
await prisma.user.deleteMany() | ||
await prisma.$disconnect() | ||
process.env.TEST_MYSQL_URI = baseUri | ||
}) | ||
|
||
test('delete 1 user, should error', async () => { | ||
await prisma.user.create({ | ||
data: { | ||
name: 'Bob', | ||
email: 'bob@prisma.io', | ||
posts: { | ||
create: { title: 'Hello Earth' }, | ||
}, | ||
profile: { | ||
create: { bio: 'I like pinguins' }, | ||
}, | ||
}, | ||
}) | ||
|
||
expect(await prisma.user.findMany()).toHaveLength(1) | ||
|
||
try { | ||
await prisma.user.delete({ | ||
where: { | ||
email: 'bob@prisma.io', | ||
}, | ||
}) | ||
} catch (e) { | ||
if (process.env.PRISMA_FORCE_NAPI) { | ||
expect(e.message).toMatchInlineSnapshot(` | ||
Invalid \`prisma.user.delete()\` invocation in | ||
/client/src/__tests__/integration/errors/default-onDelete-cascade-mysql/test.ts:47:31 | ||
44 expect(await prisma.user.findMany()).toHaveLength(1) | ||
45 | ||
46 try { | ||
→ 47 await prisma.user.delete( | ||
The change you are trying to make would violate the required relation 'PostToUser' between the \`Post\` and \`User\` models. | ||
`) | ||
} else { | ||
expect(e.message).toMatchInlineSnapshot(` | ||
Invalid \`prisma.user.delete()\` invocation: | ||
The change you are trying to make would violate the required relation 'PostToUser' between the \`Post\` and \`User\` models. | ||
`) | ||
} | ||
} | ||
}) | ||
}) |
34 changes: 34 additions & 0 deletions
34
...s/client/src/__tests__/integration/errors/default-onDelete-cascade-postgres/schema.prisma
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,34 @@ | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("TEST_POSTGRES_URI") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
author User @relation(fields: [authorId], references: [id]) | ||
authorId Int | ||
} | ||
|
||
model Profile { | ||
id Int @id @default(autoincrement()) | ||
bio String? | ||
user User @relation(fields: [userId], references: [id]) | ||
userId Int @unique | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
profile Profile? | ||
} |
76 changes: 76 additions & 0 deletions
76
...ackages/client/src/__tests__/integration/errors/default-onDelete-cascade-postgres/test.ts
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,76 @@ | ||
import path from 'path' | ||
import { generateTestClient } from '../../../../utils/getTestClient' | ||
import { tearDownPostgres } from '../../../../utils/setupPostgres' | ||
import { migrateDb } from '../../__helpers__/migrateDb' | ||
|
||
let prisma | ||
const baseUri = process.env.TEST_POSTGRES_URI | ||
|
||
describe('default-onDelete-cascade(postgresql)', () => { | ||
beforeAll(async () => { | ||
process.env.TEST_POSTGRES_URI += '-default-onDelete-Cascade' | ||
await tearDownPostgres(process.env.TEST_POSTGRES_URI!) | ||
await migrateDb({ | ||
connectionString: process.env.TEST_POSTGRES_URI!, | ||
schemaPath: path.join(__dirname, 'schema.prisma'), | ||
}) | ||
await generateTestClient() | ||
const { PrismaClient } = require('./node_modules/@prisma/client') | ||
prisma = new PrismaClient() | ||
}) | ||
|
||
afterAll(async () => { | ||
await prisma.post.deleteMany() | ||
await prisma.profile.deleteMany() | ||
await prisma.user.deleteMany() | ||
await prisma.$disconnect() | ||
process.env.TEST_POSTGRES_URI = baseUri | ||
}) | ||
|
||
test('delete 1 user, should error', async () => { | ||
await prisma.user.create({ | ||
data: { | ||
name: 'Bob', | ||
email: 'bob@prisma.io', | ||
posts: { | ||
create: { title: 'Hello Earth' }, | ||
}, | ||
profile: { | ||
create: { bio: 'I like pinguins' }, | ||
}, | ||
}, | ||
}) | ||
|
||
expect(await prisma.user.findMany()).toHaveLength(1) | ||
|
||
try { | ||
await prisma.user.delete({ | ||
where: { | ||
email: 'bob@prisma.io', | ||
}, | ||
}) | ||
} catch (e) { | ||
if (process.env.PRISMA_FORCE_NAPI) { | ||
expect(e.message).toMatchInlineSnapshot(` | ||
Invalid \`prisma.user.delete()\` invocation in | ||
/client/src/__tests__/integration/errors/default-onDelete-cascade-postgres/test.ts:47:31 | ||
44 expect(await prisma.user.findMany()).toHaveLength(1) | ||
45 | ||
46 try { | ||
→ 47 await prisma.user.delete( | ||
The change you are trying to make would violate the required relation 'PostToUser' between the \`Post\` and \`User\` models. | ||
`) | ||
} else { | ||
expect(e.message).toMatchInlineSnapshot(` | ||
Invalid \`prisma.user.delete()\` invocation: | ||
The change you are trying to make would violate the required relation 'PostToUser' between the \`Post\` and \`User\` models. | ||
`) | ||
} | ||
} | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
...ckages/client/src/__tests__/integration/errors/default-onDelete-cascade-sqlite/.gitignore
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 @@ | ||
*.db |
34 changes: 34 additions & 0 deletions
34
...ges/client/src/__tests__/integration/errors/default-onDelete-cascade-sqlite/schema.prisma
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,34 @@ | ||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./dev.db" | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
author User @relation(fields: [authorId], references: [id]) | ||
authorId Int | ||
} | ||
|
||
model Profile { | ||
id Int @id @default(autoincrement()) | ||
bio String? | ||
user User @relation(fields: [userId], references: [id]) | ||
userId Int @unique | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
profile Profile? | ||
} |
70 changes: 70 additions & 0 deletions
70
src/packages/client/src/__tests__/integration/errors/default-onDelete-cascade-sqlite/test.ts
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,70 @@ | ||
import path from 'path' | ||
import { generateTestClient } from '../../../../utils/getTestClient' | ||
import { migrateDb } from '../../__helpers__/migrateDb' | ||
|
||
let prisma | ||
describe('default-onDelete-cascade(sqlite)', () => { | ||
beforeAll(async () => { | ||
await migrateDb({ | ||
connectionString: `file:./dev.db`, | ||
schemaPath: path.join(__dirname, 'schema.prisma'), | ||
}) | ||
await generateTestClient() | ||
const { PrismaClient } = require('./node_modules/@prisma/client') | ||
prisma = new PrismaClient() | ||
}) | ||
|
||
afterAll(async () => { | ||
await prisma.post.deleteMany() | ||
await prisma.profile.deleteMany() | ||
await prisma.user.deleteMany() | ||
await prisma.$disconnect() | ||
}) | ||
|
||
test('delete 1 user, should error', async () => { | ||
await prisma.user.create({ | ||
data: { | ||
name: 'Bob', | ||
email: 'bob@prisma.io', | ||
posts: { | ||
create: { title: 'Hello Earth' }, | ||
}, | ||
profile: { | ||
create: { bio: 'I like pinguins' }, | ||
}, | ||
}, | ||
}) | ||
|
||
expect(await prisma.user.findMany()).toHaveLength(1) | ||
|
||
try { | ||
await prisma.user.delete({ | ||
where: { | ||
email: 'bob@prisma.io', | ||
}, | ||
}) | ||
} catch (e) { | ||
if (process.env.PRISMA_FORCE_NAPI) { | ||
expect(e.message).toMatchInlineSnapshot(` | ||
Invalid \`prisma.user.delete()\` invocation in | ||
/client/src/__tests__/integration/errors/default-onDelete-cascade-sqlite/test.ts:41:31 | ||
38 expect(await prisma.user.findMany()).toHaveLength(1) | ||
39 | ||
40 try { | ||
→ 41 await prisma.user.delete( | ||
The change you are trying to make would violate the required relation 'PostToUser' between the \`Post\` and \`User\` models. | ||
`) | ||
} else { | ||
expect(e.message).toMatchInlineSnapshot(` | ||
Invalid \`prisma.user.delete()\` invocation: | ||
The change you are trying to make would violate the required relation 'PostToUser' between the \`Post\` and \`User\` models. | ||
`) | ||
} | ||
} | ||
}) | ||
}) |
41 changes: 41 additions & 0 deletions
41
.../client/src/__tests__/integration/errors/default-onDelete-cascade-sqlserver/schema.prisma
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,41 @@ | ||
datasource my_db { | ||
provider = "sqlserver" | ||
url = env("TEST_MSSQL_JDBC_URI") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["microsoftSqlServer"] | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
author User @relation(fields: [authorId], references: [id]) | ||
authorId Int | ||
@@map("PostDefaultOnDelete") | ||
} | ||
|
||
model Profile { | ||
id Int @id @default(autoincrement()) | ||
bio String? | ||
user User @relation(fields: [userId], references: [id]) | ||
userId Int @unique | ||
@@map("ProfileDefaultOnDelete") | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
profile Profile? | ||
@@map("UserDefaultOnDelete") | ||
} |
Oops, something went wrong.