|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe Bls::Core::ProductFactory do |
| 4 | + describe "#create" do |
| 5 | + it "assigns the ingredients to the Product" do |
| 6 | + response = build_product_response |
| 7 | + ingredient = Bls::Core::Ingredient.build(response[:ingredients]) |
| 8 | + factory = Bls::Core::ProductFactory.new(response) |
| 9 | + |
| 10 | + result = factory.create |
| 11 | + |
| 12 | + expect(result.ingredients).to match_array(ingredient) |
| 13 | + end |
| 14 | + |
| 15 | + it "assigns the allergens to the Product" do |
| 16 | + response = build_product_response |
| 17 | + allergen = Bls::Core::Allergen.build_from_array(response[:allergens]) |
| 18 | + factory = Bls::Core::ProductFactory.new(response) |
| 19 | + |
| 20 | + result = factory.create |
| 21 | + |
| 22 | + expect(result.allergens).to match_array(allergen) |
| 23 | + end |
| 24 | + |
| 25 | + it "assigns the dietary tags to the Product" do |
| 26 | + response = build_product_response |
| 27 | + dietary_tags = Bls::Core::Allergen. |
| 28 | + build_from_array(response[:dietary_tags]) |
| 29 | + factory = Bls::Core::ProductFactory.new(response) |
| 30 | + |
| 31 | + result = factory.create |
| 32 | + |
| 33 | + expect(result.dietary_tags).to match_array(dietary_tags) |
| 34 | + end |
| 35 | + |
| 36 | + it "assigns the nutrition facts to the Product" do |
| 37 | + response = build_product_response |
| 38 | + factory = Bls::Core::ProductFactory.new(response) |
| 39 | + product = factory.create |
| 40 | + |
| 41 | + result = product.nutrition_facts |
| 42 | + |
| 43 | + expect(result.keys).to match_array([:as_packaged, :as_cooked]) |
| 44 | + end |
| 45 | + end |
| 46 | +end |
0 commit comments