-
-
Notifications
You must be signed in to change notification settings - Fork 12
test: migrate more migration cases, a few minor fixes #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ | |
| email: user.email, | ||
| name: user.name, | ||
| }); | ||
| expect(updated.updatedAt.getTime()).toBeGreaterThan(user.updatedAt.getTime()); | ||
|
Check failure on line 41 in tests/e2e/orm/client-api/update.test.ts
|
||
|
|
||
| // id as filter | ||
| updated = await client.user.update({ | ||
|
|
@@ -114,6 +114,21 @@ | |
| ).resolves.toMatchObject({ id: 'user2' }); | ||
| }); | ||
|
|
||
| it('does not update updatedAt if no other scalar fields are updated', async () => { | ||
| const user = await createUser(client, '[email protected]'); | ||
| const originalUpdatedAt = user.updatedAt; | ||
|
|
||
| await client.user.update({ | ||
| where: { id: user.id }, | ||
| data: { | ||
| posts: { create: { title: 'Post1' } }, | ||
| }, | ||
| }); | ||
|
|
||
| const updatedUser = await client.user.findUnique({ where: { id: user.id } }); | ||
| expect(updatedUser?.updatedAt).toEqual(originalUpdatedAt); | ||
| }); | ||
|
|
||
| it('works with numeric incremental update', async () => { | ||
| await createUser(client, '[email protected]', { | ||
| profile: { create: { id: '1', bio: 'bio' } }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import Decimal from 'decimal.js'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| // TODO: zod support | ||
| it.skip('verifies issue 657', async () => { | ||
| const { zodSchemas } = await createTestClient(` | ||
| model Foo { | ||
| id Int @id @default(autoincrement()) | ||
| intNumber Int @gt(0) | ||
| floatNumber Float @gt(0) | ||
| decimalNumber Decimal @gt(0.1) @lte(10) | ||
| } | ||
| `); | ||
|
|
||
| const schema = zodSchemas.models.FooUpdateSchema; | ||
| expect(schema.safeParse({ intNumber: 0 }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ intNumber: 1 }).success).toBeTruthy(); | ||
| expect(schema.safeParse({ floatNumber: 0 }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ floatNumber: 1.1 }).success).toBeTruthy(); | ||
| expect(schema.safeParse({ decimalNumber: 0 }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ decimalNumber: '0' }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ decimalNumber: new Decimal(0) }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ decimalNumber: 11 }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ decimalNumber: '11.123456789' }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ decimalNumber: new Decimal('11.123456789') }).success).toBeFalsy(); | ||
| expect(schema.safeParse({ decimalNumber: 10 }).success).toBeTruthy(); | ||
| expect(schema.safeParse({ decimalNumber: '10' }).success).toBeTruthy(); | ||
| expect(schema.safeParse({ decimalNumber: new Decimal('10') }).success).toBeTruthy(); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| // TODO: field-level policy support | ||
| it.skip('verifies issue 665', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| admin Boolean @default(false) | ||
| username String @unique @allow("all", auth() == this) @allow("all", auth().admin) | ||
| password String @password @default("") @allow("all", auth() == this) @allow("all", auth().admin) | ||
| firstName String @default("") | ||
| lastName String @default("") | ||
|
|
||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| await db.$unuseAll.user.create({ data: { id: 1, username: 'test', password: 'test', admin: true } }); | ||
|
|
||
| // admin | ||
| let r = await db.$setAuth({ id: 1, admin: true }).user.findFirst(); | ||
| expect(r.username).toEqual('test'); | ||
|
|
||
| // owner | ||
| r = await db.$setAuth({ id: 1 }).user.findFirst(); | ||
| expect(r.username).toEqual('test'); | ||
|
|
||
| // anonymous | ||
| r = await db.$setAuth({ id: 0 }).user.findFirst(); | ||
| expect(r.username).toBeUndefined(); | ||
|
|
||
| // non-owner | ||
| r = await db.$setAuth({ id: 2 }).user.findFirst(); | ||
| expect(r.username).toBeUndefined(); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { loadSchema } from '@zenstackhq/testtools'; | ||
| import { it } from 'vitest'; | ||
|
|
||
| it('verifies issue 674', async () => { | ||
| await loadSchema( | ||
| ` | ||
| model Foo { | ||
| id Int @id | ||
| } | ||
|
|
||
| enum MyUnUsedEnum { ABC CDE @@map('my_unused_enum') } | ||
| `, | ||
| ); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 689', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model UserRole { | ||
| id Int @id @default(autoincrement()) | ||
| user User @relation(fields: [userId], references: [id]) | ||
| userId Int | ||
| role String | ||
|
|
||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| userRole UserRole[] | ||
| deleted Boolean @default(false) | ||
|
|
||
| @@allow('create,read', true) | ||
| @@allow('read', auth() == this) | ||
| @@allow('read', userRole?[user == auth() && 'Admin' == role]) | ||
| @@allow('read', userRole?[user == auth()]) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const rawDb = db.$unuseAll(); | ||
|
|
||
| await rawDb.user.create({ | ||
| data: { | ||
| id: 1, | ||
| userRole: { | ||
| create: [ | ||
| { id: 1, role: 'Admin' }, | ||
| { id: 2, role: 'Student' }, | ||
| ], | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await rawDb.user.create({ | ||
| data: { | ||
| id: 2, | ||
| userRole: { | ||
| connect: { id: 1 }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const c1 = await rawDb.user.count({ | ||
| where: { | ||
| userRole: { | ||
| some: { role: 'Student' }, | ||
| }, | ||
| NOT: { deleted: true }, | ||
| }, | ||
| }); | ||
|
|
||
| const c2 = await db.user.count({ | ||
| where: { | ||
| userRole: { | ||
| some: { role: 'Student' }, | ||
| }, | ||
| NOT: { deleted: true }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(c1).toEqual(c2); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { it } from 'vitest'; | ||
|
|
||
| // TODO: field-level policy support | ||
| it.skip('verifies issue 703', async () => { | ||
| await createPolicyTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| name String? | ||
| admin Boolean @default(false) | ||
|
|
||
| companiesWorkedFor Company[] | ||
|
|
||
| username String @unique @allow("all", auth() == this) @allow('read', companiesWorkedFor?[owner == auth()]) @allow("all", auth().admin) | ||
| } | ||
|
|
||
| model Company { | ||
| id Int @id @default(autoincrement()) | ||
| name String? | ||
| owner User @relation(fields: [ownerId], references: [id]) | ||
| ownerId Int | ||
| } | ||
| `, | ||
| ); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.