feat: added beforeLogin hook (#1289)

This commit is contained in:
Daniel Söderling
2022-10-24 18:05:12 +02:00
committed by GitHub
parent a9f2f0ec03
commit 09d793926d
7 changed files with 89 additions and 5 deletions

View File

@@ -8,6 +8,9 @@ import { hooksSlug } from './collections/Hook';
import { generatedAfterReadText, nestedAfterReadHooksSlug } from './collections/NestedAfterReadHooks';
import { relationsSlug } from './collections/Relations';
import type { NestedAfterReadHook } from './payload-types';
import { hooksUsersSlug } from './collections/Users';
import { devUser, regularUser } from '../credentials';
import { AuthenticationError } from '../../src/errors';
let client: RESTClient;
@@ -117,4 +120,20 @@ describe('Hooks', () => {
expect(retrievedDoc.group.subGroup.shouldPopulate.title).toEqual(relation.title);
});
});
describe('auth collection hooks', () => {
it('allow admin login', async () => {
const { user } = await payload.login({
collection: hooksUsersSlug,
data: {
email: devUser.email,
password: devUser.password,
},
});
expect(user).toBeDefined();
});
it('deny user login', async () => {
await expect(() => payload.login({ collection: hooksUsersSlug, data: { email: regularUser.email, password: regularUser.password } })).rejects.toThrow(AuthenticationError);
});
});
});