Add additional model and integration tests

This commit adds new tests for a better coverage.

integration/
  * home
  * supplier

models/
  * article
  * delivery
  * group_order_article
  * supplier

also adds a new factory for delivery

Co-authored-by: viehlieb <pf@pragma-shift.net>
Co-authored-by: Tobias Kneuker <tk@pragma-shift.net>
This commit is contained in:
Philipp Rothmann 2022-10-31 16:36:06 +01:00 committed by Patrick Gansterer
parent 9a46640d3b
commit c6560e0cea
8 changed files with 167 additions and 7 deletions

View file

@ -15,6 +15,38 @@ describe Article do
expect(article).to be_deleted
end
describe 'convert units' do
it 'returns nil when equal' do
expect(article.convert_units(article)).to be_nil
end
it 'returns false when invalid unit' do
article1 = build :article, supplier: supplier, unit: 'invalid'
expect(article.convert_units(article1)).to be false
end
it 'converts from ST to KI (german foodcoops legacy)' do
article1 = build :article, supplier: supplier, unit: 'ST'
article2 = build :article, supplier: supplier, name: 'banana 10-12 St', price: 12.34, unit: 'KI'
new_price, new_unit_quantity = article1.convert_units(article2)
expect(new_unit_quantity).to eq 10
expect(new_price).to eq 1.23
end
it 'converts from g to kg' do
article1 = build :article, supplier: supplier, unit: 'kg'
article2 = build :article, supplier: supplier, unit: 'g', price: 0.12, unit_quantity: 1500
new_price, new_unit_quantity = article1.convert_units(article2)
expect(new_unit_quantity).to eq 1.5
expect(new_price).to eq 120
end
end
it 'computes changed article attributes' do
article2 = build :article, supplier: supplier, name: 'banana'
expect(article.unequal_attributes(article2)[:name]).to eq 'banana'
end
it 'computes the gross price correctly' do
article.deposit = 0
article.tax = 12