mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 06:02:46 +00:00
Add test for error handling deleting notifications
This commit is contained in:
@@ -58,7 +58,7 @@ describe('Tests for admin api', ()=>{
|
|||||||
expect(response.body).toEqual(savedNotification);
|
expect(response.body).toEqual(savedNotification);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail adding a new notification without dismissKey', async () => {
|
it('should handle error adding a notification without dismissKey', async () => {
|
||||||
const inputNotification = {
|
const inputNotification = {
|
||||||
title : 'Test Notification',
|
title : 'Test Notification',
|
||||||
text : 'This is a test notification',
|
text : 'This is a test notification',
|
||||||
@@ -96,5 +96,21 @@ describe('Tests for admin api', ()=>{
|
|||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.body).toEqual({ dismissKey: 'testKey' });
|
expect(response.body).toEqual({ dismissKey: 'testKey' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle error deleting a notification that doesnt exist', async ()=>{
|
||||||
|
const dismissKey = 'testKey';
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'findOneAndDelete')
|
||||||
|
.mockImplementationOnce(() => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue() };
|
||||||
|
});
|
||||||
|
const response = await app
|
||||||
|
.delete(`/admin/notification/delete/${dismissKey}`)
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'});
|
||||||
|
expect(response.status).toBe(500);
|
||||||
|
expect(response.body).toEqual({ message: 'Notification not found' });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user