Define supplier_ids in inventory_reset_strategy specs for clarity

This commit is contained in:
Arun Kumar Mohan
2020-10-17 20:12:14 -05:00
parent 5928eba767
commit c65108731c

View File

@@ -19,6 +19,7 @@ describe ProductImport::InventoryResetStrategy do
let(:excluded_items_ids) { [variant_override.id] }
context 'and supplier_ids is []' do
let(:supplier_ids) { [] }
let(:relation) do
instance_double(ActiveRecord::Relation, update_all: true)
end
@@ -26,12 +27,13 @@ describe ProductImport::InventoryResetStrategy do
before { allow(VariantOverride).to receive(:where) { relation } }
it 'does not update any DB record' do
inventory_reset.reset([])
inventory_reset.reset(supplier_ids)
expect(relation).not_to have_received(:update_all)
end
end
context 'and supplier_ids is nil' do
let(:supplier_ids) { nil }
let(:relation) do
instance_double(ActiveRecord::Relation, update_all: true)
end
@@ -39,12 +41,13 @@ describe ProductImport::InventoryResetStrategy do
before { allow(VariantOverride).to receive(:where) { relation } }
it 'does not update any DB record' do
inventory_reset.reset(nil)
inventory_reset.reset(supplier_ids)
expect(relation).not_to have_received(:update_all)
end
end
context 'and supplier_ids is set' do
let(:supplier_ids) { enterprise.id }
let(:variant) { create(:variant) }
let!(:variant_override) do
create(
@@ -55,7 +58,7 @@ describe ProductImport::InventoryResetStrategy do
)
end
it 'does not update the count_on_hand of the excluded items' do
inventory_reset.reset(enterprise.id)
inventory_reset.reset(supplier_ids)
expect(variant_override.reload.count_on_hand).to eq(10)
end
@@ -66,7 +69,7 @@ describe ProductImport::InventoryResetStrategy do
hub: enterprise,
variant: variant
)
inventory_reset.reset(enterprise.id)
inventory_reset.reset(supplier_ids)
expect(non_excluded_variant_override.reload.count_on_hand).to eq(0)
end
end
@@ -76,6 +79,7 @@ describe ProductImport::InventoryResetStrategy do
let(:excluded_items_ids) { [] }
context 'and supplier_ids is []' do
let(:supplier_ids) { [] }
let(:relation) do
instance_double(ActiveRecord::Relation, update_all: true)
end
@@ -83,12 +87,13 @@ describe ProductImport::InventoryResetStrategy do
before { allow(VariantOverride).to receive(:where) { relation } }
it 'does not update any DB record' do
inventory_reset.reset([])
inventory_reset.reset(supplier_ids)
expect(relation).not_to have_received(:update_all)
end
end
context 'and supplier_ids is nil' do
let(:supplier_ids) { nil }
let(:relation) do
instance_double(ActiveRecord::Relation, update_all: true)
end
@@ -96,12 +101,13 @@ describe ProductImport::InventoryResetStrategy do
before { allow(VariantOverride).to receive(:where) { relation } }
it 'does not update any DB record' do
inventory_reset.reset(nil)
inventory_reset.reset(supplier_ids)
expect(relation).not_to have_received(:update_all)
end
end
context 'and supplier_ids is set' do
let(:supplier_ids) { enterprise.id }
let(:enterprise) { variant.product.supplier }
let(:variant) { create(:variant) }
let!(:variant_override) do
@@ -113,7 +119,7 @@ describe ProductImport::InventoryResetStrategy do
)
end
it 'sets all count_on_hand to 0' do
inventory_reset.reset(enterprise.id)
inventory_reset.reset(supplier_ids)
expect(variant_override.reload.count_on_hand).to eq(0)
end
end
@@ -123,6 +129,7 @@ describe ProductImport::InventoryResetStrategy do
let(:excluded_items_ids) { nil }
context 'and supplier_ids is []' do
let(:supplier_ids) { [] }
let(:relation) do
instance_double(ActiveRecord::Relation, update_all: true)
end
@@ -130,12 +137,13 @@ describe ProductImport::InventoryResetStrategy do
before { allow(VariantOverride).to receive(:where) { relation } }
it 'does not update any DB record' do
inventory_reset.reset([])
inventory_reset.reset(supplier_ids)
expect(relation).not_to have_received(:update_all)
end
end
context 'and supplier_ids is nil' do
let(:supplier_ids) { nil }
let(:relation) do
instance_double(ActiveRecord::Relation, update_all: true)
end
@@ -143,12 +151,13 @@ describe ProductImport::InventoryResetStrategy do
before { allow(VariantOverride).to receive(:where) { relation } }
it 'does not update any DB record' do
inventory_reset.reset(nil)
inventory_reset.reset(supplier_ids)
expect(relation).not_to have_received(:update_all)
end
end
context 'and supplier_ids is set' do
let(:supplier_ids) { enterprise.id }
let(:enterprise) { variant.product.supplier }
let(:variant) { create(:variant) }
let!(:variant_override) do
@@ -160,7 +169,7 @@ describe ProductImport::InventoryResetStrategy do
)
end
it 'sets all count_on_hand to 0' do
inventory_reset.reset(enterprise.id)
inventory_reset.reset(supplier_ids)
expect(variant_override.reload.count_on_hand).to eq(0)
end
end