<commit_before>/// <reference path='../../typings/mocha/mocha.d.ts' />
/// <reference path='../../typings/es6-promise/es6-promise.d.ts' />
/// <reference path='../../typings/mock-fs/mock-fs.d.ts' />

import { expect } from '../util/specs';
import { request, requestApp, IRupertTest } from '../util/request';

import * as mockfs from 'mock-fs';

import {
  Request as Q, Response as S
} from 'express';

import {
  Rupert,
  Config,
  IPlugin,
  IPluginHandler,
  Methods,
  ILogger,
  Inject,
  Injector,
  bind
} from '../rupert';

import {
  getMockLogger
} from '../logger/mockLogger';

describe('Rupert App', function() {
  it('creates and injects a new Rupert app', function() {
    const app = Rupert.createApp({foo: 'bar'});
    expect(app.config.find('foo')).to.equal('bar');
  });

  it('has an express application', function(done) {
    const rupert = Rupert.createApp({log: {level: 'silent'}});
    rupert.app.all('/', (q: Q, s: S, n: Function) => {
      s.status(200).send('OK');
    });
    requestApp(rupert.app)
      .get('/')
      .expect(200)
      .expect('set-cookie', /NODE_ENV=development/)
      .end(done)
      ;
  });

  describe('servers', function() {
    it('makes an insecure server', function(done) {
      let config: Config = new Config({hostname: 'rupert-test'});
      const rupert = new Rupert(config, getMockLogger());

      expect(rupert.servers.http).to.exist;
      expect(rupert.servers.https).to.not.exist;
      expect(rupert.url).to.equal('http://rupert-test:8080/');

      rupert.app.all('/', (q: Q, s: S, n: Function) => {
        s.status(200).send('OK');
      });

      request(rupert).then((test: IRupertTest) => {
        test.get('/').expect(200).finish(done);
      }).catch(done);
    });

    it('makes a secure server', function(done) {
      /** tslint:disable */
      mockfs({
        'env/': {
          'server.key':
'-----BEGIN RSA PRIVATE KEY-----\n' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>/+<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'-----END RSA PRIVATE KEY-----\n',
          'server.crt':
'-----BEGIN CERTIFICATE-----\n' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'PxthncRzo7OA6EQyE<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>ZLMk\n' +
'uSBRBM5Jv/9F7QNpodN8TIyA5u96dCwRHvVafD4biT40lPfauPoOTn66g3IOX2Sj\n' +
'-----END CERTIFICATE-----\n'
        },
      });
      /** tslint:enable */

      after(mockfs.restore);

      let config: Config = new Config({
        hostname: 'rupert-test',
        tls: {}
      });

      const rupert = new Rupert(config, getMockLogger());

      expect(rupert.servers.http).to.exist;
      expect(rupert.servers.https).to.exist;
      expect(rupert.url).to.equal('https://rupert-test:8443/');

      rupert.app.all('/', (q: Q, s: S, n: Function) => {
        s.status(200).send('OK');
      });

      request(rupert).then((test: IRupertTest) => {
        test.get('/').expect(200).finish(done);
      }).catch(done);
    });
  });

  describe('plugins', function() {
    it('loads plugins in an app context', function() {
      let config: Config = new Config({hostname: 'rupert-test'});
      let logger: ILogger = getMockLogger();
      let injector = Injector.create([
        bind(Config).toValue(config),
        bind(ILogger).toValue(logger),
        bind(Injector).toFactory(() => injector)
      ]);

      let testRupert: Rupert = null;
      class TestPlugin implements IPlugin {
        public handlers: IPluginHandler[] = [];
        constructor(
          @Inject(Rupert) rupert: Rupert
        ) {
          testRupert = rupert;
        }
      }

      const rupert = new Rupert(config, logger, injector, [TestPlugin]);

      expect(testRupert).to.equal(rupert);
    });

    it('utilizes plugin handlers', function(done) {
      class TestPlugin implements IPlugin {
        public handlers: IPluginHandler[] = [{
          methods: [Methods.GET],
          route: '/plugin',
          handler: (q: Q, s: S) => {
            s.send('OK!');
          }
        }];
      }

      const rupert = Rupert.createApp({log: {level: 'silly'}}, [TestPlugin]);

      requestApp(rupert.app)
        .get('/plugin')
        .expect(200)
        .expect(/OK/)
        .end(done)
        ;
    });
  });
});

<commit_msg>Bump test back to silent.<commit_after>/// <reference path='../../typings/mocha/mocha.d.ts' />
/// <reference path='../../typings/es6-promise/es6-promise.d.ts' />
/// <reference path='../../typings/mock-fs/mock-fs.d.ts' />

import { expect } from '../util/specs';
import { request, requestApp, IRupertTest } from '../util/request';

import * as mockfs from 'mock-fs';

import {
  Request as Q, Response as S
} from 'express';

import {
  Rupert,
  Config,
  IPlugin,
  IPluginHandler,
  Methods,
  ILogger,
  Inject,
  Injector,
  bind
} from '../rupert';

import {
  getMockLogger
} from '../logger/mockLogger';

describe('Rupert App', function() {
  it('creates and injects a new Rupert app', function() {
    const app = Rupert.createApp({foo: 'bar'});
    expect(app.config.find('foo')).to.equal('bar');
  });

  it('has an express application', function(done) {
    const rupert = Rupert.createApp({log: {level: 'silent'}});
    rupert.app.all('/', (q: Q, s: S, n: Function) => {
      s.status(200).send('OK');
    });
    requestApp(rupert.app)
      .get('/')
      .expect(200)
      .expect('set-cookie', /NODE_ENV=development/)
      .end(done)
      ;
  });

  describe('servers', function() {
    it('makes an insecure server', function(done) {
      let config: Config = new Config({hostname: 'rupert-test'});
      const rupert = new Rupert(config, getMockLogger());

      expect(rupert.servers.http).to.exist;
      expect(rupert.servers.https).to.not.exist;
      expect(rupert.url).to.equal('http://rupert-test:8080/');

      rupert.app.all('/', (q: Q, s: S, n: Function) => {
        s.status(200).send('OK');
      });

      request(rupert).then((test: IRupertTest) => {
        test.get('/').expect(200).finish(done);
      }).catch(done);
    });

    it('makes a secure server', function(done) {
      /** tslint:disable */
      mockfs({
        'env/': {
          'server.key':
'-----BEGIN RSA PRIVATE KEY-----\n' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'hBJzZSH<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'cyAwADmrCLbSl4SVQv5aNmLFKci0qQbqJ4hWQB8CgYBYIcuA5W8THJvkfN6kMl3E\n' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'-----END RSA PRIVATE KEY-----\n',
          'server.crt':
'-----BEGIN CERTIFICATE-----\n' +
'<KEY>' +
'VQQ<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'<KEY>' +
'khcw0VBgWU6HaAYQX5PpVd+ySa/IL33A/e6oKJeUqFJ+kKik87SWDfWS9ixQDR4K\n' +
'iRGDCpmP+ivKxa4WSrSOjL71PXoNxwRWFdPMpe535xkcaGjW7lk1rMj/nKOK6q04\n' +
'6PyO4ZpcCF6MuRTr4UN721Ae5unBhZv72RdX6ND6FT9P1mdviiiFimZuqCf8ZLMk\n' +
'uSBRBM5Jv/9F7QNpodN8TIyA5u96dCwRHvVafD4biT40lPfauPoOTn66g3IOX2Sj\n' +
'-----END CERTIFICATE-----\n'
        },
      });
      /** tslint:enable */

      after(mockfs.restore);

      let config: Config = new Config({
        hostname: 'rupert-test',
        tls: {}
      });

      const rupert = new Rupert(config, getMockLogger());

      expect(rupert.servers.http).to.exist;
      expect(rupert.servers.https).to.exist;
      expect(rupert.url).to.equal('https://rupert-test:8443/');

      rupert.app.all('/', (q: Q, s: S, n: Function) => {
        s.status(200).send('OK');
      });

      request(rupert).then((test: IRupertTest) => {
        test.get('/').expect(200).finish(done);
      }).catch(done);
    });
  });

  describe('plugins', function() {
    it('loads plugins in an app context', function() {
      let config: Config = new Config({hostname: 'rupert-test'});
      let logger: ILogger = getMockLogger();
      let injector = Injector.create([
        bind(Config).toValue(config),
        bind(ILogger).toValue(logger),
        bind(Injector).toFactory(() => injector)
      ]);

      let testRupert: Rupert = null;
      class TestPlugin implements IPlugin {
        public handlers: IPluginHandler[] = [];
        constructor(
          @Inject(Rupert) rupert: Rupert
        ) {
          testRupert = rupert;
        }
      }

      const rupert = new Rupert(config, logger, injector, [TestPlugin]);

      expect(testRupert).to.equal(rupert);
    });

    it('utilizes plugin handlers', function(done) {
      class TestPlugin implements IPlugin {
        public handlers: IPluginHandler[] = [{
          methods: [Methods.GET],
          route: '/plugin',
          handler: (q: Q, s: S) => {
            s.send('OK!');
          }
        }];
      }

      const rupert = Rupert.createApp({log: {level: 'silent'}}, [TestPlugin]);

      requestApp(rupert.app)
        .get('/plugin')
        .expect(200)
        .expect(/OK/)
        .end(done)
        ;
    });
  });
});


{'fraction_non_alphanumeric': 0.21909333333333333, 'fraction_numerical': 0.014613333333333334, 'mean_word_length': 2.5772605875619994, 'pattern_counts': {'":': 0, '<': 106, '<?xml version=': 0, '>': 120, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1160056', 'n_tokens_mistral': 3674, 'n_tokens_neox': 3547, 'n_words': 616}