MotorSignal-App/server/waze_relay/test/waze_compatibility.test.js

43 lines
1.5 KiB
JavaScript

const { describe, it } = require('node:test');
const assert = require('node:assert');
const app = require('../server');
describe('Waze Compatibility and Health Endpoints', () => {
it('health endpoint returns legacy service name and status ok', async () => {
// Test the health route handler directly
const route = app._router.stack.find(
(layer) => layer.route && layer.route.path && (layer.route.path === '/health' || layer.route.path.includes('/health'))
);
assert.ok(route, 'Health route should be registered');
let responseData = null;
const req = {};
const res = {
json: (data) => {
responseData = data;
}
};
route.route.stack[0].handle(req, res);
assert.strictEqual(responseData?.status, 'ok');
assert.strictEqual(responseData?.service, 'MotorSignal Waze Community Relay');
assert.ok(Array.isArray(responseData?.features));
assert.ok(responseData.features.includes('police'));
assert.ok(responseData.features.includes('traffic'));
});
it('mounts legacy /alerts, /api/alerts, and /api/waze routes', () => {
const mountedPaths = app._router.stack
.filter((layer) => layer.name === 'router')
.map((layer) => layer.regexp.toString());
// Express regex representations for paths
const hasAlerts = mountedPaths.some((p) => p.includes('alerts'));
const hasApiAlerts = mountedPaths.some((p) => p.includes('api'));
assert.ok(hasAlerts, '/alerts router should be mounted');
assert.ok(hasApiAlerts, '/api/* router should be mounted');
});
});