<commit_before>/* global describe, it, xit */
/* jslint node: true, esnext: true */

"use strict";

const chai = require('chai'),
  assert = chai.assert,
  expect = chai.expect,
  should = chai.should(),
  mochaInterceptorTest = require('kronos-test-interceptor').mochaInterceptorTest,
  llm = require('loglevel-mixin'),
  Interceptor = require('../index').Interceptor,
  TimeLoggerInterceptor = require('../index').TimeLoggerInterceptor,
  TimeoutInterceptor = require('../index').TimeoutInterceptor,
  LimitingInterceptor = require('../index').LimitingInterceptor;

const logger = {};
llm.defineLogLevelProperties(logger, llm.defaultLogLevels, llm.defaultLogLevels);


/* simple owner with name */
function dummyEndpoint(name) {
  return {get name() {
      return name;
    },
    toString() {
      return this.name;
    },
    "step": logger
  };
}

describe('interceptors', () => {
  const ep = dummyEndpoint('ep');

  mochaInterceptorTest(Interceptor, ep, {}, "none");


  mochaInterceptorTest(TimeLoggerInterceptor, ep, {}, "logger-request-time", itc => {});


  const REQUEST_LIMIT = 1;

  mochaInterceptorTest(LimitingInterceptor, ep, {
    limit: REQUEST_LIMIT
  }, "request-limit", (itc, withConfig) => {
    it('has limit', () => assert.equal(itc.limit, REQUEST_LIMIT));

    itc.connected = dummyEndpoint('ep');

    // request value is the timeout
    itc.connected.receive = request =>
      new Promise((fullfilled, rejected) =>
        setTimeout(() => fullfilled(request), 200));

    xit('sending lots of request', done => {
      let i;
      for (i = 0; i < REQUEST_LIMIT + 1; i++) {
        const response = itc.receive(i).then(
          f => {<commit_msg>test(interceptor): Add a test to get the interceptor type<commit_after>/* global describe, it, xit */
/* jslint node: true, esnext: true */

"use strict";

const chai = require('chai'),
  assert = chai.assert,
  expect = chai.expect,
  should = chai.should(),
  mochaInterceptorTest = require('kronos-test-interceptor').mochaInterceptorTest,
  llm = require('loglevel-mixin'),
  Interceptor = require('../index').Interceptor,
  TimeLoggerInterceptor = require('../index').TimeLoggerInterceptor,
  TimeoutInterceptor = require('../index').TimeoutInterceptor,
  LimitingInterceptor = require('../index').LimitingInterceptor;

const logger = {};
llm.defineLogLevelProperties(logger, llm.defaultLogLevels, llm.defaultLogLevels);


/* simple owner with name */
function dummyEndpoint(name) {
  return {get name() {
      return name;
    },
    toString() {
      return this.name;
    },
    "step": logger
  };
}

describe('interceptors', () => {

  it('get type', done => {
    assert.equal("none", Interceptor.type);
    done();
  });


  const ep = dummyEndpoint('ep');

  mochaInterceptorTest(Interceptor, ep, {}, "none");


  mochaInterceptorTest(TimeLoggerInterceptor, ep, {}, "logger-request-time", itc => {});


  const REQUEST_LIMIT = 1;

  mochaInterceptorTest(LimitingInterceptor, ep, {
    limit: REQUEST_LIMIT
  }, "request-limit", (itc, withConfig) => {
    it('has limit', () => assert.equal(itc.limit, REQUEST_LIMIT));

    itc.connected = dummyEndpoint('ep');

    // request value is the timeout
    itc.connected.receive = request =>
      new Promise((fullfilled, rejected) =>
        setTimeout(() => fullfilled(request), 200));

    xit('sending lots of request', done => {
      let i;
      for (i = 0; i < REQUEST_LIMIT + 1; i++) {
        const response = itc.receive(i).then(
          f => {
{'fraction_non_alphanumeric': 0.15846681922196795, 'fraction_numerical': 0.003432494279176201, 'mean_word_length': 3.6939597315436243, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 22, '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': '2235114', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1085, 'n_words': 238}