unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
54 lines • 2.06 kB
JavaScript
import express from 'express';
import { conditionalMiddleware } from '../../../../lib/middleware/conditional-middleware.js';
import supertest from 'supertest';
test('disabled middleware should not block paths that use the same path', async () => {
const app = express();
const path = '/api/admin/projects';
app.use(path, conditionalMiddleware(() => false, (_req, res) => {
res.send({ changeRequest: 'hello' });
}));
app.get(path, (_req, res) => {
res.json({ projects: [] });
});
await supertest(app)
.get('/api/admin/projects')
.expect(200, { projects: [] });
});
test('should return 404 when path is not enabled', async () => {
const app = express();
const path = '/api/admin/projects';
app.use(`${path}/change-requests`, conditionalMiddleware(() => false, (_req, res) => {
res.send({ changeRequest: 'hello' });
}));
app.get(path, (_req, res) => {
res.json({ projects: [] });
});
await supertest(app).get('/api/admin/projects/change-requests').expect(404);
});
test('should respect ordering of endpoints', async () => {
const app = express();
const path = '/api/admin/projects';
app.use(path, conditionalMiddleware(() => true, (_req, res) => {
res.json({ name: 'Request changes' });
}));
app.get(path, (_req, res) => {
res.json({ projects: [] });
});
await supertest(app)
.get('/api/admin/projects')
.expect(200, { name: 'Request changes' });
});
test('disabled middleware should not block paths that use the same basepath', async () => {
const app = express();
const path = '/api/admin/projects';
app.use(`${path}/change-requests`, conditionalMiddleware(() => false, (_req, res) => {
res.json({ name: 'Request changes' });
}));
app.get(path, (_req, res) => {
res.json({ projects: [] });
});
await supertest(app)
.get('/api/admin/projects')
.expect(200, { projects: [] });
});
//# sourceMappingURL=conditional-middleware.e2e.test.js.map