Skip to content

Commit dad65de

Browse files
committed
add test
1 parent 5a3ee9f commit dad65de

File tree

1 file changed

+29
-0
lines changed
  • tests/integration/tests/enhancements/with-policy

1 file changed

+29
-0
lines changed

tests/integration/tests/enhancements/with-policy/auth.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,33 @@ describe('With Policy: auth() test', () => {
505505
])
506506
);
507507
});
508+
509+
it('Default auth() without user context', async () => {
510+
const { enhance } = await loadSchema(
511+
`
512+
model User {
513+
id String @id
514+
posts Post[]
515+
516+
@@allow('all', true)
517+
}
518+
519+
model Post {
520+
id String @id @default(uuid())
521+
title String
522+
author User @relation(fields: [authorId], references: [id])
523+
authorId String @default(auth().id)
524+
525+
@@allow('all', auth().id != null)
526+
}
527+
`
528+
);
529+
530+
const db = enhance();
531+
await expect(db.user.create({ data: { id: 'userId-1' } })).toResolveTruthy();
532+
await expect(db.post.create({ data: { title: 'title' } })).rejects.toThrow(
533+
'Using `auth()` in `@default` requires a user context'
534+
);
535+
await expect(db.post.findMany({})).toResolveTruthy();
536+
});
508537
});

0 commit comments

Comments
 (0)