mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 09:42:43 +00:00
return correct data
This commit is contained in:
@@ -67,13 +67,11 @@ describe('Tests for admin api', ()=>{
|
|||||||
jest.spyOn(NotificationModel, 'deleteNotification')
|
jest.spyOn(NotificationModel, 'deleteNotification')
|
||||||
.mockImplementationOnce(async (key) => {
|
.mockImplementationOnce(async (key) => {
|
||||||
expect(key).toBe(dismissKey); // Ensure the correct key is passed
|
expect(key).toBe(dismissKey); // Ensure the correct key is passed
|
||||||
return { dismissKey }; // Simulate the notification object that was deleted
|
return { message: 'Notification deleted successfully' }; // Simulate the notification object that was deleted
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await app
|
const response = await app
|
||||||
.delete(`/admin/notification/delete/${dismissKey}`)
|
.delete(`/admin/notification/delete/${dismissKey}`)
|
||||||
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.body).toEqual({ message: 'Notification deleted successfully' });
|
expect(response.body).toEqual({ message: 'Notification deleted successfully' });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ NotificationSchema.statics.addNotification = async function(data) {
|
|||||||
try {
|
try {
|
||||||
const newNotification = new this(notificationData);
|
const newNotification = new this(notificationData);
|
||||||
const savedNotification = await newNotification.save();
|
const savedNotification = await newNotification.save();
|
||||||
return { notification: savedNotification };
|
return savedNotification;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { message: err.message || 'Error saving notification' };
|
return { message: err.message || 'Error saving notification' };
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ NotificationSchema.statics.deleteNotification = async function(dismissKey) {
|
|||||||
if(!deletedNotification) {
|
if(!deletedNotification) {
|
||||||
return { message: 'Notification not found' };
|
return { message: 'Notification not found' };
|
||||||
}
|
}
|
||||||
return { message: 'Notification deleted successfully' }; // Update response here
|
return { message: 'Notification deleted successfully' };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { message: err.message || 'Error deleting notification' };
|
return { message: err.message || 'Error deleting notification' };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user