Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jp524 committed Jun 4, 2024
1 parent b003d66 commit 900f380
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions spec/services/itemizable_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,27 @@
expect(UpdateExistingEvent.count).to eq(1)
end

it "should update quantity in different locations" do
attributes[:storage_location_id] = new_storage_location.id
subject
expect(itemizable.reload.line_items.count).to eq(2)
expect(itemizable.line_items.sum(&:quantity)).to eq(4)
expect(storage_location.size).to eq(10)
expect(new_storage_location.size).to eq(24)
context "when storage location changes" do
context "when there is no intervening audit" do
it "should update quantity in different locations" do
attributes[:storage_location_id] = new_storage_location.id
subject
expect(itemizable.reload.line_items.count).to eq(2)
expect(itemizable.line_items.sum(&:quantity)).to eq(4)
expect(storage_location.size).to eq(10)
expect(new_storage_location.size).to eq(24)
end
end

context "when there is an intervening audit on one of the items involved" do
it "raises an error" do
msg = "Cannot change the storage location because there has been an intervening audit of some items. " \
"If you need to change the storage location, please delete this donation and create a new donation with the new storage location."
create(:audit, :with_items, item: itemizable.items.first, organization: organization, storage_location: storage_location, status: "finalized")
attributes[:storage_location_id] = new_storage_location.id
expect { subject }.to raise_error(msg)
end
end
end

it "should raise an error if any item is inactive" do
Expand Down Expand Up @@ -114,13 +128,27 @@
expect(itemizable.issued_at).to eq(2.days.ago)
end

it "should update quantity in different locations" do
attributes[:storage_location_id] = new_storage_location.id
subject
expect(itemizable.reload.line_items.count).to eq(2)
expect(itemizable.line_items.sum(&:quantity)).to eq(4)
expect(storage_location.size).to eq(30)
expect(new_storage_location.size).to eq(16)
context "when storage location changes" do
context "when there is no intervening audit" do
it "should update quantity in different locations" do
attributes[:storage_location_id] = new_storage_location.id
subject
expect(itemizable.reload.line_items.count).to eq(2)
expect(itemizable.line_items.sum(&:quantity)).to eq(4)
expect(storage_location.size).to eq(30)
expect(new_storage_location.size).to eq(16)
end
end

context "when there is an intervening audit on one of the items involved" do
it "raises an error" do
msg = "Cannot change the storage location because there has been an intervening audit of some items. " \
"If you need to change the storage location, please reclaim this distribution and create a new distribution from the new storage location."
create(:audit, :with_items, item: itemizable.items.first, organization: organization, storage_location: storage_location, status: "finalized")
attributes[:storage_location_id] = new_storage_location.id
expect { subject }.to raise_error(msg)
end
end
end

it "should raise an error if any item is inactive" do
Expand Down

0 comments on commit 900f380

Please sign in to comment.