mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-18 07:52:41 +00:00
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.
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
"test:api-unit": "jest \"server/.*.spec.js\" --verbose",
|
"test:api-unit": "jest \"server/.*.spec.js\" --verbose",
|
||||||
"test:api-unit:themes": "jest \"server/.*.spec.js\" -t \"theme bundle\" --verbose",
|
"test:api-unit:themes": "jest \"server/.*.spec.js\" -t \"theme bundle\" --verbose",
|
||||||
"test:api-unit:css": "jest \"server/.*.spec.js\" -t \"Get CSS\" --verbose",
|
"test:api-unit:css": "jest \"server/.*.spec.js\" -t \"Get CSS\" --verbose",
|
||||||
|
"test:api-unit:notifications": "jest \"server/.*.spec.js\" -t \"Notifications\" --verbose",
|
||||||
"test:coverage": "jest --coverage --silent --runInBand",
|
"test:coverage": "jest --coverage --silent --runInBand",
|
||||||
"test:dev": "jest --verbose --watch",
|
"test:dev": "jest --verbose --watch",
|
||||||
"test:basic": "jest tests/markdown/basic.test.js --verbose",
|
"test:basic": "jest tests/markdown/basic.test.js --verbose",
|
||||||
|
|||||||
30
server/admin.api.spec.js
Normal file
30
server/admin.api.spec.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user