<commit_before># frozen_string_literal: true

require 'spec_helper'

RSpec.describe EsaFeeder::UseCases::Feed do
  let(:esa_client) { double('esa client') }

  let(:templates) { build_list(:esa_template, 2) }
  let(:posts) { build_list(:esa_post, 2) }

  let(:expected) do
    [
      { templates[0].number => posts[0].number },
      { templates[1].number => posts[1].number }
    ]
  end

  subject do
    described_class.new(esa_client, slack_client).call(tag: 'feed_mon')
  end

  before do
    expect(esa_client).to receive(:find_templates)
      .with('feed_mon').once
      .and_return(templates)
    expect(esa_client).to receive(:create_from_template)
      .with(templates[0], 'esa_bot').once
      .and_return(posts[0])
    expect(esa_client).to receive(:create_from_template)
      .with(templates[1], 'esa_bot').once
      .and_return(posts[1])
  end

  context 'notifier provided' do
    let(:slack_client) { double('slack client') }
    it 'create posts and notify' do
      expect(slack_client).to receive(:notify_creation).exactly(templates.count)
      expect(subject).to eq(expected)
    end
  end

  context 'notifier not provided' do
    let(:slack_client) { nil }<commit_msg>Feedの引数変えたのでspecも修正<commit_after># frozen_string_literal: true

require 'spec_helper'

RSpec.describe EsaFeeder::UseCases::Feed do
  let(:esa_client) { double('esa client') }

  let(:templates) { build_list(:esa_template, 2) }
  let(:posts) { build_list(:esa_post, 2) }

  let(:expected) do
    [
      { templates[0].number => posts[0].number },
      { templates[1].number => posts[1].number }
    ]
  end

  subject do
    described_class.new(esa_client, slack_client).call('feed_mon', 'esa_bot')
  end

  before do
    expect(esa_client).to receive(:find_templates)
      .with('feed_mon').once
      .and_return(templates)
    expect(esa_client).to receive(:create_from_template)
      .with(templates[0], 'esa_bot').once
      .and_return(posts[0])
    expect(esa_client).to receive(:create_from_template)
      .with(templates[1], 'esa_bot').once
      .and_return(posts[1])
  end

  context 'notifier provided' do
    let(:slack_client) { double('slack client') }
    it 'create posts and notify' do
      expect(slack_client).to receive(:notify_creation).exactly(templates.count)
      expect(subject).to eq(expected)
    end
  end

  context 'notifier not provided' do
    let(:slack_client) { nil }
{'fraction_non_alphanumeric': 0.13798836242726517, 'fraction_numerical': 0.00831255195344971, 'mean_word_length': 3.9022403258655802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4605718', 'n_tokens_mistral': 827, 'n_tokens_neox': 804, 'n_words': 146}