From 4968300e7aa98c68a60498bc95bed0c926ee85f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 6 Oct 2024 19:54:41 +0200 Subject: [PATCH] return correct data --- server/admin.api.spec.js | 4 +--- server/notifications.model.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/server/admin.api.spec.js b/server/admin.api.spec.js index d3cfaff15..d69824bf9 100644 --- a/server/admin.api.spec.js +++ b/server/admin.api.spec.js @@ -67,13 +67,11 @@ describe('Tests for admin api', ()=>{ jest.spyOn(NotificationModel, 'deleteNotification') .mockImplementationOnce(async (key) => { 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 .delete(`/admin/notification/delete/${dismissKey}`) .set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`); - expect(response.status).toBe(200); expect(response.body).toEqual({ message: 'Notification deleted successfully' }); }); diff --git a/server/notifications.model.js b/server/notifications.model.js index 2d5f25ce8..578bc01e4 100644 --- a/server/notifications.model.js +++ b/server/notifications.model.js @@ -25,7 +25,7 @@ NotificationSchema.statics.addNotification = async function(data) { try { const newNotification = new this(notificationData); const savedNotification = await newNotification.save(); - return { notification: savedNotification }; + return savedNotification; } catch (err) { return { message: err.message || 'Error saving notification' }; } @@ -39,7 +39,7 @@ NotificationSchema.statics.deleteNotification = async function(dismissKey) { if(!deletedNotification) { return { message: 'Notification not found' }; } - return { message: 'Notification deleted successfully' }; // Update response here + return { message: 'Notification deleted successfully' }; } catch (err) { return { message: err.message || 'Error deleting notification' }; }