Add beforeCreate hook test

This commit is contained in:
Elliot DeNolf
2020-05-15 11:27:02 -04:00
parent 83a69e50b2
commit 098305ee3b
2 changed files with 22 additions and 0 deletions

View File

@@ -340,6 +340,25 @@ describe('Collections - REST', () => {
});
describe('Hooks', () => {
it('beforeCreate', async () => {
const response = await fetch(`${url}/api/hooktests`, {
body: JSON.stringify({
title: faker.name.firstName(),
description: 'Original',
priority: 1,
}),
headers: {
Authorization: `JWT ${token}`,
'Content-Type': 'application/json',
hook: 'beforeCreate', // Used by hook
},
method: 'post',
});
const data = await response.json();
expect(response.status).toBe(201);
expect(data.doc.description).toEqual('Original-beforeCreateSuffix');
});
it('afterRead', async () => {
const response = await fetch(`${url}/api/hooktests`, {
body: JSON.stringify({