Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('binds current controller to the request context as singleton', async () => {
const controller1 = await requestCtx.get(CoreBindings.CONTROLLER_CURRENT);
expect(controller1).instanceOf(MyController);
const controller2 = await requestCtx.get(CoreBindings.CONTROLLER_CURRENT);
expect(controller2).to.be.exactly(controller1);
const childCtx = new Context(requestCtx);
const controller3 = await childCtx.get(CoreBindings.CONTROLLER_CURRENT);
expect(controller3).to.be.exactly(controller1);
await expect(
appCtx.get(CoreBindings.CONTROLLER_CURRENT),
).to.be.rejectedWith(/The key .+ is not bound to any value/);
});
function givenContextsAndHandlerRoute() {
const spec = anOperationSpec().build();
const route = new Route('get', '/greet', spec, () => {});
appCtx = new Context('application');
requestCtx = new Context(appCtx, 'request');
route.updateBindings(requestCtx);
}
});
beforeEach(() => {
ctx = new Context();
});
function givenContextsAndHandlerRoute() {
const spec = anOperationSpec().build();
const route = new Route('get', '/greet', spec, () => {});
appCtx = new Context('application');
requestCtx = new Context(appCtx, 'request');
route.updateBindings(requestCtx);
}
});
function givenContextsAndControllerRoute() {
const spec = anOperationSpec().build();
const route = new MyRoute(
'get',
'/greet',
spec,
MyController,
myControllerFactory,
'greet',
);
appCtx = new Context('application');
requestCtx = new Context(appCtx, 'request');
route.updateBindings(requestCtx);
}
});
function givenContextsAndControllerRoute() {
const spec = anOperationSpec().build();
const route = new MyRoute(
'get',
'/greet',
spec,
MyController,
myControllerFactory,
'greet',
);
appCtx = new Context('application');
requestCtx = new Context(appCtx, 'request');
route.updateBindings(requestCtx);
}
});