<commit_before>require 'spec_helper'

feature "shopping with variant overrides defined", js: true do
  include AuthenticationWorkflow
  include WebHelper
  include ShopWorkflow
  include CheckoutWorkflow
  include UIComponentHelper

  let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let(:producer) { create(:supplier_enterprise) }
  let(:oc) { create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub]) }
  let(:outgoing_exchange) { oc.exchanges.outgoing.first }
  let(:sm) { hub.shipping_methods.first }
  let(:pm) { hub.payment_methods.first }
  let(:p1) { create(:simple_product, supplier: producer) }
  let(:p2) { create(:simple_product, supplier: producer) }
  let(:v1) { create(:variant, product: p1, price: 11.11, unit_value: 1) }
  let(:v2) { create(:variant, product: p1, price: 22.22, unit_value: 2) }
  let(:v3) { create(:variant, product: p2, price: 33.33, unit_value: 3) }
  let(:v4) { create(:variant, product: p1, price: 44.44, unit_value: 4) }
  let!(:vo1) { create(:variant_override, hub: hub, variant: v1, price: 55.55, count_on_hand: nil) }
  let!(:vo2) { create(:variant_override, hub: hub, variant: v2, count_on_hand: 0) }
  let!(:vo3) { create(:variant_override, hub: hub, variant: v3, count_on_hand: 0) }
  let!(:vo4) { create(:variant_override, hub: hub, variant: v4, count_on_hand: 3) }
  let(:ef) { create(:enterprise_fee, enterprise: hub, fee_type: 'packing', calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)) }

  before do
    outgoing_exchange.variants = [v1, v2, v3, v4]
    outgoing_exchange.enterprise_fees << ef
    sm.calculator.preferred_amount = 0
    visit shop_path
    click_link hub.name
  end

  describe "viewing products" do
    it "shows the overridden price" do
      page.should_not have_price "$12.22" # $11.11 + 10% fee
      page.should have_price "$61.11"
    end

    it "looks up stock from the override" do
      # Product should appear but one of the variants is out of stock
      page.should_not have_content v2.options_text

      # Entire product should not appear - no stock<commit_msg>Fix shops path for spec<commit_after>require 'spec_helper'

feature "shopping with variant overrides defined", js: true do
  include AuthenticationWorkflow
  include WebHelper
  include ShopWorkflow
  include CheckoutWorkflow
  include UIComponentHelper

  let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let(:producer) { create(:supplier_enterprise) }
  let(:oc) { create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub]) }
  let(:outgoing_exchange) { oc.exchanges.outgoing.first }
  let(:sm) { hub.shipping_methods.first }
  let(:pm) { hub.payment_methods.first }
  let(:p1) { create(:simple_product, supplier: producer) }
  let(:p2) { create(:simple_product, supplier: producer) }
  let(:v1) { create(:variant, product: p1, price: 11.11, unit_value: 1) }
  let(:v2) { create(:variant, product: p1, price: 22.22, unit_value: 2) }
  let(:v3) { create(:variant, product: p2, price: 33.33, unit_value: 3) }
  let(:v4) { create(:variant, product: p1, price: 44.44, unit_value: 4) }
  let!(:vo1) { create(:variant_override, hub: hub, variant: v1, price: 55.55, count_on_hand: nil) }
  let!(:vo2) { create(:variant_override, hub: hub, variant: v2, count_on_hand: 0) }
  let!(:vo3) { create(:variant_override, hub: hub, variant: v3, count_on_hand: 0) }
  let!(:vo4) { create(:variant_override, hub: hub, variant: v4, count_on_hand: 3) }
  let(:ef) { create(:enterprise_fee, enterprise: hub, fee_type: 'packing', calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)) }

  before do
    outgoing_exchange.variants = [v1, v2, v3, v4]
    outgoing_exchange.enterprise_fees << ef
    sm.calculator.preferred_amount = 0
    visit shops_path
    click_link hub.name
  end

  describe "viewing products" do
    it "shows the overridden price" do
      page.should_not have_price "$12.22" # $11.11 + 10% fee
      page.should have_price "$61.11"
    end

    it "looks up stock from the override" do
      # Product should appear but one of the variants is out of stock
      page.should_not have_content v2.options_text

      # Entire product should not appear - no stock
{'fraction_non_alphanumeric': 0.12741222971402, 'fraction_numerical': 0.031155545222041385, 'mean_word_length': 4.6980132450331125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4040964', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1456, 'n_words': 383}