<commit_before>'use strict';

const expect = require('chai').expect;
const request = require('request-promise');
const TelegramBot = require('node-telegram-bot-api');
//const gameHandler = require('../../../lib/handlers/handler.game');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const TOKEN = process.env.TEST_TELEGRAM_TOKEN;
if (!TOKEN) {
  throw new Error('Bot token not provided');
}

describe('handler.game', function gameHandlerSuite() {
  describe('#gameCreation', function gameCreationSuite() {
    it('should extract the hours and minutes from message "/dota at 1930"', function test(done) {
      const bot = new TelegramBot(TOKEN, { webHook: true });
      bot.onText(/^\/dog?t[ea]s?(?:@\w*)?\b\s*(?=(?:.*\b(\d{2})[:.;-]?(\d{2})\b)?)(.+)?/i, (msg, match) => {
        bot._WebHook._webServer.close();
        try {
          expect(match[1]).to.equal('19');
          expect(match[2]).to.equal('30');
          done();
        } catch (e) {
          done(e);
        }
      });
      const url = `http://localhost:8443/bot${TOKEN}`;
      request({
        url,
        method: 'POST',
        json: true,
        headers: {
          'content-type': 'application/json',
        },
        body: { update_id: 0, message: { text: '/dota at 1930' } }
      });
    });

    it('should call `onText` callback on match', function test(done) {
      const bot = new TelegramBot(TOKEN, { webHook: true });
      bot.onText(/\/echo (.+)/, (msg, match) => {
        bot._WebHook._webServer.close();
        expect(match[1]).to.equal('ECHO ALOHA');
        done();
      });
      const url = `http://localhost:8443/bot${TOKEN}`;
      request({
        url,
        method: 'POST',
        json: true,
        headers: {
          'content-type': 'application/json',
        },
        body: { update_id: 0, message: { text: '/echo ECHO ALOHA' } }
      });
    });
  });
});<commit_msg>Simplified test<commit_after>'use strict';

const expect = require('chai').expect;
const request = require('request-promise');
const TelegramBot = require('node-telegram-bot-api');
//const gameHandler = require('../../../lib/handlers/handler.game');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const TOKEN = process.env.TEST_TELEGRAM_TOKEN;
if (!TOKEN) {
  throw new Error('Bot token not provided');
}

// This should be extracted into another file and imported
const sendMessage = (bot, message) => {
  bot.textRegexpCallbacks.forEach((reg) => {
    const result = reg.regexp.exec(message.text);
    if (result) {
      reg.callback(message, result);
    }
  });
};

describe('handler.game', function gameHandlerSuite() {
  describe('#gameCreation', function gameCreationSuite() {
    // Example from the node-telegram-bot-api github project
    it('should call `onText` callback on match', function test(done) {
      const bot = new TelegramBot(TOKEN, { webHook: true });
      bot.onText(/\/echo (.+)/, (msg, match) => {
        bot._WebHook._webServer.close();
        expect(match[1]).to.equal('ECHO ALOHA');
        done();
      });
      const url = `http://localhost:8443/bot${TOKEN}`;
      request({
        url,
        method: 'POST',
        json: true,
        headers: {
          'content-type': 'application/json',
        },
        body: { update_id: 0, message: { text: '/echo ECHO ALOHA' } }
      });
    });

    // My re-working of their example
    it('should extract the hours and minutes from message "/dota at 1930"', function test(done) {
      const bot = new TelegramBot(TOKEN);
      bot.onText(/^\/dog?t[ea]s?(?:@\w*)?\b\s*(?=(?:.*\b(\d{2})[:.;-]?(\d{2})\b)?)(.+)?/i, (msg, match) => {
        try {
          expect(match[1]).to.equal('19');
          expect(match[2]).to.equal('30');
          done();
        } catch (e) {
          done(e);
        }
      });
      sendMessage(bot, { text: '/dota at 1930' });
    });

  });
});
{'fraction_non_alphanumeric': 0.19323172306897443, 'fraction_numerical': 0.013174890209248256, 'mean_word_length': 2.5555555555555554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '237345', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1261, 'n_words': 263}