Skip to content

Commit cb68815

Browse files
authored
test(delegate): add @password interaction test (#1721)
1 parent 57652a1 commit cb68815

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
import { compareSync } from 'bcryptjs';
3+
4+
describe('Polymorphic @omit', () => {
5+
const model = `
6+
model User {
7+
id Int @id @default(autoincrement())
8+
posts Post[]
9+
10+
@@allow('all', true)
11+
}
12+
13+
model Asset {
14+
id Int @id @default(autoincrement())
15+
type String
16+
assetPassword String @password
17+
18+
@@delegate(type)
19+
@@allow('all', true)
20+
}
21+
22+
model Post extends Asset {
23+
title String
24+
postPassword String @password
25+
user User? @relation(fields: [userId], references: [id])
26+
userId Int? @unique
27+
}
28+
`;
29+
30+
it('hashes when created directly', async () => {
31+
const { enhance } = await loadSchema(model);
32+
33+
const db = enhance();
34+
const post = await db.post.create({ data: { title: 'Post1', assetPassword: 'asset', postPassword: 'post' } });
35+
expect(compareSync('asset', post.assetPassword)).toBeTruthy();
36+
expect(compareSync('post', post.postPassword)).toBeTruthy();
37+
});
38+
39+
it('hashes when created nested', async () => {
40+
const { enhance } = await loadSchema(model);
41+
42+
const db = enhance();
43+
const user = await db.user.create({
44+
data: { posts: { create: { title: 'Post1', assetPassword: 'asset', postPassword: 'post' } } },
45+
include: { posts: true },
46+
});
47+
expect(compareSync('asset', user.posts[0].assetPassword)).toBeTruthy();
48+
expect(compareSync('post', user.posts[0].postPassword)).toBeTruthy();
49+
});
50+
});

0 commit comments

Comments
 (0)