agmission/Development/server/tests/integration/main.integration.test.js
2026-04-29 09:40:51 -04:00

77 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* Integration tests main controller (controllers/main.js)
*
* Covers: pingAPI_get, getAppConfig_get, setAppConfig_post
*/
const { connectDB, disconnectDB, clearCollection } = require('./jest.setup');
const { mockReq, mockRes, newId } = require('./mock_data');
let Settings;
beforeAll(async () => {
await connectDB();
Settings = require('../../model/setting');
});
afterAll(async () => {
await disconnectDB();
});
const mainCtl = require('../../controllers/main');
describe('main controller data methods', () => {
afterAll(async () => {
await clearCollection(Settings);
});
// -------------------------------------------------------------------------
describe('pingAPI_get', () => {
it('responds with a pong / alive message', async () => {
const req = mockReq();
const res = mockRes();
await mainCtl.pingAPI_get(req, res);
// pingAPI_get uses res.send() or res.json()
const called = res.json.mock.calls.length > 0 || res.send.mock.calls.length > 0;
expect(called).toBe(true);
});
});
// -------------------------------------------------------------------------
describe('getAppConfig_get', () => {
it('returns an app config object', async () => {
const req = mockReq({ query: {} });
const res = mockRes();
await mainCtl.getAppConfig_get(req, res);
const called = res.json.mock.calls.length > 0 || res.send.mock.calls.length > 0;
expect(called).toBe(true);
expect(typeof res._data).toBe('object');
});
});
// -------------------------------------------------------------------------
describe('setAppConfig_post', () => {
it('saves an app config value and returns the saved document', async () => {
await clearCollection(Settings);
const req = mockReq({
uid: newId(),
ut: '1',
body: { key: 'testKey', value: 'testValue' },
});
const res = mockRes();
await mainCtl.setAppConfig_post(req, res);
expect(res.json).toHaveBeenCalled();
expect(res._data).toBeTruthy();
});
});
});