require 'spec_helper'

describe PaymentHistory do

  let(:user) {FactoryGirl.create(:user)}
  let(:user2) {FactoryGirl.create(:user)}
  let(:jam_track) {FactoryGirl.create(:jam_track)}

  before(:each) do

  end

  describe "index" do
    it "empty" do
      result = PaymentHistory.index(user)
      result[:query].length.should eq(0)
      result[:next].should eq(nil)
    end

    it "one" do
      sale = Sale.create_jam_track_sale(user)
      shopping_cart = ShoppingCart.create(user, jam_track)
      sale_line_item = SaleLineItem.create_from_shopping_cart(sale, shopping_cart, nil, 'some_adjustment_uuid', nil)

      result = PaymentHistory.index(user)
      result[:query].length.should eq(1)
      result[:next].should eq(nil)
    end

    it "user filtered correctly" do
      sale = Sale.create_jam_track_sale(user)
      shopping_cart = ShoppingCart.create(user, jam_track)
      sale_line_item = SaleLineItem.create_from_shopping_cart(sale, shopping_cart, nil, 'some_adjustment_uuid', nil)

      result = PaymentHistory.index(user)
      result[:query].length.should eq(1)
      result[:next].should eq(nil)

      sale2 = Sale.create_jam_track_sale(user2)
      shopping_cart = ShoppingCart.create(user2, jam_track)
      sale_line_item2 = SaleLineItem.create_from_shopping_cart(sale2, shopping_cart, nil, 'some_adjustment_uuid', nil)

      result = PaymentHistory.index(user)
      result[:query].length.should eq(1)
      result[:next].should eq(nil)
    end
  end
end
