0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 12:02:48 +00:00
Files
homebrewery/server/admin.api.spec.js
Trevor Buckner 8949248bc4 Example test
Added an example test that queries /admin/notification/all and checks if the response returns a list of notifications.

Since we don't have a real database, we overwrite (mock) NotificationModel to just return some fake data, otherwise the test would crash.
2024-10-01 17:15:36 -04:00

31 lines
891 B
JavaScript

const supertest = require('supertest');
// Mimic https responses to avoid being redirected all the time
const app = supertest.agent(require('app.js').app)
.set('X-Forwarded-Proto', 'https');
const NotificationModel = require('./notifications.model.js').model;
// Mock the NotificationModel
jest.mock('./notifications.model.js');
describe('Tests for admin api', () => {
afterEach(() => {
jest.resetAllMocks();
});
describe('Notifications', () => {
it('should return list of all notifications', async () => {
const fakeNotifications = ["a", "b"];
NotificationModel.getAll.mockResolvedValue(fakeNotifications);
const response = await app
.get('/admin/notification/all')
.set('Authorization', 'Basic ' + Buffer.from('admin:password3').toString('base64'));
expect(response.status).toBe(200);
expect(response.body).toEqual(fakeNotifications);
});
});
});