Skip to content

Commit

Permalink
add next to template, fixes #1593
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwooley committed May 12, 2024
1 parent 1c4dfbf commit e03ddec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/cli/src/routeGeneration/templates/express.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function RegisterRoutes(app: Router) {
validatedArgs,
successStatus: {{successStatus}},
});
next();
} catch (err) {
return next(err);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ app.use((req: any, res: any, next: any) => {
req.stringValue = 'fancyStringForContext';
next();
});
let postRouteMiddlwareCalled = false;
RegisterRoutes(app);
app.get('/reset-post-route-middleware-status', (req, res, next) => {
postRouteMiddlwareCalled = false;
res.json({ postRouteMiddlwareCalled }).send();
next();
});
app.get('/post-route-middleware-status', (req, res, next) => {
res.json({ postRouteMiddlwareCalled }).send();
next();
});
app.use((req, res, next) => {
postRouteMiddlwareCalled = true;
next();
});

// It's important that this come after the main routes are registered
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/express-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ import {
const basePath = '/v1';

describe('Express Server', () => {
it('can reset the post route middleware status', () => {
return verifyGetRequest('/reset-post-route-middleware-status', (_err, res) => {
expect(res.body.postRouteMiddlwareCalled).to.eq(false);
});
});
it('can handle get request to root controller`s path', () => {
return verifyGetRequest(basePath + '/', (_err, res) => {
const model = res.body as TestModel;
expect(model.id).to.equal(1);
});
});

it('can verify that post request middleware was called', () => {
return verifyGetRequest('/post-route-middleware-status', (_err, res) => {
expect(res.body.postRouteMiddlwareCalled).to.eq(true);
});
});
it('can handle get request to root controller`s method path', () => {
return verifyGetRequest(basePath + '/rootControllerMethodWithPath', (_err, res) => {
const model = res.body as TestModel;
Expand Down

0 comments on commit e03ddec

Please sign in to comment.