2013-09-18 12:44:41 +02:00
|
|
|
require_relative '../spec_helper'
|
2013-07-24 04:04:59 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
feature 'product distribution', js: true do
|
2023-05-12 13:01:12 +02:00
|
|
|
let(:ftt) { create(:financial_transaction_type) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:user_a) { create(:user, groups: [create(:ordergroup)]) }
|
|
|
|
let(:user_b) { create(:user, groups: [create(:ordergroup)]) }
|
|
|
|
let(:supplier) { create(:supplier) }
|
|
|
|
let(:article) { create(:article, supplier: supplier, unit_quantity: 5) }
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:order) { create(:order, supplier: supplier, article_ids: [article.id]) }
|
2013-07-24 04:04:59 +02:00
|
|
|
let(:oa) { order.order_articles.first }
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
before do
|
2013-07-25 13:08:38 +02:00
|
|
|
# make sure users have enough money to order
|
2015-04-24 15:19:57 +02:00
|
|
|
[user_a, user_b].each do |user|
|
|
|
|
ordergroup = Ordergroup.find(user.ordergroup.id)
|
2017-03-04 14:15:18 +01:00
|
|
|
ordergroup.add_financial_transaction! 5000, 'for ordering', admin, ftt
|
2013-07-24 04:04:59 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
order # make sure order is referenced
|
2013-07-24 04:04:59 +02:00
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'agrees to documented example' do
|
|
|
|
# gruppe a bestellt 2(3), weil sie auf jeden fall was von x bekommen will
|
|
|
|
login user_a
|
|
|
|
visit new_group_order_path(order_id: order.id)
|
2016-02-18 22:34:06 +01:00
|
|
|
scrolldown
|
2015-04-24 15:19:57 +02:00
|
|
|
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
|
|
|
3.times { find("[data-increase_tolerance='#{oa.id}']").click }
|
|
|
|
find('input[type=submit]').click
|
|
|
|
expect(page).to have_selector('body')
|
|
|
|
# gruppe b bestellt 2(0)
|
|
|
|
login user_b
|
|
|
|
visit new_group_order_path(order_id: order.id)
|
2016-02-18 22:34:06 +01:00
|
|
|
scrolldown
|
2015-04-24 15:19:57 +02:00
|
|
|
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
|
|
|
find('input[type=submit]').click
|
|
|
|
expect(page).to have_selector('body')
|
|
|
|
# gruppe a faellt ein dass sie doch noch mehr braucht von x und aendert auf 4(1).
|
|
|
|
login user_a
|
|
|
|
visit edit_group_order_path(id: order.group_order(user_a.ordergroup).id, order_id: order.id)
|
2016-02-18 22:34:06 +01:00
|
|
|
scrolldown
|
2015-04-24 15:19:57 +02:00
|
|
|
2.times { find("[data-increase_quantity='#{oa.id}']").click }
|
|
|
|
2.times { find("[data-decrease_tolerance='#{oa.id}']").click }
|
|
|
|
find('input[type=submit]').click
|
|
|
|
expect(page).to have_selector('body')
|
|
|
|
# die zuteilung
|
|
|
|
order.finish!(admin)
|
|
|
|
oa.reload
|
|
|
|
# Endstand: insg. Bestellt wurden 6(1)
|
|
|
|
expect(oa.quantity).to eq(6)
|
|
|
|
expect(oa.tolerance).to eq(1)
|
|
|
|
# Gruppe a bekommt 3 einheiten.
|
2023-05-12 13:01:12 +02:00
|
|
|
goa_a = oa.group_order_articles.joins(:group_order).where(group_orders: { ordergroup_id: user_a.ordergroup.id }).first
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(goa_a.result).to eq(3)
|
|
|
|
# gruppe b bekommt 2 einheiten.
|
2023-05-12 13:01:12 +02:00
|
|
|
goa_b = oa.group_order_articles.joins(:group_order).where(group_orders: { ordergroup_id: user_b.ordergroup.id }).first
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(goa_b.result).to eq(2)
|
|
|
|
end
|
2013-07-24 04:04:59 +02:00
|
|
|
end
|