require 'spec_helper'

describe AffiliateMonthlyPayment do
  let(:partner) {  FactoryGirl.create(:affiliate_partner) }

  it ".index orders DESC" do

    monthly1 = FactoryGirl.create(:affiliate_monthly_payment, closed: true, month: 2, year: 2015, affiliate_partner: partner)
    monthly2 = FactoryGirl.create(:affiliate_monthly_payment, closed: true, month: 3, year: 2015, affiliate_partner: partner)
    monthly3 = FactoryGirl.create(:affiliate_monthly_payment, closed: true, month: 4, year: 2015, affiliate_partner: partner)
    monthly4 = FactoryGirl.create(:affiliate_monthly_payment, closed: true, month: 1, year: 2016, affiliate_partner: partner)

    monthly_payments = AffiliateMonthlyPayment.index(partner.partner_user, {})[0]
    expect(monthly_payments.map(&:year)).to eq [2016, 2015, 2015, 2015]
    expect(monthly_payments.map(&:month)).to eq [1, 4, 3, 2]
  end
end 