Update more specs

This commit is contained in:
Matt-Yorkley
2023-08-08 12:10:05 +01:00
committed by Gaetan Craig-Riou
parent b22c42613a
commit d9899e8af6
13 changed files with 31 additions and 34 deletions

View File

@@ -25,6 +25,7 @@ describe Api::V0::ProductsController, type: :controller do
end
context "as a normal user" do
let(:taxon) { create(:taxon) }
let(:attachment) { fixture_file_upload("thinking-cat.jpg") }
before do
@@ -34,9 +35,10 @@ describe Api::V0::ProductsController, type: :controller do
it "gets a single product" do
product.create_image!(attachment:)
product.variants.create!(unit_value: "1", unit_description: "thing", price: 1)
product.variants.create!(unit_value: "1", unit_description: "thing", price: 1, primary_taxon: taxon)
product.variants.first.images.create!(attachment:)
product.set_property("spree", "rocks")
api_get :show, id: product.to_param
expect(all_attributes.all?{ |attr| json_response.keys.include? attr }).to eq(true)
@@ -117,8 +119,7 @@ describe Api::V0::ProductsController, type: :controller do
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]
expect(errors.keys).to match_array(["name", "primary_taxon", "supplier", "variant_unit",
"price"])
expect(errors.keys).to match_array(["name", "supplier", "variant_unit", "price"])
end
it "can update a product" do

View File

@@ -127,6 +127,7 @@ describe Api::V0::VariantsController, type: :controller do
let(:product) { create(:product) }
let(:variant) { product.variants.first }
let(:taxon) { create(:taxon) }
let!(:variant2) { create(:variant, product:) }
context "deleted variants" do
@@ -144,7 +145,7 @@ describe Api::V0::VariantsController, type: :controller do
it "can create a new variant" do
original_number_of_variants = variant.product.variants.count
api_post :create, variant: { sku: "12345", unit_value: "1",
unit_description: "L", price: "1" },
unit_description: "L", price: "1", primary_taxon_id: taxon.id },
product_id: variant.product.id
expect(attributes.all?{ |attr| json_response.include? attr.to_s }).to eq(true)

View File

@@ -93,6 +93,7 @@ describe Spree::Admin::ProductsController, type: :controller do
variant_unit_name: nil
)
end
let!(:taxon) { create(:taxon) }
before { controller_login_as_enterprise_user([producer]) }
@@ -111,7 +112,8 @@ describe Spree::Admin::ProductsController, type: :controller do
"price" => "5.0",
"unit_value" => 4,
"unit_description" => "",
"display_name" => "name"
"display_name" => "name",
"primary_taxon_id" => taxon.id
}
]
}

View File

@@ -11,7 +11,9 @@ module Spree
describe "deleted variants" do
let(:product) { create(:product, name: 'Product A') }
let(:deleted_variant) do
deleted_variant = product.variants.create(unit_value: "2", price: 1)
deleted_variant = product.variants.create(
unit_value: "2", price: 1, primary_taxon: create(:taxon)
)
deleted_variant.delete
deleted_variant
end

View File

@@ -43,7 +43,7 @@ module Reporting
allow(variant).to receive_message_chain(:product, :name).and_return("Product Name")
allow(variant).to receive_message_chain(:product, :properties)
.and_return [double(name: "property1"), double(name: "property2")]
allow(variant).to receive_message_chain(:product, :primary_taxon).
allow(variant).to receive_message_chain(:primary_taxon).
and_return double(name: "taxon1")
allow(variant).to receive_message_chain(:product, :group_buy_unit_size).and_return(21)
allow(subject).to receive(:query_result).and_return [variant]

View File

@@ -155,7 +155,6 @@ module Spree
describe "associations" do
it { is_expected.to belong_to(:supplier).required }
it { is_expected.to belong_to(:primary_taxon).required }
end
describe "validations and defaults" do
@@ -167,10 +166,6 @@ module Spree
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_length_of(:sku).is_at_most(255) }
it "requires a primary taxon" do
expect(build(:simple_product, primary_taxon: nil)).not_to be_valid
end
context "unit value" do
it "requires a unit value when variant unit is weight" do
expect(build(:simple_product, variant_unit: 'weight', variant_unit_name: 'name',
@@ -232,7 +227,7 @@ module Spree
before do
create(:stock_location)
product.primary_taxon = create(:taxon)
product.primary_taxon_id = create(:taxon).id
product.supplier = create(:supplier_enterprise)
product.name = "Product1"
product.variant_unit = "weight"

View File

@@ -41,11 +41,11 @@ module Spree
let!(:taxon1) { create(:taxon) }
let!(:taxon2) { create(:taxon) }
let!(:product) { create(:simple_product, primary_taxon: taxon1) }
let(:variant) { product.variants.first }
it "is touched when assignment of primary_taxon on a product changes" do
it "is touched when assignment of primary_taxon on a variant changes" do
expect do
product.primary_taxon = taxon2
product.save
variant.update(primary_taxon: taxon2)
end.to change { taxon2.reload.updated_at }
end
end

View File

@@ -162,12 +162,6 @@ describe ProductsRenderer do
expect(products_renderer.products_json).to include "998.0"
end
it "includes the primary taxon" do
taxon = create(:taxon)
allow_any_instance_of(Spree::Product).to receive(:primary_taxon).and_return taxon
expect(products_renderer.products_json).to include taxon.name
end
it "loads tag_list for variants" do
VariantOverride.create(variant:, hub: distributor, tag_list: 'lalala')
expect(products_renderer.products_json).to include "[\"lalala\"]"

View File

@@ -344,7 +344,6 @@ describe '
within "tr#p_#{p.id}" do
expect(page).to have_field "product_name", with: p.name
expect(page).to have_select "producer_id", selected: s1.name
expect(page).to have_select2 "p#{p.id}_category_id", selected: t2.name
expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)"
expect(page).to have_checked_field "inherits_properties"
expect(page).to have_field "product_sku", with: p.sku
@@ -352,7 +351,6 @@ describe '
fill_in "product_name", with: "Big Bag Of Potatoes"
select s2.name, from: 'producer_id'
select "Weight (kg)", from: "variant_unit_with_scale"
select2_select t1.name, from: "p#{p.id}_category_id"
uncheck "inherits_properties"
fill_in "product_sku", with: "NEW SKU"
end
@@ -365,7 +363,6 @@ describe '
expect(p.supplier).to eq s2
expect(p.variant_unit).to eq "weight"
expect(p.variant_unit_scale).to eq 1000 # Kg
expect(p.primary_taxon.permalink).to eq t1.permalink
expect(p.inherits_properties).to be false
expect(p.sku).to eq "NEW SKU"
end

View File

@@ -143,7 +143,7 @@ describe '
expect(product.variants.first.unit_value).to eq(5000)
expect(product.variants.first.unit_description).to eq("")
expect(product.variant_unit_name).to eq("")
expect(product.primary_taxon_id).to eq(taxon.id)
expect(product.variants.first.primary_taxon_id).to eq(taxon.id)
expect(product.variants.first.price.to_s).to eq('19.99')
expect(product.on_hand).to eq(5)
expect(product.variants.first.tax_category_id).to eq(tax_category.id)

View File

@@ -358,15 +358,15 @@ describe '
let(:taxon) { create(:taxon, name: 'Taxon Name') }
let(:product1) {
create(:simple_product, name: "Product Name", price: 100, supplier:,
primary_taxon: taxon)
primary_taxon_id: taxon.id)
}
let(:product2) {
create(:simple_product, name: "Product 2", price: 99.0, variant_unit: 'weight',
variant_unit_scale: 1, unit_value: '100', supplier:,
primary_taxon: taxon, sku: "product_sku")
primary_taxon_id: taxon.id, sku: "product_sku")
}
let(:variant1) { product1.variants.first }
let(:variant2) { create(:variant, product: product1, price: 80.0) }
let(:variant2) { create(:variant, product: product1, price: 80.0, primary_taxon: taxon) }
let(:variant3) { product2.variants.first }
before do
@@ -396,17 +396,17 @@ describe '
expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city,
"Product Name",
product1.properties.map(&:presentation).join(", "),
product1.primary_taxon.name, "1g", "100.0",
taxon.name, "1g", "100.0",
"none", "", "sku1", "No", "10"]
expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city,
"Product Name",
product1.properties.map(&:presentation).join(", "),
product1.primary_taxon.name, "1g", "80.0",
taxon.name, "1g", "80.0",
"none", "", "sku2", "No", "20"]
expect(page).to have_table_row [product2.supplier.name, product1.supplier.address.city,
"Product 2",
product1.properties.map(&:presentation).join(", "),
product2.primary_taxon.name, "100g", "99.0",
taxon.name, "100g", "99.0",
"none", "", "product_sku", "No", "9"]
end

View File

@@ -9,6 +9,8 @@ describe '
include AuthenticationHelper
include WebHelper
let!(:taxon) { create(:taxon) }
describe "new variant" do
it "creating a new variant" do
# Given a product with a unit-related option type
@@ -21,6 +23,7 @@ describe '
fill_in 'unit_value_human', with: '1'
fill_in 'variant_unit_description', with: 'foo'
select taxon.name, from: "variant_primary_taxon_id"
click_button 'Create'
# Then the variant should have been created
@@ -61,6 +64,7 @@ describe '
# Expect variant_weight to accept 3 decimal places
fill_in 'variant_weight', with: '1.234'
fill_in 'unit_value_human', with: 1
select taxon.name, from: "variant_primary_taxon_id"
click_button 'Create'
# Then the variant should have been created

View File

@@ -53,8 +53,9 @@ describe "Shops caching", caching: true do
let!(:property) { create(:property, presentation: "Cached Property") }
let!(:property2) { create(:property, presentation: "New Property") }
let!(:product) {
create(:product, primary_taxon: taxon, properties: [property])
create(:product, primary_taxon_id: taxon.id, properties: [property])
}
let(:variant) { product.variants.first }
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
let(:test_domain) {
@@ -92,7 +93,7 @@ describe "Shops caching", caching: true do
expect(page).to have_content taxon.name
expect(page).to have_content property.presentation
product.update_attribute(:primary_taxon, taxon2)
variant.update_attribute(:primary_taxon, taxon2)
product.update_attribute(:properties, [property2])
visit enterprise_shop_path(distributor)