|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { NestApplication } from '../nest-application'; |
| 3 | +import { ApplicationConfig } from '../application-config'; |
| 4 | +import { NestContainer } from '../injector'; |
| 5 | +import { NoopHttpAdapter } from './utils/noop-adapter.spec'; |
| 6 | + |
| 7 | +describe('NestApplication', () => { |
| 8 | + describe('Hybrid Application', () => { |
| 9 | + class Interceptor { |
| 10 | + public intercept(context, next) { |
| 11 | + return next(); |
| 12 | + } |
| 13 | + } |
| 14 | + it('default should use new ApplicationConfig', () => { |
| 15 | + const applicationConfig = new ApplicationConfig(); |
| 16 | + const container = new NestContainer(applicationConfig); |
| 17 | + const instance = new NestApplication( |
| 18 | + container, |
| 19 | + new NoopHttpAdapter({}), |
| 20 | + applicationConfig, |
| 21 | + {}, |
| 22 | + ); |
| 23 | + instance.useGlobalInterceptors(new Interceptor()); |
| 24 | + const microservice = instance.connectMicroservice({}); |
| 25 | + expect((instance as any).config.getGlobalInterceptors().length).to.equal( |
| 26 | + 1, |
| 27 | + ); |
| 28 | + expect( |
| 29 | + (microservice as any).applicationConfig.getGlobalInterceptors().length, |
| 30 | + ).to.equal(0); |
| 31 | + }); |
| 32 | + it('should inherit existing ApplicationConfig', () => { |
| 33 | + const applicationConfig = new ApplicationConfig(); |
| 34 | + const container = new NestContainer(applicationConfig); |
| 35 | + const instance = new NestApplication( |
| 36 | + container, |
| 37 | + new NoopHttpAdapter({}), |
| 38 | + applicationConfig, |
| 39 | + {}, |
| 40 | + ); |
| 41 | + instance.useGlobalInterceptors(new Interceptor()); |
| 42 | + const microservice = instance.connectMicroservice( |
| 43 | + {}, |
| 44 | + { inheritAppConfig: true }, |
| 45 | + ); |
| 46 | + expect((instance as any).config.getGlobalInterceptors().length).to.equal( |
| 47 | + 1, |
| 48 | + ); |
| 49 | + expect( |
| 50 | + (microservice as any).applicationConfig.getGlobalInterceptors().length, |
| 51 | + ).to.equal(1); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments