require 'rails_helper'

RSpec.describe FileInfo, type: :model do
  describe "associations" do
    it { is_expected.to belong_to(:releasable) }
  end

  describe ".audio" do
    it "returns only audio files" do
      audio_content_types = %w(audio/mpeg audio/x-aiff audio/aiff audio/wav audio/vnd.wave audio/wav audio/wave audio/x-wav)
      
      audio_files = audio_content_types.map do |content_type|
        create(:file_info, content_type: content_type)
      end

      non_audio_files = [
        create(:file_info, content_type: "video/mp4"),
        create(:file_info, content_type: ""),
      ]

      results = FileInfo.audio

      audio_files.each do |audio_file|
        expect(results).to include(audio_file)
      end

      non_audio_files.each do |non_audio_file|
        expect(results).not_to include(non_audio_file)
      end
    end
  end
end
