Fix jwt-token

This commit is contained in:
2025-09-16 07:27:28 +02:00
parent da0d8659e5
commit 2f87827d9d

View File

@@ -18,7 +18,7 @@ describe('Detectors Routes', () => {
detectorsRoutes = require('../../routes/detectors');
console.log('🔧 DEBUG: Required detectors route - global.__TEST_MODELS__:', !!global.__TEST_MODELS__);
// Setup express app for testing
// Setup express app for testing (matching production structure)
app = express();
app.use(express.json());
@@ -32,7 +32,8 @@ describe('Detectors Routes', () => {
next();
});
app.use('/detectors', detectorsRoutes);
// Mount routes under /api like in production
app.use('/api/detectors', detectorsRoutes);
});
after(async () => {
@@ -65,7 +66,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(201);
@@ -86,7 +87,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(404);
@@ -114,7 +115,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(403);
@@ -143,7 +144,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(201);
@@ -172,7 +173,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(200);
@@ -192,7 +193,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(invalidData);
expect(response.status).to.equal(400);
@@ -214,7 +215,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(invalidData);
expect(response.status).to.equal(400);
@@ -236,7 +237,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(criticalDetection);
expect(response.status).to.equal(201);
@@ -260,7 +261,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(201);
@@ -279,7 +280,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(heartbeatData);
expect(response.status).to.equal(200);
@@ -295,7 +296,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(heartbeatData);
expect(response.status).to.equal(400);
@@ -309,7 +310,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(heartbeatData);
expect(response.status).to.equal(200);
@@ -323,7 +324,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(heartbeatData);
expect(response.status).to.equal(400);
@@ -340,7 +341,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(heartbeatData);
expect(response.status).to.equal(200);
@@ -353,7 +354,7 @@ describe('Detectors Routes', () => {
describe('Error Handling', () => {
it('should handle invalid JSON payload', async () => {
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.set('Content-Type', 'application/json')
.send('invalid json{');
@@ -377,7 +378,7 @@ describe('Detectors Routes', () => {
};
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(response.status).to.equal(500);
@@ -389,7 +390,7 @@ describe('Detectors Routes', () => {
it('should handle missing required fields gracefully', async () => {
const response = await request(app)
.post('/detectors')
.post('/api/detectors')
.send({});
expect(response.status).to.equal(400);
@@ -414,7 +415,7 @@ describe('Detectors Routes', () => {
};
await request(app)
.post('/detectors')
.post('/api/detectors')
.send(detectionData);
expect(consoleSpy.called).to.be.true;