Skip to content
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

test(delegate): add @password interaction test #1721

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { loadSchema } from '@zenstackhq/testtools';
import { compareSync } from 'bcryptjs';

describe('Polymorphic @omit', () => {
const model = `
model User {
id Int @id @default(autoincrement())
posts Post[]

@@allow('all', true)
}

model Asset {
id Int @id @default(autoincrement())
type String
assetPassword String @password

@@delegate(type)
@@allow('all', true)
}

model Post extends Asset {
title String
postPassword String @password
user User? @relation(fields: [userId], references: [id])
userId Int? @unique
}
`;

it('hashes when created directly', async () => {
const { enhance } = await loadSchema(model);

const db = enhance();
const post = await db.post.create({ data: { title: 'Post1', assetPassword: 'asset', postPassword: 'post' } });
expect(compareSync('asset', post.assetPassword)).toBeTruthy();
expect(compareSync('post', post.postPassword)).toBeTruthy();
});

it('hashes when created nested', async () => {
const { enhance } = await loadSchema(model);

const db = enhance();
const user = await db.user.create({
data: { posts: { create: { title: 'Post1', assetPassword: 'asset', postPassword: 'post' } } },
include: { posts: true },
});
expect(compareSync('asset', user.posts[0].assetPassword)).toBeTruthy();
expect(compareSync('post', user.posts[0].postPassword)).toBeTruthy();
});
});
Loading