From 2bcb95349620937b70ae99bd1571c08197031d15 Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Wed, 28 Sep 2022 09:33:37 +0200 Subject: [PATCH 1/2] group_order_article_spec: add tolerance test --- spec/models/group_order_article_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/models/group_order_article_spec.rb b/spec/models/group_order_article_spec.rb index ddb9158a..b4888df4 100644 --- a/spec/models/group_order_article_spec.rb +++ b/spec/models/group_order_article_spec.rb @@ -46,7 +46,7 @@ describe GroupOrderArticle do let(:article) { create :article, supplier: order.supplier, unit_quantity: 1 } let(:oa) { order.order_articles.create(:article => article) } let(:goa) { create :group_order_article, group_order: go, order_article: oa } - let!(:goaq) { create :group_order_article_quantity, group_order_article: goa, quantity: 4 } + let!(:goaq) { create :group_order_article_quantity, group_order_article: goa, quantity: 4, tolerance: 6} it 'can calculate the result for the distribution strategy "first order first serve"' do res = goa.calculate_result(2) @@ -55,9 +55,13 @@ describe GroupOrderArticle do it 'can calculate the result for the distribution strategy "no automatic distribution"' do FoodsoftConfig[:distribution_strategy] = FoodsoftConfig::DistributionStrategy::NO_AUTOMATIC_DISTRIBUTION - res = goa.calculate_result(2) expect(res).to eq(quantity: 4, tolerance: 0, total: 4) end + + it 'determines tolerance correctly' do + res = goa.calculate_result(6) + expect(res).to eq(quantity: 4, tolerance: 2, total: 6) + end end end From 9b68f7566504a92e0e3cc2407cacd62e0cbfbeb8 Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Thu, 29 Sep 2022 13:36:38 +0200 Subject: [PATCH 2/2] group_order_article_spec: add updates quantity tolerance test --- spec/models/group_order_article_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/models/group_order_article_spec.rb b/spec/models/group_order_article_spec.rb index b4888df4..1e7a2d3a 100644 --- a/spec/models/group_order_article_spec.rb +++ b/spec/models/group_order_article_spec.rb @@ -40,6 +40,15 @@ describe GroupOrderArticle do goa.update_quantities(0, 0) expect(GroupOrderArticle.exists?(goa.id)).to be false end + + it 'updates quantity and tolerance' do + goa.update_quantities(2,2) + goa.update_quantities(1,1) + expect(goa.quantity).to eq(1) + expect(goa.tolerance).to eq(1) + goa.update_quantities(1,2) + expect(goa.tolerance).to eq(2) + end end describe 'distribution strategy' do