From d224d04535621da1d4c7c7463a666b1d8ea4dc1d Mon Sep 17 00:00:00 2001 From: daniel starns Date: Wed, 21 Sep 2022 11:41:39 +0100 Subject: [PATCH 1/3] test: add regression for gh-13089 --- .../tests/functional/issues/13089/_matrix.ts | 9 +++++ .../functional/issues/13089/prisma/_schema.ts | 19 +++++++++ .../tests/functional/issues/13089/tests.ts | 39 +++++++++++++++++++ 3 files changed, 67 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..44257e9bad5d --- /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 + } + ` +}) 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..e1eb50f653b7 --- /dev/null +++ b/packages/client/tests/functional/issues/13089/tests.ts @@ -0,0 +1,39 @@ +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( + () => { + test('should return records when using a `$` in the search string', async () => { + await prisma.users.create({ + data: { + firstName: 'foo', + }, + }) + + await prisma.users.create({ + data: { + firstName: '$foo', + }, + }) + + const records = await prisma.users.findMany({ + where: { + firstName: '$foo', + }, + }) + + expect(records).toHaveLength(1) + expect(records[0].firstName).toEqual('$foo') + }) + }, + { + optOut: { + from: ['cockroachdb', 'mysql', 'postgresql', 'sqlite', 'sqlserver'], + reason: 'Only applicable to Mongodb', + }, + }, +) From c9252f5bb2b014165184728a98be29768cd2a638 Mon Sep 17 00:00:00 2001 From: daniel starns Date: Thu, 22 Sep 2022 15:48:56 +0100 Subject: [PATCH 2/3] test: add more operations --- .../functional/issues/13089/prisma/_schema.ts | 2 +- .../tests/functional/issues/13089/tests.ts | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/client/tests/functional/issues/13089/prisma/_schema.ts b/packages/client/tests/functional/issues/13089/prisma/_schema.ts index 44257e9bad5d..12a6fde7caa2 100644 --- a/packages/client/tests/functional/issues/13089/prisma/_schema.ts +++ b/packages/client/tests/functional/issues/13089/prisma/_schema.ts @@ -13,7 +13,7 @@ export default testMatrix.setupSchema(({ provider }) => { model users { id String @id @map("_id") @default(auto()) @db.ObjectId - firstName String + firstName String @unique } ` }) diff --git a/packages/client/tests/functional/issues/13089/tests.ts b/packages/client/tests/functional/issues/13089/tests.ts index e1eb50f653b7..84832557d11b 100644 --- a/packages/client/tests/functional/issues/13089/tests.ts +++ b/packages/client/tests/functional/issues/13089/tests.ts @@ -7,7 +7,7 @@ declare let prisma: PrismaClient // https://github.com/prisma/prisma/issues/13089 testMatrix.setupTestSuite( () => { - test('should return records when using a `$` in the search string', async () => { + beforeAll(async () => { await prisma.users.create({ data: { firstName: 'foo', @@ -19,7 +19,9 @@ testMatrix.setupTestSuite( firstName: '$foo', }, }) + }) + test('should return records when using a `$` in the search string', async () => { const records = await prisma.users.findMany({ where: { firstName: '$foo', @@ -29,6 +31,31 @@ testMatrix.setupTestSuite( expect(records).toHaveLength(1) expect(records[0].firstName).toEqual('$foo') }) + + test('should update records when using a `$` in the search string', async () => { + const records = await prisma.users.update({ + where: { + firstName: '$foo', + }, + data: { + firstName: '$$foo', + }, + select: { + firstName: true, + }, + }) + + expect(records).toHaveLength(1) + expect(records[0].firstName).toEqual('$$foo') + }) + + test('should delete records when using a `$` in the search string', async () => { + await prisma.users.delete({ + where: { + firstName: '$$foo', + }, + }) + }) }, { optOut: { From f05a6a882047ed64e03ce7e0ae3f67024d0ff206 Mon Sep 17 00:00:00 2001 From: daniel starns Date: Thu, 22 Sep 2022 16:36:14 +0100 Subject: [PATCH 3/3] test: * --- packages/client/tests/functional/issues/13089/tests.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/client/tests/functional/issues/13089/tests.ts b/packages/client/tests/functional/issues/13089/tests.ts index 84832557d11b..d4622b9f1fc6 100644 --- a/packages/client/tests/functional/issues/13089/tests.ts +++ b/packages/client/tests/functional/issues/13089/tests.ts @@ -33,7 +33,7 @@ testMatrix.setupTestSuite( }) test('should update records when using a `$` in the search string', async () => { - const records = await prisma.users.update({ + const record = await prisma.users.update({ where: { firstName: '$foo', }, @@ -45,8 +45,7 @@ testMatrix.setupTestSuite( }, }) - expect(records).toHaveLength(1) - expect(records[0].firstName).toEqual('$$foo') + expect(record.firstName).toEqual('$$foo') }) test('should delete records when using a `$` in the search string', async () => {