# frozen_string_literal: true

require 'test_helper'
require 'ox'

require_relative '../support/command_results'

describe 'article_fixture_gen --smtp-text' do
  let(:cmdline) do
    "article_fixture_gen --article-count=#{article_count} " \
      "--smtp-count=#{smtp_count} --smtp-text=#{smtp_text}"
  end
  let(:article_count) { 2 }
  let(:smtp_count) { 2 }
  let(:smtp_text) { 'SMTPTEXTHERE' }
  let(:results) { CommandResults.call(cmdline) }

  it 'produces no error output' do
    expect(results.errors).must_be :empty?
  end

  describe 'produces output such that each article has' do
    let(:article_count) { 20 }
    let(:smtp_count) { 8 }

    let(:article_strings) { results.output.join.split("\n\n") }

    it 'the correct text in each smtp marker-tag pair' do
      pattern = %r{<a href="" id="#{smtp_text}-\d+?"\/>}
      actual = article_strings.map do |article_string|
        article_string.scan(pattern).count == smtp_count
      end
      mismatches = actual.reject { |value| value == true }
      expect(mismatches).must_be :empty?
    end
  end # describe 'produces output such that each article has'
end
