import { DyNTS_Http_Settings } from './http-settings.control-model'; import * as BodyParser from 'body-parser'; describe('| DyNTS_Http_Settings', () => { it('| should create an instance with default settings', () => { const settings = new DyNTS_Http_Settings(); expect(settings.httpPort).toBeUndefined(); expect(settings.httpsPort).toBeUndefined(); expect(settings.socketPath).toBeUndefined(); expect(settings.httpUrlencoded).toEqual({ limit: '50mb', extended: true, } as BodyParser.OptionsUrlencoded); expect(settings.httpJson).toEqual({ limit: '50mb', } as BodyParser.OptionsJson); expect(settings.httpsUrlencoded).toEqual({ limit: '50mb', extended: true, } as BodyParser.OptionsUrlencoded); expect(settings.httpsJson).toEqual({ limit: '50mb', } as BodyParser.OptionsJson); }); it('| should create an instance with provided settings', () => { const customSettings: DyNTS_Http_Settings = { httpPort: 8080, httpsPort: 8443, httpUrlencoded: { limit: '100mb', extended: false, }, httpJson: { limit: '100mb', }, httpsUrlencoded: { limit: '100mb', extended: false, }, httpsJson: { limit: '100mb', }, }; const settings = new DyNTS_Http_Settings(customSettings); expect(settings.httpPort).toBe(8080); expect(settings.httpsPort).toBe(8443); expect(settings.httpUrlencoded).toEqual({ limit: '100mb', extended: false, } as BodyParser.OptionsUrlencoded); expect(settings.httpJson).toEqual({ limit: '100mb', } as BodyParser.OptionsJson); expect(settings.httpsUrlencoded).toEqual({ limit: '100mb', extended: false, } as BodyParser.OptionsUrlencoded); expect(settings.httpsJson).toEqual({ limit: '100mb', } as BodyParser.OptionsJson); }); it('| should have socketPath undefined when not provided', () => { const settings = new DyNTS_Http_Settings(); expect(settings.socketPath).toBeUndefined(); }); it('| should set socketPath when provided in constructor', () => { const settings = new DyNTS_Http_Settings({ socketPath: '/ws' }); expect(settings.socketPath).toBe('/ws'); }); });