2013-09-18 12:44:41 +02:00
|
|
|
require_relative '../spec_helper'
|
2013-07-15 00:17:07 +02:00
|
|
|
|
|
|
|
describe Order do
|
|
|
|
|
2017-10-12 00:20:30 +02:00
|
|
|
it 'automaticly finishes ended' do
|
|
|
|
create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.from_now
|
|
|
|
create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.ago
|
|
|
|
create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.from_now, end_action: :auto_close
|
|
|
|
order = create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.ago, end_action: :auto_close
|
|
|
|
|
|
|
|
Order.finish_ended!
|
|
|
|
order.reload
|
|
|
|
|
|
|
|
expect(Order.open.count).to eq 3
|
|
|
|
expect(Order.finished.count).to eq 1
|
|
|
|
expect(order).to be_finished
|
|
|
|
end
|
|
|
|
|
2018-06-19 22:12:34 +02:00
|
|
|
it 'sends mail if min_order_quantity has been reached' do
|
|
|
|
create :user, groups: [create(:ordergroup)]
|
|
|
|
create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.ago, end_action: :auto_close_and_send_min_quantity
|
|
|
|
|
|
|
|
Order.finish_ended!
|
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq 1
|
|
|
|
end
|
|
|
|
|
2013-07-15 00:17:07 +02:00
|
|
|
it 'needs a supplier' do
|
2013-09-18 12:44:41 +02:00
|
|
|
expect(build(:order, supplier: nil)).to be_invalid
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'needs order articles' do
|
2013-09-18 12:44:41 +02:00
|
|
|
supplier = create :supplier, article_count: 0
|
|
|
|
expect(build(:order, supplier: supplier)).to be_invalid
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be created' do
|
2013-09-18 12:44:41 +02:00
|
|
|
expect(build(:order, article_count: 1)).to be_valid
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with articles' do
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:order) { create :order }
|
2013-07-15 00:17:07 +02:00
|
|
|
|
2013-07-24 22:46:25 +02:00
|
|
|
it 'is open by default' do expect(order).to be_open end
|
|
|
|
it 'is not finished by default' do expect(order).to_not be_finished end
|
|
|
|
it 'is not closed by default' do expect(order).to_not be_closed end
|
2013-07-15 00:17:07 +02:00
|
|
|
|
|
|
|
it 'has valid order articles' do
|
2014-02-20 15:04:53 +01:00
|
|
|
order.order_articles.each {|oa| expect(oa).to be_valid }
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be finished' do
|
|
|
|
# TODO randomise user
|
|
|
|
order.finish!(User.first)
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(order).to_not be_open
|
|
|
|
expect(order).to be_finished
|
|
|
|
expect(order).to_not be_closed
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be closed' do
|
|
|
|
# TODO randomise user
|
|
|
|
order.finish!(User.first)
|
|
|
|
order.close!(User.first)
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(order).to_not be_open
|
|
|
|
expect(order).to be_closed
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-22 00:33:16 +01:00
|
|
|
describe 'with a default end date' do
|
|
|
|
let(:order) { create :order }
|
|
|
|
before do
|
|
|
|
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=WEEKLY;BYDAY=MO', time: '9:00'}}
|
|
|
|
order.init_dates
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'to have a correct date' do
|
|
|
|
expect(order.ends.to_date).to eq Date.today.next_week.at_beginning_of_week(:monday)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'to have a correct time' do
|
|
|
|
expect(order.ends.strftime('%H:%M')).to eq '09:00'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|