foodsoft/spec/models/group_order_spec.rb

53 lines
1.9 KiB
Ruby
Raw Permalink Normal View History

2013-09-18 12:44:41 +02:00
require_relative '../spec_helper'
2013-07-15 18:45:02 +02:00
describe GroupOrder do
2023-02-15 16:06:12 +01:00
let(:ordergroup) { create(:ordergroup) }
let(:user) { create :user, groups: [ordergroup] }
let(:supplier) { create(:supplier, article_count: 3) }
let(:order) { create :order, supplier: supplier }
2013-07-15 18:45:02 +02:00
# the following two tests are currently disabled - https://github.com/foodcoops/foodsoft/issues/158
2013-07-15 18:45:02 +02:00
# it 'needs an order' do
# expect(FactoryBot.build(:group_order, ordergroup: user.ordergroup)).to be_invalid
# end
# it 'needs an ordergroup' do
# expect(FactoryBot.build(:group_order, order: order)).to be_invalid
# end
2013-07-15 18:45:02 +02:00
describe do
2023-02-15 16:06:12 +01:00
let(:go) { create :group_order, order: order, ordergroup: ordergroup }
2013-07-15 18:45:02 +02:00
it 'has zero price initially' do
2013-07-24 22:46:25 +02:00
expect(go.price).to eq(0)
2013-07-15 18:45:02 +02:00
end
end
2023-02-15 16:06:12 +01:00
describe "load data for javascript" do
let(:group_order) { create :group_order, order: order, ordergroup: ordergroup }
let!(:article) { order.articles.first }
let(:order_article) { OrderArticle.find_or_create_by!(order: order, article: article) }
let(:previous_order) { create :order, supplier: supplier, starts: 20.days.ago, ends: 18.days.ago }
let(:previous_group_order) { create :group_order, order: previous_order, ordergroup: ordergroup }
let(:previous_order_article) { OrderArticle.find_or_create_by!(order: previous_order, article: article) }
it "includes data from the last order" do
create :group_order_article,
order_article: previous_order_article,
group_order: previous_group_order,
quantity: 23,
tolerance: 11
order.order_articles.map(&:update_results!)
order.group_orders.map(&:update_price!)
order_article_data = group_order.load_data[:order_articles][order_article.id]
expect(order_article_data[:previous_quantity]).to eq(23)
expect(order_article_data[:previous_tolerance]).to eq(11)
end
end
2013-07-15 18:45:02 +02:00
end