-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
packages/client/tests/functional/issues/14001-mongo-order-by-conflict/_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,9 @@ | ||
import { defineMatrix } from '../../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'mongodb', | ||
}, | ||
], | ||
]) |
20 changes: 20 additions & 0 deletions
20
packages/client/tests/functional/issues/14001-mongo-order-by-conflict/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,20 @@ | ||
import { idForProvider } from '../../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model Resource { | ||
id ${idForProvider(provider)} | ||
OrderBy Int @unique() | ||
} | ||
` | ||
}) |
69 changes: 69 additions & 0 deletions
69
packages/client/tests/functional/issues/14001-mongo-order-by-conflict/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,69 @@ | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
/** | ||
* Regression test for #14001 | ||
* Invalid character in mongo query | ||
*/ | ||
testMatrix.setupTestSuite( | ||
() => { | ||
test('findFirst', async () => { | ||
const result = prisma.resource.findFirst({ | ||
where: { OrderBy: { gt: 0 } }, | ||
orderBy: { OrderBy: 'asc' }, | ||
cursor: { OrderBy: 1 }, | ||
distinct: ['OrderBy'], | ||
}) | ||
|
||
await expect(result).resolves.toMatchInlineSnapshot(`null`) | ||
}) | ||
|
||
test('findMany', async () => { | ||
const result = prisma.resource.findMany({ | ||
where: { OrderBy: { gt: 0 } }, | ||
orderBy: { OrderBy: 'asc' }, | ||
cursor: { OrderBy: 1 }, | ||
distinct: ['OrderBy'], | ||
}) | ||
|
||
await expect(result).resolves.toMatchInlineSnapshot(`Array []`) | ||
}) | ||
|
||
test('aggregate', async () => { | ||
const result = prisma.resource.aggregate({ | ||
where: { OrderBy: { gt: 0 } }, | ||
_count: true, | ||
orderBy: { OrderBy: 'asc' }, | ||
cursor: { OrderBy: 1 }, | ||
}) | ||
|
||
await expect(result).resolves.toMatchInlineSnapshot(` | ||
Object { | ||
_count: 0, | ||
} | ||
`) | ||
}) | ||
|
||
test('groupBy', async () => { | ||
const result = prisma.resource.groupBy({ | ||
where: { OrderBy: { gt: 0 } }, | ||
by: ['OrderBy'], | ||
orderBy: { OrderBy: 'asc' }, | ||
having: { | ||
OrderBy: 1, | ||
}, | ||
}) | ||
|
||
await expect(result).resolves.toMatchInlineSnapshot(`Array []`) | ||
}) | ||
}, | ||
{ | ||
optOut: { | ||
from: ['cockroachdb', 'mysql', 'postgresql', 'sqlite', 'sqlserver'], | ||
reason: 'Only a test for mongodb', | ||
}, | ||
}, | ||
) |