<commit_before>require 'spec_helper'

RSpec.feature 'Admin Stock Locations', :js do
  let(:vendor) { create(:vendor) }
  let!(:user) { create(:user, vendors: [vendor]) }
  let!(:stock_location) { create(:stock_location, name: 'Test') }

  context 'for user with admin role' do
    context 'index' do
      stub_authorization!

      scenario 'displays all stock locations' do
        visit spree.admin_stock_locations_path
        expect(page).to have_selector('tr', count: 3)
      end
    end
  end

  context 'for user with vendor' do
    before(:each) do
      login_as(user, scope: :spree_user)
      visit spree.admin_stock_locations_path
    end

    context 'index' do
      scenario 'displays only vendor stock location' do
        expect(page).to have_selector('tr', count: 2)
      end
    end

    context 'stock movements' do
      scenario 'displays stock movements for vendor stock location' do
        click_on 'Stock Movements'
        expect(page).to have_text 'Stock Movements for Test vendor'
      end
    end

    context 'create' do
      scenario 'can create a new stock location' do
        click_link 'New Stock Location'
        expect(current_path).to eq spree.new_admin_stock_location_path

        fill_in 'stock_location_name', with: 'Vendor stock location'

        click_button 'Create'

        expect(page).to have_text 'successfully created!'
        expect(current_path).to eq spree.admin_stock_locations_path
        expect(Spree::StockLocation.last.vendor_id).to eq vendor.id
      end
    end<commit_msg>Add spec for creating stock movements by vendor<commit_after>require 'spec_helper'

RSpec.feature 'Admin Stock Locations', :js do
  let(:vendor) { create(:vendor) }
  let!(:product) { create(:product, vendor_id: vendor.id, name: 'Test') }
  let!(:user) { create(:user, vendors: [vendor]) }
  let!(:stock_location) { create(:stock_location, name: 'Test') }

  context 'for user with admin role' do
    context 'index' do
      stub_authorization!

      scenario 'displays all stock locations' do
        visit spree.admin_stock_locations_path
        expect(page).to have_selector('tr', count: 3)
      end
    end
  end

  context 'for user with vendor' do
    before(:each) do
      login_as(user, scope: :spree_user)
      visit spree.admin_stock_locations_path
    end

    context 'index' do
      scenario 'displays only vendor stock location' do
        expect(page).to have_selector('tr', count: 2)
      end
    end

    context 'stock movements' do
      scenario 'displays stock movements for vendor stock location' do
        click_on 'Stock Movements'
        expect(page).to have_text 'Stock Movements for Test vendor'
      end

      scenario 'can create a new stock movement for vendor stock location' do
        click_on 'Stock Movements'
        click_on 'New Stock Movement'
        expect(current_path).to eq spree.new_admin_stock_location_stock_movement_path(vendor.stock_locations.first)

        fill_in 'stock_movement_quantity', with: 5
        fill_in 'stock_movement_stock_item_id', with: 1

        click_button 'Create'

        expect(page).to have_text 'successfully created!'
        expect(Spree::StockMovement.count).to eq 1
      end
    end

    context 'create' do
      scenario 'can create a new stock location' do
        click_link 'New Stock Location'
        expect(current_path).to eq spree.new_admin_stock_location_path

        fill_in 'stock_location_name', with: 'Vendor stock location'

        click_button 'Create'

        expect(page).to have_text 'successfully created!'
        expect(current_path).to eq spree.admin_stock_locations_path
        expect(Spree::StockLocation.last.vendor_id).to eq vendor.id
      end
    end
{'fraction_non_alphanumeric': 0.0848777867311308, 'fraction_numerical': 0.0018802041364491002, 'mean_word_length': 3.101321585903084, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6606768', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1082, 'n_words': 326}