require 'spec_helper'

describe MusicSessionHelper, type: :helper do

  describe "facebook_image_for_music_session" do
    it "with band with no photo url" do
      music_session = FactoryGirl.create(:active_music_session, band: FactoryGirl.create(:band), creator: FactoryGirl.create(:user))
      result = helper.facebook_image_for_music_session(music_session.music_session)
      result.include?("/assets/web/logo-256.png").should be true
    end

    it "with band with photo url" do
      music_session = FactoryGirl.create(:active_music_session, band: FactoryGirl.create(:band, large_photo_url: 'abc.png'), creator: FactoryGirl.create(:user))
      result = helper.facebook_image_for_music_session(music_session.music_session)
      result.include?(music_session.band.large_photo_url).should be true
    end

    it "with user with no photo url" do
      music_session = FactoryGirl.create(:active_music_session, creator: FactoryGirl.create(:user))
      result = helper.facebook_image_for_music_session(music_session.music_session)
      result.include?("/assets/web/logo-256.png").should be true
    end

    it "with user with photo url" do
      music_session = FactoryGirl.create(:active_music_session, creator: FactoryGirl.create(:user, large_photo_url: 'abc.png'))
      result = helper.facebook_image_for_music_session(music_session.music_session)
      result.include?("/assets/web/logo-256.png").should be true
    end

    it "with sharer with no photo url" do
      sharer = FactoryGirl.create(:user)
      music_session = FactoryGirl.create(:active_music_session, creator: FactoryGirl.create(:user))
      result = helper.facebook_image_for_music_session(music_session.music_session)
      result.include?("/assets/web/logo-256.png").should be true
    end

    it "with sharer with photo url" do
      sharer = FactoryGirl.create(:user, large_photo_url: 'abc.png')
      music_session = FactoryGirl.create(:active_music_session, creator: FactoryGirl.create(:user, large_photo_url: 'abc.png'))
      result = helper.facebook_image_for_music_session(music_session.music_session)
      result.include?("/assets/web/logo-256.png").should be true
    end
  end

  describe "title_for_music_session" do
    it "with band" do
      music_session = FactoryGirl.create(:active_music_session, band: FactoryGirl.create(:band), creator: FactoryGirl.create(:user))
      result = helper.title_for_music_session(music_session.music_session)
      result.start_with?("LIVE SESSION").should be true
      result.end_with?(music_session.band.name).should be true
    end

    it "with user" do
      music_session = FactoryGirl.create(:active_music_session, creator: FactoryGirl.create(:user))
      result = helper.title_for_music_session(music_session.music_session)
      result.start_with?("LIVE SESSION").should be true
      result.end_with?(music_session.music_session.creator.name).should be true
    end
  end

  describe "additional_member_count" do
    it "no unique users" do
      helper.additional_member_count([], @user).should == ""
    end

    it "has 2 users" do
      user2 = FactoryGirl.create(:user)
      helper.additional_member_count([@user, user2], @user).should == " & #{user2.name}"
    end

    it "has 3 users" do
      user2 = FactoryGirl.create(:user)
      user3 = FactoryGirl.create(:user)
      helper.additional_member_count([@user, user2, user3], @user).should == " & 2 OTHERS"
    end
  end
end
