Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('boots non-global interceptors when app.boot() is called', async () => {
const expectedBinding = {
key: `interceptors.myInterceptor`,
tags: [
ContextTags.PROVIDER,
ContextTags.TYPE,
ContextTags.NAMESPACE,
ContextTags.NAME,
],
scope: BindingScope.TRANSIENT,
};
await app.boot();
const binding = app.getBinding('interceptors.myInterceptor');
expect({
key: binding.key,
tags: binding.tagNames,
scope: binding.scope,
}).to.eql(expectedBinding);
});
it('boots global interceptors when app.boot() is called', async () => {
const expectedBinding = {
key: `${GLOBAL_INTERCEPTOR_NAMESPACE}.myGlobalInterceptor`,
tags: [
ContextTags.PROVIDER,
ContextTags.TYPE,
ContextTags.GLOBAL_INTERCEPTOR,
ContextTags.NAMESPACE,
ContextTags.GLOBAL_INTERCEPTOR_GROUP,
ContextTags.NAME,
],
scope: BindingScope.TRANSIENT,
};
await app.boot();
const bindings = app
.findByTag(ContextTags.GLOBAL_INTERCEPTOR)
.map(b => ({key: b.key, tags: b.tagNames, scope: b.scope}));
expect(bindings).to.containEql(expectedBinding);
});
async function expectGeocoderToBeBound(myApp: Application) {
const boundServices = myApp.find('services.*').map(b => b.key);
expect(boundServices).to.containEql('services.GeocoderService');
const binding = myApp.getBinding('services.GeocoderService');
expect(binding.scope).to.equal(BindingScope.TRANSIENT);
const serviceInstance1 = await myApp.get('services.GeocoderService');
expect(serviceInstance1).to.be.instanceOf(DummyGeocoder);
const serviceInstance2 = await myApp.get('services.GeocoderService');
expect(serviceInstance2).to.not.be.equal(serviceInstance1);
}
function expectNoteRepoToBeBound(myApp: Application) {
const boundRepositories = myApp.find('repositories.*').map(b => b.key);
expect(boundRepositories).to.containEql('repositories.NoteRepo');
const binding = myApp.getBinding('repositories.NoteRepo');
expect(binding.scope).to.equal(BindingScope.TRANSIENT);
const repoInstance = myApp.getSync('repositories.NoteRepo');
expect(repoInstance).to.be.instanceOf(NoteRepo);
}