<commit_before>require_relative 'test-common'

require 'cinch/plugins/tyrant-faction-chat'

describe Cinch::Plugins::TyrantFactionChat do
  include Cinch::Test

  let(:bot) {
    make_bot(Cinch::Plugins::TyrantFactionChat) { |c|
      self.loggers.stub('debug') { nil }
    }
  }

  before :each do
    @conn = FakeConnection.new
    @tyrant = Tyrants.get_fake('testplayer', @conn)
    expect(Tyrants).to receive(:get).with('testplayer').and_return(@tyrant)
    @conn.respond('getFactionMessages', '', {'messages' => [
      {'post_id' => '60', 'message' => 'm1', 'user_id' => '1'},
    ]})
    @chan = FakeChannel.new
    bot.plugins[0].stub(:Channel).and_return(@chan)
  end

  it 'makes a test bot' do
    expect(bot).to be_a Cinch::Bot
  end

  it 'does nothing if there are no new messages' do
    @conn.respond('getNewFactionMessages', 'last_post=60', {'messages' => []})
    bot.plugins[0].get_timers[0].fire!
    expect(@chan.messages).to be == []
  end

  it 'does nothing if there are no new messages' do
    @conn.respond('getNewFactionMessages', 'last_post=60', {'messages' => [
      {'post_id' => '61', 'message' => 'm2', 'user_id' => '2'},
    ]})
    expect(Tyrant).to receive(:get_name_of_id).with('2').and_return('usertwo')
    bot.plugins[0].get_timers[0].fire!
    expect(@chan.messages).to be == ['[FACTION] usertwo: m2']
  end

  # TODO: !chat (on|off)
end<commit_msg>spec: Ensure TyrantFactionChat updates last_post<commit_after>require_relative 'test-common'

require 'cinch/plugins/tyrant-faction-chat'

describe Cinch::Plugins::TyrantFactionChat do
  include Cinch::Test

  let(:bot) {
    make_bot(Cinch::Plugins::TyrantFactionChat) { |c|
      self.loggers.stub('debug') { nil }
    }
  }

  before :each do
    @conn = FakeConnection.new
    @tyrant = Tyrants.get_fake('testplayer', @conn)
    expect(Tyrants).to receive(:get).with('testplayer').and_return(@tyrant)
    @conn.respond('getFactionMessages', '', {'messages' => [
      {'post_id' => '60', 'message' => 'm1', 'user_id' => '1'},
    ]})
    @chan = FakeChannel.new
    bot.plugins[0].stub(:Channel).and_return(@chan)
  end

  it 'makes a test bot' do
    expect(bot).to be_a Cinch::Bot
  end

  it 'does nothing if there are no new messages' do
    @conn.respond('getNewFactionMessages', 'last_post=60', {'messages' => []})
    bot.plugins[0].get_timers[0].fire!
    expect(@chan.messages).to be == []
  end

  context 'with new messages' do
    before :each do
      @conn.respond('getNewFactionMessages', 'last_post=60', {'messages' => [
        {'post_id' => '61', 'message' => 'm2', 'user_id' => '2'},
      ]})
      expect(Tyrant).to receive(:get_name_of_id).with('2').and_return('usertwo')
      bot.plugins[0].get_timers[0].fire!
    end

    it 'posts new messages' do
      expect(@chan.messages).to be == ['[FACTION] usertwo: m2']
    end

    it 'updates last post before doing next poll' do
      @conn.respond('getNewFactionMessages', 'last_post=61', {'messages' => []})
      bot.plugins[0].get_timers[0].fire!
    end
  end

  # TODO: !chat (on|off)
end
{'fraction_non_alphanumeric': 0.17875816993464053, 'fraction_numerical': 0.013725490196078431, 'mean_word_length': 3.82807570977918, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1664424', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1096, 'n_words': 212}