<commit_before>const api = require('../app/api');

describe('api', () => {
  describe('createMap', () => {
    let stub = () => { /* just an empty stub function */ };
    let processor = {getFenBase: stub};
    let res = {};
    it('maps /api/fenbase and related requestProcess', () => {
      spyOn(processor, 'getFenBase');
      const map = api.createMap(processor);
      map({url: 'http://localhost:9966/api/fenbase'}, res);
      expect(processor.getFenBase).toHaveBeenCalled();
    });
  });
});
<commit_msg>tests for API module added<commit_after>const api = require('../app/api');
const http = require('http');

describe('api', () => {
  let stub = () => { /* just an empty stub function */ };
  let processor = {getFenBase: stub, ping: stub, getUsersCount: stub, analyze: stub, getBase: stub,
    default: stub
  };
  let port = 112233;

  describe('createMap', () => {
    let res = {};
    let map;
    beforeEach(() => {
      spyOn(processor, 'getFenBase');
      spyOn(processor, 'ping');
      spyOn(processor, 'getUsersCount');
      spyOn(processor, 'getBase');
      spyOn(processor, 'analyze');
      spyOn(processor, 'default');
      map = api.createMap(processor);
    });
    it('maps /api/fenbase and related requestProcess', () => {
      map({url: '/api/fenbase'}, res);
      expect(processor.getFenBase).toHaveBeenCalled();
    });
    it('maps /api/ping', () => {
      map({url: '/api/ping'}, res);
      expect(processor.ping).toHaveBeenCalled();
    });
    it('maps /api/userscount', () => {
      map({url: '/api/userscount'}, res);
      expect(processor.getUsersCount).toHaveBeenCalled();
    });
    it('maps /api/analyze', () => {
      map({url: '/api/analyze'}, res);
      expect(processor.analyze).toHaveBeenCalled();
    });
    it('maps /api/base', () => {
      map({url: '/api/base'}, res);
      expect(processor.getBase).toHaveBeenCalled();
    });
    it('maps to default in case of unsupported api call', () => {
      map({url: '/api/unsupported'}, res);
      expect(processor.default).toHaveBeenCalled();
    });
  });
  describe('register', () => {
    it('creates http server on a specified port', () => {
      const server = {listen: stub};
      spyOn(http, 'createServer').and.returnValue(server);
      spyOn(api, 'createMap').and.stub();
      spyOn(server, 'listen');
      api.register(processor, port);
      expect(http.createServer).toHaveBeenCalled();
      expect(server.listen).toHaveBeenCalledWith(port);
    });
  });
});

{'fraction_non_alphanumeric': 0.19887730553327987, 'fraction_numerical': 0.00400962309542903, 'mean_word_length': 3.1376451077943615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7510453', 'n_tokens_mistral': 790, 'n_tokens_neox': 797, 'n_words': 155}