-
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.
fix(client): include enums into scalar select lists (#16540)
Fix #16535
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
packages/client/tests/functional/issues/16535-select-enum/_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,15 @@ | ||
import { defineMatrix } from '../../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'postgresql', | ||
}, | ||
{ | ||
provider: 'mysql', | ||
}, | ||
{ | ||
provider: 'cockroachdb', | ||
}, | ||
], | ||
]) |
26 changes: 26 additions & 0 deletions
26
packages/client/tests/functional/issues/16535-select-enum/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,26 @@ | ||
import { idForProvider } from '../../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["clientExtensions"] | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model User { | ||
id ${idForProvider(provider)} | ||
role UserRole | ||
} | ||
enum UserRole { | ||
ADMIN | ||
USER | ||
} | ||
` | ||
}) |
29 changes: 29 additions & 0 deletions
29
packages/client/tests/functional/issues/16535-select-enum/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,29 @@ | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { Prisma as PrismaNamespace, PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
declare let Prisma: typeof PrismaNamespace | ||
|
||
testMatrix.setupTestSuite( | ||
() => { | ||
test('allows to select enum field', async () => { | ||
const user = await prisma.user.create({ | ||
data: { | ||
role: 'ADMIN', | ||
}, | ||
select: { | ||
role: true, | ||
}, | ||
}) | ||
|
||
expect(user).toEqual({ role: 'ADMIN' }) | ||
}) | ||
}, | ||
{ | ||
optOut: { | ||
from: ['sqlite', 'mongodb', 'sqlserver'], | ||
reason: 'No support for enums', | ||
}, | ||
}, | ||
) |