mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Import DFC milligram
This commit is contained in:
@@ -34,6 +34,8 @@ class QuantitativeValueBuilder < DfcBuilder
|
||||
case quantity.unit
|
||||
when quantity_unit.LITRE
|
||||
["volume", "liter", 1]
|
||||
when quantity_unit.MILLIGRAM
|
||||
["weight", "mg", 0.001]
|
||||
when quantity_unit.GRAM
|
||||
["weight", "gram", 1]
|
||||
when quantity_unit.KILOGRAM
|
||||
|
||||
@@ -89,5 +89,19 @@ describe QuantitativeValueBuilder do
|
||||
expect(product.variant_unit_scale).to eq 1_000
|
||||
expect(product.unit_value).to eq 4_000
|
||||
end
|
||||
|
||||
it "knows metric units with a small scale" do
|
||||
quantity = DataFoodConsortium::Connector::QuantitativeValue.new(
|
||||
unit: quantity_unit.MILLIGRAM,
|
||||
value: 5,
|
||||
)
|
||||
|
||||
builder.apply(quantity, product)
|
||||
|
||||
expect(product.variant_unit).to eq "weight"
|
||||
expect(product.variant_unit_name).to eq "mg"
|
||||
expect(product.variant_unit_scale).to eq 0.001
|
||||
expect(product.unit_value).to eq 0.005
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user