Skip to content

Commit

Permalink
chore: add more type tests (#4805)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Dec 28, 2020
1 parent 01b10f0 commit e1cb56a
Show file tree
Hide file tree
Showing 38 changed files with 813 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/packages/client/jest.config.js
Expand Up @@ -23,6 +23,6 @@ module.exports = {
],
collectCoverageFrom: ['src/**/*.ts', '!**/__tests__/**/*'],
snapshotSerializers: ['./helpers/jestSnapshotSerializer'],
testTimeout: 30000,
testTimeout: 70000,
setupFiles: ['./helpers/jestSetup.js'],
}
@@ -0,0 +1 @@
export { PrismaClient } from '@prisma/client'
40 changes: 40 additions & 0 deletions src/packages/client/src/__tests__/types/accounts/index.test-d.ts
@@ -0,0 +1,40 @@
import { PrismaClient } from '.'
import { expectError } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectError(
await prisma.userTest.findUnique({
where: {
id: 'Example',
},
select: {
id: true,
globalConfiguration: {
select: {
accounts: {
select: {
config: {
select: {
list: true,
data: false,
asd: true,
},
},
},
},
},
},
},
}),
)
})()
@@ -0,0 +1 @@
export { PrismaClient } from '@prisma/client'
90 changes: 90 additions & 0 deletions src/packages/client/src/__tests__/types/aggregate/index.test-d.ts
@@ -0,0 +1,90 @@
import { PrismaClient } from '.'
import { expectError } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectError(
await prisma.user.aggregate({
cursor: {
email: 'a@a.de',
},
orderBy: {
age: 'asc',
},
skip: 12,
take: 10,
where: {
age: { gt: 500, lt: '' },
},
count: true,
avg: {
age: true,
followerCount: true,
},
max: {
age: true,
followerCount: true,
},
min: {
age: true,
followerCount: true,
},
sum: {
age: true,
followerCount: true,
},
}),
)

expectError(
await prisma.user.aggregate({
cursor: {
email: 'a@a.de',
},
orderBy: {
age: 'asc',
},
skip: 12,
take: 10,
where: {
AND: [
{
age: { gt: 500, lt: '' },
},
],
OR: [
{
age: { gt: 500 },
},
],
},
count: true,
avg: {
age: true,
followerCount: true,
},
max: {
age: true,
followerCount: true,
},
min: {
followerCount: true,
},
sum: {
age: true,
followerCount: true,
},
someField: {}, // TODO: fix types
someRandomField: {}, // TODO: fix types
}),
)
})()
1 change: 1 addition & 0 deletions src/packages/client/src/__tests__/types/blog/index.d.ts
@@ -0,0 +1 @@
export { PrismaClient } from '@prisma/client'
28 changes: 28 additions & 0 deletions src/packages/client/src/__tests__/types/blog/index.test-d.ts
@@ -0,0 +1,28 @@
import { PrismaClient } from '.'
import { expectError } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectError(await prisma.$queryRaw(123))
expectError(await prisma.post.create({}))
expectError(
await prisma.post.update({
data: {},
}),
)
expectError(await prisma.post.updateMany({}))
expectError(
await prisma.post.count({
asd: true,
}),
)
})()
@@ -0,0 +1 @@
export { PrismaClient } from '@prisma/client'
@@ -0,0 +1,32 @@
import { PrismaClient } from '.'
import { expectError } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectError(
await prisma.user.update({
where: {},
data: {
posts: {
connectOrCreate: {
where: {
id: '123',
},
create: {
published: true,
},
},
},
},
}),
)
})()
@@ -0,0 +1 @@
export { PrismaClient } from '@prisma/client'
@@ -0,0 +1,32 @@
import { PrismaClient } from '.'
import { expectError } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectError(
await prisma.user.update({
where: {},
data: {
posts: {
connectOrCreate: {
where: {
id: '123',
},
create: {
published: true,
},
},
},
},
}),
)
})()
@@ -0,0 +1 @@
export { PrismaClient } from '@prisma/client'
26 changes: 26 additions & 0 deletions src/packages/client/src/__tests__/types/deleteMany/index.test-d.ts
@@ -0,0 +1,26 @@
import { PrismaClient } from '.'
import { expectError } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectError(
await prisma.post.deleteMany({
where: {
AND: {
AND: {
title: false,
},
},
},
}),
)
})()
@@ -0,0 +1 @@
export { PrismaClient, SortOrder, UserCreateArgs } from '@prisma/client'
@@ -0,0 +1,16 @@
import { PrismaClient } from '.'
import { expectDeprecated } from 'tsd'

// tslint:disable

const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:dev.db',
},
},
})

;(async () => {
expectDeprecated(prisma.post.findOne)
})()
55 changes: 55 additions & 0 deletions src/packages/client/src/__tests__/types/deprecation/schema.prisma
@@ -0,0 +1,55 @@
datasource db {
provider = "postgres"
url = env("SOME_DB")
}

generator client {
provider = "prisma-client-js"
output = "@prisma/client"
}

// / User model comment
model User {
id String @default(uuid()) @id
email String @unique
// / name comment
name String?
posts Post[]
}

model Post {
id String @default(cuid()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean
title String
content String?
authorId String?
author User? @relation(fields: [authorId], references: [id])
}

enum Role {
USER
ADMIN
}

model MachineData {
id String @default(cuid()) @id
machineId String
os String
osVersion Float
osArch String
procFreq Float
procCores Int
ram Int
}

model Like {
id String @default(cuid()) @id
userId String
user User @relation(fields: [userId], references: [id])
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}

0 comments on commit e1cb56a

Please sign in to comment.