Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzerty23 committed Feb 21, 2024
1 parent f4aacfe commit 7eb9670
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/integration/tests/enhancements/with-policy/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,33 @@ describe('With Policy: auth() test', () => {
])
);
});

it('Default auth() without user context', async () => {
const { enhance } = await loadSchema(
`
model User {
id String @id
posts Post[]
@@allow('all', true)
}
model Post {
id String @id @default(uuid())
title String
author User @relation(fields: [authorId], references: [id])
authorId String @default(auth().id)
@@allow('all', auth().id != null)
}
`
);

const db = enhance();
await expect(db.user.create({ data: { id: 'userId-1' } })).toResolveTruthy();
await expect(db.post.create({ data: { title: 'title' } })).rejects.toThrow(
'Using `auth()` in `@default` requires a user context'
);
await expect(db.post.findMany({})).toResolveTruthy();
});
});

0 comments on commit 7eb9670

Please sign in to comment.