From 8bbead4b00f5541ee070c8f3f7f7d0b1e221b843 Mon Sep 17 00:00:00 2001 From: Daniel Starns Date: Fri, 23 Sep 2022 19:27:11 +0200 Subject: [PATCH] test(client): Regression test for gh-13089 (#15435) --- .../tests/functional/issues/13089/_matrix.ts | 9 +++ .../functional/issues/13089/prisma/_schema.ts | 19 ++++++ .../tests/functional/issues/13089/tests.ts | 65 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 packages/client/tests/functional/issues/13089/_matrix.ts create mode 100644 packages/client/tests/functional/issues/13089/prisma/_schema.ts create mode 100644 packages/client/tests/functional/issues/13089/tests.ts diff --git a/packages/client/tests/functional/issues/13089/_matrix.ts b/packages/client/tests/functional/issues/13089/_matrix.ts new file mode 100644 index 000000000000..6ce62561f786 --- /dev/null +++ b/packages/client/tests/functional/issues/13089/_matrix.ts @@ -0,0 +1,9 @@ +import { defineMatrix } from '../../_utils/defineMatrix' + +export default defineMatrix(() => [ + [ + { + provider: 'mongodb', + }, + ], +]) diff --git a/packages/client/tests/functional/issues/13089/prisma/_schema.ts b/packages/client/tests/functional/issues/13089/prisma/_schema.ts new file mode 100644 index 000000000000..12a6fde7caa2 --- /dev/null +++ b/packages/client/tests/functional/issues/13089/prisma/_schema.ts @@ -0,0 +1,19 @@ +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 users { + id String @id @map("_id") @default(auto()) @db.ObjectId + firstName String @unique + } + ` +}) diff --git a/packages/client/tests/functional/issues/13089/tests.ts b/packages/client/tests/functional/issues/13089/tests.ts new file mode 100644 index 000000000000..d4622b9f1fc6 --- /dev/null +++ b/packages/client/tests/functional/issues/13089/tests.ts @@ -0,0 +1,65 @@ +import testMatrix from './_matrix' +// @ts-ignore +import type { PrismaClient } from './node_modules/@prisma/client' + +declare let prisma: PrismaClient + +// https://github.com/prisma/prisma/issues/13089 +testMatrix.setupTestSuite( + () => { + beforeAll(async () => { + await prisma.users.create({ + data: { + firstName: 'foo', + }, + }) + + await prisma.users.create({ + data: { + firstName: '$foo', + }, + }) + }) + + test('should return records when using a `$` in the search string', async () => { + const records = await prisma.users.findMany({ + where: { + firstName: '$foo', + }, + }) + + expect(records).toHaveLength(1) + expect(records[0].firstName).toEqual('$foo') + }) + + test('should update records when using a `$` in the search string', async () => { + const record = await prisma.users.update({ + where: { + firstName: '$foo', + }, + data: { + firstName: '$$foo', + }, + select: { + firstName: true, + }, + }) + + expect(record.firstName).toEqual('$$foo') + }) + + test('should delete records when using a `$` in the search string', async () => { + await prisma.users.delete({ + where: { + firstName: '$$foo', + }, + }) + }) + }, + { + optOut: { + from: ['cockroachdb', 'mysql', 'postgresql', 'sqlite', 'sqlserver'], + reason: 'Only applicable to Mongodb', + }, + }, +)