0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 14:02:41 +00:00

add last test

This commit is contained in:
Víctor Losada Hernández
2024-10-03 08:53:27 +02:00
parent d216216df7
commit 9cc4d2d7c5

View File

@@ -13,7 +13,7 @@ describe('Tests for admin api', () => {
describe('Notifications', ()=>{ describe('Notifications', ()=>{
it('should return list of all notifications', async ()=>{ it('should return list of all notifications', async ()=>{
const fakeNotifications = ["a", "b"]; const fakeNotifications = ['a', 'b'];
// Change 'getAll' function to just return the above array instead of actually using the database // Change 'getAll' function to just return the above array instead of actually using the database
jest.spyOn(NotificationModel, 'getAll') jest.spyOn(NotificationModel, 'getAll')
@@ -21,7 +21,7 @@ describe('Tests for admin api', () => {
const response = await app const response = await app
.get('/admin/notification/all') .get('/admin/notification/all')
.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(fakeNotifications); expect(response.body).toEqual(fakeNotifications);
@@ -52,11 +52,30 @@ describe('Tests for admin api', () => {
const response = await app const response = await app
.post('/admin/notification/add') .post('/admin/notification/add')
.set('Authorization', 'Basic ' + Buffer.from('admin:password3').toString('base64')) .set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`)
.send(inputNotification); .send(inputNotification);
expect(response.status).toBe(201); expect(response.status).toBe(201);
expect(response.body).toEqual(savedNotification); expect(response.body).toEqual(savedNotification);
}); });
it('should delete a notification based on its dismiss key', async () => {
const dismissKey = 'testKey';
// Mock the deleteOne function to simulate a successful deletion
jest.spyOn(NotificationModel, 'deleteOne')
.mockImplementationOnce((query) => {
expect(query).toEqual({ dismissKey }); // Ensure the correct query is passed
return Promise.resolve({ deletedCount: 1 });
});
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' });
});
}); });
}); });