<commit_before>'use strict';

import express, { Router } from 'express';
import Framework from './framework';
import assert from 'assert';
import request from 'supertest';

describe('Framework class', () => {
  it('provides config defaults', () => {
    assert(Framework.defaults);
    assert(typeof Framework.defaults === 'function');
    assert(typeof Framework.defaults() === 'object');
  });

  it('provides a config validator', () => {
    assert(Framework.validateConfig);
    assert(typeof Framework.validateConfig === 'function');
  });

  it('provides valid config defaults', () => {
    assert(Framework.validateConfig(Framework.defaults()) === true);
  });

  it('initializes', () => {
    const config = Framework.defaults();
    const framework = new Framework(config, []);

    describe('Framework instance', () => {
      it('maintains a config', () => {
        assert(framework.config);
        assert.deepEqual(framework.config, config);
      });

      it('attaches body parsers', () => {
        assert(framework.router.stack[0].name === 'jsonParser');
        assert(framework.router.stack[1].name === 'urlencodedParser');
      });
    });
  });

  it('loads a plugin', () => {
    // define a plugin

    // eslint-disable-next-line require-jsdoc
    function testMiddleware(req, res, next) {
      res.sendStatus(200);
    }
    const router = Router();
    router.get('/', testMiddleware);
    const plugin = {
      config: {
        base: '/plugin',
      },
      postRouterMiddleware: [],
      preRouterMiddleware: [],
      router,
    };

    // initialize
    const framework = new Framework(Framework.defaults(), [plugin]);

    // create app
    const app = express();
    app.use(framework.app);

    // assertions
    assert.deepEqual(framework.preRouterMiddleware, plugin.preRouterMiddleware);
    assert.deepEqual(
      framework.postRouterMiddleware,
      plugin.postRouterMiddleware,
    );
    return request(app)
      .get(`${Framework.defaults().base}${plugin.config.base}`)
      .expect(200);
  });
});<commit_msg>Add non-root endpoint for Framework base class API test<commit_after>'use strict';

import express, { Router } from 'express';
import Framework from './framework';
import assert from 'assert';
import request from 'supertest';

describe('Framework class', () => {
  it('provides config defaults', () => {
    assert(Framework.defaults);
    assert(typeof Framework.defaults === 'function');
    assert(typeof Framework.defaults() === 'object');
  });

  it('provides a config validator', () => {
    assert(Framework.validateConfig);
    assert(typeof Framework.validateConfig === 'function');
  });

  it('provides valid config defaults', () => {
    assert(Framework.validateConfig(Framework.defaults()) === true);
  });

  it('initializes', () => {
    const config = Framework.defaults();
    const framework = new Framework(config, []);

    describe('Framework instance', () => {
      it('maintains a config', () => {
        assert(framework.config);
        assert.deepEqual(framework.config, config);
      });

      it('attaches body parsers', () => {
        assert(framework.router.stack[0].name === 'jsonParser');
        assert(framework.router.stack[1].name === 'urlencodedParser');
      });
    });
  });

  it('loads a plugin', () => {
    // define a plugin

    // eslint-disable-next-line require-jsdoc
    function testMiddleware(req, res, next) {
      res.sendStatus(200);
    }
    const router = Router();
    router.get('/endpoint', testMiddleware);
    const plugin = {
      config: {
        base: '/plugin',
      },
      postRouterMiddleware: [],
      preRouterMiddleware: [],
      router,
    };

    // initialize
    const framework = new Framework(Framework.defaults(), [plugin]);

    // create app
    const app = express();
    app.use(framework.app);

    // assertions
    assert.deepEqual(framework.preRouterMiddleware, plugin.preRouterMiddleware);
    assert.deepEqual(
      framework.postRouterMiddleware,
      plugin.postRouterMiddleware,
    );
    return request(app)
      .get(`${Framework.defaults().base}${plugin.config.base}/endpoint`)
      .expect(200);
  });
});
{'fraction_non_alphanumeric': 0.16431812753761643, 'fraction_numerical': 0.0038213518032003822, 'mean_word_length': 3.142433234421365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, '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': '881802', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1144, 'n_words': 240}