require 'spec_helper'

describe 'Fixxpert show customer' do

  it 'should show customer' do
    fixxpert = create :fixxpert
    customer = create :customer
    other_fixxpert = create :fixxpert
    # Need at least one comment for access
    comment = create :comment, user: customer, for_user: fixxpert
    login_as_user fixxpert

    click_link 'fixxpert_customers_link'
    click_link "show_contacted_customer_#{customer.id}"

    within '#comments' do
      page.should have_content comment.text
    end
  end

  it 'should show all the interactions between the user and the fixxpert' do
    fixxpert = create :fixxpert
    customer = create :customer
    other_fixxpert = create :fixxpert
    comment_1 = create :comment, user: customer, for_user: fixxpert, text: 'For customer to fixxpert'
    comment_2 = create :comment, user: fixxpert, for_user: customer, text: 'For fixxpert to customer'

    other_comment_1 = create :comment, user: customer, for_user: other_fixxpert, text: 'For customer to other fixxpert'
    other_comment_2 = create :comment, user: other_fixxpert, for_user: customer, text: 'For other fixxpert to customer'

    expert_session = create :expert_session, fixxpert: fixxpert, customer: customer
    invoice = create :invoice, expert_session: expert_session, customer: customer, fixxpert: fixxpert

    login_as_user fixxpert

    click_link 'fixxpert_customers_link'
    click_link "show_contacted_customer_#{customer.id}"

    within '#comments' do
      page.should have_content comment_1.text
      page.should have_content comment_2.text

      page.should_not have_content other_comment_1.text
      page.should_not have_content other_comment_2.text
    end

    within '#expert_sessions' do
      page.should have_content expert_session.date.strftime("%m-%d-%Y")
    end

    within '#invoices' do
      page.should have_content I18n.l invoice.created_at.to_date
    end
  end
end
