2014-11-22 00:33:16 +01:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
feature Order, js: true do
|
2014-11-22 00:33:16 +01:00
|
|
|
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
|
|
|
let(:article) { create :article, unit_quantity: 1 }
|
|
|
|
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id] } # need to ref article
|
|
|
|
let(:go1) { create :group_order, order: order }
|
|
|
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
|
|
|
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
before { login admin }
|
2014-11-22 00:33:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can get to the new order page' do
|
|
|
|
article.supplier
|
|
|
|
visit orders_path
|
|
|
|
click_link_or_button I18n.t('orders.index.new_order')
|
|
|
|
click_link_or_button order.name
|
|
|
|
expect(page).to have_text I18n.t('orders.new.title')
|
|
|
|
expect(page).to have_text article.name
|
|
|
|
end
|
2014-11-22 00:33:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'fills in the end date with a schedule' do
|
|
|
|
FoodsoftConfig[:time_zone] = 'UTC'
|
|
|
|
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00'}}
|
|
|
|
visit new_order_path(supplier_id: article.supplier.id)
|
|
|
|
expect(page).to have_text I18n.t('orders.new.title')
|
|
|
|
expect(find_field('order_ends_time_value').value).to eq '12:00'
|
|
|
|
expect(find_field('order_ends_date_value').value).to eq Date.today.next_month.at_beginning_of_month.strftime('%Y-%m-%d')
|
|
|
|
end
|
2014-11-22 00:33:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can create a new order' do
|
2017-04-01 15:12:05 +02:00
|
|
|
visit new_order_path(supplier_id: article.supplier_id)
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to have_text I18n.t('orders.new.title')
|
|
|
|
find('input[type="submit"]').click
|
2017-04-01 15:12:05 +02:00
|
|
|
expect(page).to have_selector('.alert-success')
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(Order.count).to eq 1
|
|
|
|
expect(Order.first.supplier).to eq article.supplier
|
|
|
|
end
|
2014-11-22 00:33:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can close an order' do
|
|
|
|
setup_and_close_order
|
|
|
|
expect(order).to be_finished
|
|
|
|
expect(page).to_not have_link I18n.t('orders.index.action_end')
|
|
|
|
expect(oa.units_to_order).to eq 1
|
2014-11-22 00:33:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup_and_close_order
|
|
|
|
# have at least something ordered
|
|
|
|
goa1.update_quantities 1, 0
|
|
|
|
oa.update_results!
|
|
|
|
# and close the order
|
|
|
|
visit orders_path
|
2019-10-28 09:39:32 +01:00
|
|
|
accept_confirm do
|
|
|
|
click_link_or_button I18n.t('orders.index.action_end')
|
|
|
|
end
|
2017-04-01 15:12:05 +02:00
|
|
|
expect(page).to have_selector('.alert-success')
|
2014-11-22 00:33:16 +01:00
|
|
|
order.reload
|
|
|
|
oa.reload
|
|
|
|
end
|
|
|
|
end
|