-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): aggregate runtime tests
- Loading branch information
1 parent
fbc0b1f
commit 1bcdcd9
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
src/packages/client/src/__tests__/runtime-tests/__snapshots__/runtime.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/packages/client/src/__tests__/runtime-tests/aggregations/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!dev.db |
Binary file not shown.
47 changes: 47 additions & 0 deletions
47
src/packages/client/src/__tests__/runtime-tests/aggregations/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
3 changes: 3 additions & 0 deletions
3
src/packages/client/src/__tests__/runtime-tests/aggregations/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"shouldSucceed": true | ||
} |
30 changes: 30 additions & 0 deletions
30
src/packages/client/src/__tests__/runtime-tests/aggregations/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} |