-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(client): Test default selection contents
Should help to prevent issues like #18148
- Loading branch information
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/client/tests/functional/default-selection/_matrix.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,24 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'sqlite', | ||
}, | ||
{ | ||
provider: 'postgresql', | ||
}, | ||
{ | ||
provider: 'mysql', | ||
}, | ||
{ | ||
provider: 'mongodb', | ||
}, | ||
{ | ||
provider: 'cockroachdb', | ||
}, | ||
{ | ||
provider: 'sqlserver', | ||
}, | ||
], | ||
]) |
57 changes: 57 additions & 0 deletions
57
packages/client/tests/functional/default-selection/prisma/_schema.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,57 @@ | ||
import { foreignKeyForProvider, idForProvider } from '../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
const fields: string[] = [] | ||
const declarations: string[] = [] | ||
|
||
if (provider === 'postgresql' || provider === 'cockroachdb' || provider === 'mongodb') { | ||
fields.push('list String[]') | ||
} | ||
|
||
if (provider !== 'sqlite' && provider !== 'sqlserver') { | ||
declarations.push(/* Prisma */ ` | ||
enum Enum { | ||
A | ||
B | ||
}`) | ||
|
||
fields.push('enum Enum') | ||
} | ||
|
||
if (provider === 'mongodb') { | ||
declarations.push(/* Prisma */ ` | ||
type Composite { | ||
value String | ||
} | ||
`) | ||
fields.push('composite Composite') | ||
} | ||
|
||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model Model { | ||
id ${idForProvider(provider)} | ||
value String | ||
otherId ${foreignKeyForProvider(provider)} @unique | ||
relation Other @relation(fields: [otherId], references: [id]) | ||
${fields.join('\n')} | ||
} | ||
model Other { | ||
id ${idForProvider(provider)} | ||
model Model? | ||
} | ||
${declarations.join('\n')} | ||
` | ||
}) |
74 changes: 74 additions & 0 deletions
74
packages/client/tests/functional/default-selection/tests.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,74 @@ | ||
import { expectTypeOf } from 'expect-type' | ||
|
||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { Prisma as PrismaNamespace, PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
testMatrix.setupTestSuite(({ provider }) => { | ||
beforeAll(async () => { | ||
const input: Partial<PrismaNamespace.ModelCreateInput> = { | ||
value: 'Foo', | ||
relation: { | ||
create: {}, | ||
}, | ||
} | ||
|
||
if (provider !== 'sqlite' && provider !== 'sqlserver') { | ||
// @ts-test-if: provider !== 'sqlite' && provider !== 'sqlserver' | ||
input.enum = 'A' | ||
} | ||
|
||
if (provider === 'postgresql' || provider === 'cockroachdb' || provider === 'mongodb') { | ||
// @ts-test-if: provider === 'postgresql' || provider === 'cockroachdb' || provider === 'mongodb' | ||
input.list = ['Hello', 'world'] | ||
} | ||
|
||
if (provider === 'mongodb') { | ||
// @ts-test-if: provider === 'mongodb' | ||
input.composite = { value: 'I am composite' } | ||
} | ||
|
||
await prisma.model.create({ data: input as PrismaNamespace.ModelCreateInput }) | ||
}) | ||
|
||
test('includes scalars', async () => { | ||
const model = await prisma.model.findFirstOrThrow() | ||
|
||
expect(model.id).toBeDefined() | ||
expect(model.value).toBeDefined() | ||
expect(model.otherId).toBeDefined() | ||
}) | ||
|
||
test('does not include relations', async () => { | ||
const model = await prisma.model.findFirstOrThrow() | ||
|
||
expectTypeOf(model).not.toHaveProperty('relation') | ||
expect(model).not.toHaveProperty('relation') | ||
}) | ||
|
||
testIf(provider !== 'sqlite' && provider !== 'sqlserver')('includes enums', async () => { | ||
const model = await prisma.model.findFirstOrThrow() | ||
|
||
// @ts-test-if: provider !== 'sqlite' && provider !== 'sqlserver' | ||
expect(model.enum).toBeDefined() | ||
}) | ||
|
||
testIf(provider === 'postgresql' || provider === 'cockroachdb' || provider === 'mongodb')( | ||
'includes lists', | ||
async () => { | ||
const model = await prisma.model.findFirstOrThrow() | ||
|
||
// @ts-test-if: provider === 'postgresql' || provider === 'cockroachdb' || provider === 'mongodb' | ||
expect(model.list).toBeDefined() | ||
}, | ||
) | ||
|
||
testIf(provider === 'mongodb')('includes composites', async () => { | ||
const model = await prisma.model.findFirstOrThrow() | ||
|
||
// @ts-test-if: provider === 'mongodb' | ||
expect(model.composite).toBeDefined() | ||
}) | ||
}) |