Skip to content

Commit

Permalink
test(client): mongo query conflict #14001 (#15327)
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Sep 22, 2022
1 parent 650e6a4 commit f0a6d89
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineMatrix } from '../../_utils/defineMatrix'

export default defineMatrix(() => [
[
{
provider: 'mongodb',
},
],
])
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()
}
`
})
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',
},
},
)

0 comments on commit f0a6d89

Please sign in to comment.