ravel
Version:
Ravel Rapid Application Development Framework
65 lines (55 loc) • 1.89 kB
JavaScript
describe('Ravel end-to-end middleware test', () => {
let app;
describe('basic application server consisting of routes', () => {
beforeEach(async () => {
const Ravel = require('../../lib/ravel');
// stub Routes (miscellaneous routes, such as templated HTML content)
const middleware = Ravel.Module.middleware;
const pre = Ravel.Routes.before;
const mapping = Ravel.Routes.mapping;
.Module('testm')
class TestModule {
async someMiddleware (ctx, next) {
ctx.body = 'Hello';
await next();
}
anotherMiddlewareFactory (word) {
return async function (ctx, next) {
ctx.body = word;
await next();
};
}
}
.Routes('/api/routes')
class TestRoutes {
getHandler (ctx) {
ctx.body += ' World!';
}
anotherHandler (ctx) {
ctx.body += ' World!';
}
}
app = new Ravel();
app.set('log level', app.$log.NONE);
app.set('keygrip keys', ['mysecret']);
app.load(TestModule, TestRoutes);
await app.init();
});
it('@middleware should make a module method available as middleware for use with @before', () => {
return request(app.callback)
.get('/api/routes/some')
.expect(200, 'Hello World!');
});
it('@middleware should make a module factory method available as middleware for use with @before', () => {
return request(app.callback)
.get('/api/routes/another')
.expect(200, 'Goodbye World!');
});
});
});