Skip to content

Commit

Permalink
test(client): regression of #16196
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Nov 10, 2022
1 parent 3bb8243 commit 408c205
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 0 deletions.
@@ -0,0 +1,15 @@
import { defineMatrix } from '../../_utils/defineMatrix'

export default defineMatrix(() => [
[
{
provider: 'sqlite',
},
{
provider: 'postgresql',
},
{
provider: 'cockroachdb',
},
],
])
@@ -0,0 +1,36 @@
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 User {
id ${idForProvider(provider)}
email String @unique
posts Post[]
profile Profile?
}
model Post {
id ${idForProvider(provider)}
title String
user User @relation(fields: [userId], references: [id])
userId String
}
model Profile {
id ${idForProvider(provider)}
name String
user User @relation(fields: [userId], references: [id])
userId String @unique
}
`
})
@@ -0,0 +1,131 @@
import { randomBytes } from 'crypto'

import testMatrix from './_matrix'
// @ts-ignore
import type { PrismaClient } from './node_modules/@prisma/client'

declare let prisma: PrismaClient

const id = randomBytes(12).toString('hex')
testMatrix.setupTestSuite(
(suiteConfig, suiteMeta) => {
beforeAll(async () => {
await prisma.user.create({
data: {
id: id,
email: 'john@doe.io',
posts: {
create: [{ title: 'A' }, { title: 'B' }, { title: 'C' }],
},
},
})
})

test('upsert (update) with nested select many relation', async () => {
const data = await prisma.user.upsert({
where: { id },
create: {
email: 'john@doe.io',
},
update: {
email: 'johnny@doe.io',
},
select: {
posts: {
select: {
user: {
select: {
email: true,
},
},
},
},
},
})

expect(data).toMatchInlineSnapshot(`
Object {
posts: Array [
Object {
user: Object {
email: johnny@doe.io,
},
},
Object {
user: Object {
email: johnny@doe.io,
},
},
Object {
user: Object {
email: johnny@doe.io,
},
},
],
}
`)
})

test('upsert (update) with nested select one relation', async () => {
const data = await prisma.user.upsert({
where: { id },
create: {
email: 'john@doe.io',
},
update: {
email: 'johnny@doe.io',
},
select: {
profile: {
select: {
user: {
select: {
email: true,
},
},
},
},
},
})

expect(data).toMatchInlineSnapshot(`
Object {
profile: null,
}
`)
})

test('upsert (create) with nested select one relation', async () => {
const data = await prisma.user.upsert({
where: { id: randomBytes(12).toString('hex') },
create: {
email: 'jane@joe.io',
},
update: {
email: 'janette@doe.io',
},
select: {
email: true,
profile: {
select: {
id: true,
},
},
},
})

expect(data).toMatchInlineSnapshot(`
Object {
email: jane@joe.io,
profile: null,
}
`)
})
},
{
optOut: {
from: ['mysql', 'mongodb', 'sqlserver'],
reason: "We don't support native upserts for these",
},
},
)

0 comments on commit 408c205

Please sign in to comment.