# frozen_string_literal: true

require 'rails_helper'

describe BlankContract do
  describe 'rendering the contract' do
    let(:project) { build(:project) }

    it 'works with appearance releases' do
      appearance_release = create(:appearance_release_with_contract_template, project: project, person_name: 'Jane Doe')

      result = render_contract_html_for(appearance_release)

      expect(result).not_to be_nil
    end

    it 'works with talent releases' do
      talent_release = create(:talent_release_with_contract_template, project: project, person_name: 'Jane Doe')

      result = render_contract_html_for(talent_release)

      expect(result).not_to be_nil
    end

    it 'works with location releases' do
      location_release = create(:location_release_with_contract_template, project: project, person_name: 'Jane Doe')

      result = render_contract_html_for(location_release)

      expect(result).not_to be_nil
    end

    it 'works with material releases' do
      material_release = create(:material_release_with_contract_template, project: project, person_name: 'Jane Doe')

      result = render_contract_html_for(material_release)

      expect(result).not_to be_nil
    end

    it 'renders a QR code, serial number and warning not to copy' do
      material_release = create(:material_release_with_contract_template, project: project, person_name: 'Jane Doe')
      result = render_contract_html_for(material_release)

      expect(result).to include 'DO NOT COPY'
    end
  end

  private

  # Reaching into the object's internals a bit here to avoid generating a PDF unnecessarily
  def render_contract_html_for(releasable)
    BlankContract.new(releasable).send(:as_html)
  end
end
