Sha256: f5601c24cb5ac297a391b9cce99e569afa7c360c700efe3588b55745b380cb98

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe Spree::Promotion::Rules::AffiliatedPromotionRule, :type => :model do
  before do
    @affiliate = FactoryGirl.create(:affiliate, path: 'corona')
    @affiliated = FactoryGirl.create(:user, email:  Faker::Internet.email, affiliate_code: @affiliate.path)
    @affiliated_order = FactoryGirl.create(:order, :user_id => @affiliated.id)

    @falsy_affiliate = FactoryGirl.create(:affiliate, path: 'victoria')
    @falsy_affiliated = FactoryGirl.create(:user, email:  Faker::Internet.email, affiliate_code: @falsy_affiliate.path)
    @falsy_affiliated_order = FactoryGirl.create(:order, :user_id => @falsy_affiliated.id)

    @user = FactoryGirl.create(:user, email: Faker::Internet.email)
    @organic_order = FactoryGirl.create(:order, :user_id => @user)

    @rule = FactoryGirl.build(:affiliated_promotion_rule)
    @rule.affiliate_list = [@affiliate.id]
  end

  it "is applicable for an order" do
    expect(@rule.applicable?(@affiliated_order)).to be_truthy
  end
  it "is elegible for affiliated user" do
    expect(@rule.eligible?(@affiliated_order)).to be_truthy
  end
  it "is not elegible for organic user" do
    expect(@rule.eligible?(@organic_order)).to be_falsy
  end
  it "is not elegible for falsy affiliated user" do
    expect(@rule.eligible?(@falsy_affiliated_order)).to be_falsy
  end
  it "returns string selected affiliate ids" do
    expect(@rule.affiliate_ids_string).to eq(@affiliate.id.to_s)
  end
  it "accepts string to assign affiliate ids" do
    @rule.affiliate_ids_string = "1"
    expect(@rule.affiliate_ids_string).to eq(@affiliate.id.to_s)
  end
  it "returns an array of affiliate ids" do
    expect(@rule.affiliate_list).to eq([@affiliate.id])
  end
  it "accepts an array to assign affiliate ids" do
    @rule.affiliate_list << [1]
    expect(@rule.affiliate_list).to eq([@affiliate.id])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_reffiliate-2.4.1 spec/models/spree/promotion/rules/affiliated_promotion_rule_spec.rb
spree_reffiliate-2.3.1 spec/models/spree/promotion/rules/affiliated_promotion_rule_spec.rb