mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 18:02:39 +00:00
last changes
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
const supertest = require('supertest');
|
const supertest = require('supertest');
|
||||||
|
|
||||||
// Mimic https responses to avoid being redirected all the time
|
|
||||||
const app = supertest.agent(require('app.js').app)
|
const app = supertest.agent(require('app.js').app)
|
||||||
.set('X-Forwarded-Proto', 'https');
|
.set('X-Forwarded-Proto', 'https');
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@ describe('Tests for admin api', ()=>{
|
|||||||
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
|
|
||||||
jest.spyOn(NotificationModel, 'getAll')
|
jest.spyOn(NotificationModel, 'getAll')
|
||||||
.mockImplementationOnce(()=>fakeNotifications);
|
.mockImplementationOnce(()=>fakeNotifications);
|
||||||
|
|
||||||
@@ -35,17 +33,15 @@ describe('Tests for admin api', ()=>{
|
|||||||
stopAt : new Date().toISOString(),
|
stopAt : new Date().toISOString(),
|
||||||
dismissKey : 'testKey'
|
dismissKey : 'testKey'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const savedNotification = {
|
const savedNotification = {
|
||||||
...inputNotification,
|
...inputNotification,
|
||||||
_id : expect.any(String), // Don't care what _id is, just that it added one
|
_id : expect.any(String),
|
||||||
createdAt : expect.any(String), // Don't care what date is, just that it added it
|
createdAt : expect.any(String),
|
||||||
startAt : inputNotification.startAt, // Convert to json to match the format coming from mongo
|
startAt : inputNotification.startAt,
|
||||||
stopAt : inputNotification.stopAt,
|
stopAt : inputNotification.stopAt,
|
||||||
};
|
};
|
||||||
|
|
||||||
//Change 'save' function to just return itself instead of actually interacting with the database
|
|
||||||
jest.spyOn(NotificationModel.prototype, 'save')
|
jest.spyOn(NotificationModel.prototype, 'save')
|
||||||
.mockImplementationOnce(function() {
|
.mockImplementationOnce(function() {
|
||||||
return Promise.resolve(this);
|
return Promise.resolve(this);
|
||||||
@@ -60,22 +56,19 @@ describe('Tests for admin api', ()=>{
|
|||||||
expect(response.body).toEqual(savedNotification);
|
expect(response.body).toEqual(savedNotification);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete a notification based on its dismiss key', async () => {
|
it('should delete a notification based on its dismiss key', async ()=>{
|
||||||
const dismissKey = 'testKey';
|
const dismissKey = 'testKey';
|
||||||
|
|
||||||
// Mock findOneAndDelete to simulate a successful deletion
|
|
||||||
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);
|
||||||
return { message: 'Notification deleted successfully' }; // Simulate the notification object that was deleted
|
return { message: 'Notification deleted successfully' };
|
||||||
});
|
});
|
||||||
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' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user