|
385 | 385 |
|
386 | 386 | it "redirects with a flash notice and send send_notification" do |
387 | 387 | expected_distribution_changes = { |
| 388 | + added: [{name: "Item 2", quantity: 4}], |
388 | 389 | removed: [], |
389 | 390 | updates: [ |
390 | 391 | { |
|
406 | 407 | end |
407 | 408 | end |
408 | 409 |
|
| 410 | + context "when only an item is added to a distribution" do |
| 411 | + let(:existing_item) { create(:item, name: "Adult Diapers", organization: organization) } |
| 412 | + let(:added_item) { create(:item, name: "Wipes (Adult)", organization: organization) } |
| 413 | + let(:storage_location) { create(:storage_location, organization: organization) } |
| 414 | + let(:distribution) do |
| 415 | + create(:distribution, :with_items, organization: organization, partner: partner, |
| 416 | + storage_location: storage_location, item: existing_item, item_quantity: 10, |
| 417 | + issued_at: 2.days.from_now) |
| 418 | + end |
| 419 | + |
| 420 | + before do |
| 421 | + TestInventory.create_inventory(organization, { |
| 422 | + storage_location.id => {existing_item.id => 100, added_item.id => 100} |
| 423 | + }) |
| 424 | + end |
| 425 | + |
| 426 | + it "sends a change notification listing the added item" do |
| 427 | + expected_changes = { |
| 428 | + added: [{name: "Wipes (Adult)", quantity: 5}], |
| 429 | + updates: [], |
| 430 | + removed: [] |
| 431 | + } |
| 432 | + |
| 433 | + expect(PartnerMailerJob).to receive(:perform_now) |
| 434 | + .with(organization.id, distribution.id, "Your Distribution Has Changed", expected_changes) |
| 435 | + |
| 436 | + put :update, params: { |
| 437 | + id: distribution.id, |
| 438 | + distribution: { |
| 439 | + storage_location_id: storage_location.id, |
| 440 | + line_items_attributes: { |
| 441 | + "0": {item_id: existing_item.id, quantity: 10}, |
| 442 | + "1": {item_id: added_item.id, quantity: 5} |
| 443 | + } |
| 444 | + } |
| 445 | + } |
| 446 | + |
| 447 | + expect(response).to have_http_status(:redirect) |
| 448 | + end |
| 449 | + end |
| 450 | + |
409 | 451 | context "when distribution reminder email is enabled" do |
410 | 452 | let(:item1) { create(:item, name: "Item 1", organization: organization, on_hand_minimum_quantity: 0) } |
411 | 453 | let(:storage_location) { create(:storage_location, organization: organization) } |
|
0 commit comments