Skip to content

Commit

Permalink
feat(client): aggregate runtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jul 5, 2020
1 parent fbc0b1f commit 1bcdcd9
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`runtime aggregations: aggregations example should succeed 1`] = `"success"`;

exports[`runtime blog: blog example should succeed 1`] = `"success"`;

exports[`runtime blog-env: blog-env example should not succeed 1`] = `
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!dev.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { PrismaClient } = require('@prisma/client')
const assert = require('assert')

module.exports = async () => {
const prisma = new PrismaClient()

const result = await prisma.user.aggregate({
avg: {
age: true,
},
count: true,
max: {
age: true,
},
min: {
age: true,
},
})

assert.deepEqual(result, {
avg: { age: 80 },
count: 10,
max: { age: 163 },
min: { age: 5 },
})

prisma.disconnect()
}

if (require.main === module) {
// seed()
module.exports()
}

async function seed() {
const prisma = new PrismaClient()
for (let i = 0; i < 10; i++) {
await prisma.user.create({
data: {
age: Math.round(Math.random() * 200),
email: `bob+${i}@hey.com`,
name: 'Bobby Brown',
},
})
}
prisma.disconnect()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"shouldSucceed": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
datasource db {
provider = "sqlite"
url = "file:dev.db"
default = true
}

generator client {
provider = "prisma-client-js"
}

// / User model comment
model User {
id String @default(uuid()) @id
email String @unique
age Int
// / 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])
}

0 comments on commit 1bcdcd9

Please sign in to comment.