|
535 | 535 | end |
536 | 536 | end |
537 | 537 |
|
| 538 | + describe "submissions:redeliver_daily_batches_by_date" do |
| 539 | + subject(:task) do |
| 540 | + Rake::Task["submissions:redeliver_daily_batches_by_date"] |
| 541 | + .tap(&:reenable) |
| 542 | + end |
| 543 | + |
| 544 | + let(:form_id) { 1 } |
| 545 | + let(:other_form_id) { 2 } |
| 546 | + let(:start_time) { "2024-01-01T00:00:00Z" } |
| 547 | + let(:end_time) { "2024-01-02T00:00:00Z" } |
| 548 | + let(:dry_run) { "false" } |
| 549 | + |
| 550 | + let!(:batched_submission) do |
| 551 | + create :submission, |
| 552 | + :sent, |
| 553 | + form_id:, |
| 554 | + created_at: Time.parse("2024-01-01T12:00:00Z"), |
| 555 | + reference: "ref1" |
| 556 | + end |
| 557 | + |
| 558 | + let!(:batch_delivery) do |
| 559 | + create :delivery, |
| 560 | + :daily_scheduled_delivery, |
| 561 | + :failed, |
| 562 | + submissions: [batched_submission], |
| 563 | + created_at: Time.parse("2024-01-02T02:00:00Z"), |
| 564 | + delivery_reference: "batch1" |
| 565 | + end |
| 566 | + |
| 567 | + let!(:next_day_batch_delivery) do |
| 568 | + submission = create :submission, |
| 569 | + :sent, |
| 570 | + form_id:, |
| 571 | + created_at: Time.parse("2024-01-02T12:00:00Z"), |
| 572 | + reference: "ref1" |
| 573 | + create :delivery, |
| 574 | + :daily_scheduled_delivery, |
| 575 | + :failed, |
| 576 | + submissions: [submission], |
| 577 | + created_at: Time.parse("2024-01-03T02:00:00Z"), |
| 578 | + delivery_reference: "batch-next-day" |
| 579 | + end |
| 580 | + |
| 581 | + let!(:other_form_batch_delivery) do |
| 582 | + submission = create :submission, |
| 583 | + :sent, |
| 584 | + form_id: other_form_id, |
| 585 | + created_at: Time.parse("2024-01-01T12:00:00Z"), |
| 586 | + reference: "ref2" |
| 587 | + create :delivery, |
| 588 | + :daily_scheduled_delivery, |
| 589 | + :failed, |
| 590 | + submissions: [submission], |
| 591 | + created_at: Time.parse("2024-01-02T02:00:00Z"), |
| 592 | + delivery_reference: "batch2" |
| 593 | + end |
| 594 | + |
| 595 | + context "with valid arguments" do |
| 596 | + let(:valid_args) { [form_id, start_time, end_time, dry_run] } |
| 597 | + |
| 598 | + it "enqueues matching batch delivery for re-delivery" do |
| 599 | + expect { |
| 600 | + task.invoke(*valid_args) |
| 601 | + }.to have_enqueued_job(SendSubmissionBatchJob).with(delivery: batch_delivery) |
| 602 | + end |
| 603 | + |
| 604 | + it "does not enqueue a batch delivery outside the time range" do |
| 605 | + expect { |
| 606 | + task.invoke(*valid_args) |
| 607 | + }.not_to have_enqueued_job(SendSubmissionBatchJob).with(delivery: next_day_batch_delivery) |
| 608 | + end |
| 609 | + |
| 610 | + it "does not enqueue another form's batch deliveries" do |
| 611 | + expect { |
| 612 | + task.invoke(*valid_args) |
| 613 | + }.not_to have_enqueued_job(SendSubmissionBatchJob).with(delivery: other_form_batch_delivery) |
| 614 | + end |
| 615 | + |
| 616 | + context "when dry_run is true" do |
| 617 | + let(:dry_run) { "true" } |
| 618 | + |
| 619 | + it "does not enqueue any jobs" do |
| 620 | + expect { |
| 621 | + task.invoke(*valid_args) |
| 622 | + }.not_to have_enqueued_job(SendSubmissionJob) |
| 623 | + end |
| 624 | + end |
| 625 | + |
| 626 | + context "when no submissions took place between the given times" do |
| 627 | + let(:valid_args) { [form_id, "2025-01-01T00:00:00Z", "2025-01-02T00:00:00Z", dry_run] } |
| 628 | + |
| 629 | + it "does not enqueue any jobs" do |
| 630 | + expect { |
| 631 | + task.invoke(*valid_args) |
| 632 | + }.not_to have_enqueued_job(SendSubmissionBatchJob) |
| 633 | + end |
| 634 | + end |
| 635 | + end |
| 636 | + |
| 637 | + context "with invalid arguments" do |
| 638 | + it "aborts when form_id is missing" do |
| 639 | + expect { |
| 640 | + task.invoke("", start_time, end_time, dry_run) |
| 641 | + }.to raise_error(SystemExit) |
| 642 | + .and output("usage: rake submissions:redeliver_daily_batches_by_date[<form_id>,<start_timestamp>,<end_timestamp>,<dry_run>]\n").to_stderr |
| 643 | + end |
| 644 | + |
| 645 | + it "aborts when start_timestamp is missing" do |
| 646 | + expect { |
| 647 | + task.invoke(form_id, "", end_time, dry_run) |
| 648 | + }.to raise_error(SystemExit) |
| 649 | + .and output("usage: rake submissions:redeliver_daily_batches_by_date[<form_id>,<start_timestamp>,<end_timestamp>,<dry_run>]\n").to_stderr |
| 650 | + end |
| 651 | + |
| 652 | + it "aborts when end_timestamp is missing" do |
| 653 | + expect { |
| 654 | + task.invoke(form_id, start_time, "", dry_run) |
| 655 | + }.to raise_error(SystemExit) |
| 656 | + .and output("usage: rake submissions:redeliver_daily_batches_by_date[<form_id>,<start_timestamp>,<end_timestamp>,<dry_run>]\n").to_stderr |
| 657 | + end |
| 658 | + |
| 659 | + it "aborts when start_timestamp is invalid" do |
| 660 | + expect { |
| 661 | + task.invoke(form_id, "invalid-date", end_time, dry_run) |
| 662 | + }.to raise_error(SystemExit) |
| 663 | + .and output("Error: Invalid timestamp format. Use ISO 8601 format (e.g. '2024-01-01T00:00:00Z')\n").to_stderr |
| 664 | + end |
| 665 | + |
| 666 | + it "aborts when end_timestamp is invalid" do |
| 667 | + expect { |
| 668 | + task.invoke(form_id, start_time, "invalid-date", dry_run) |
| 669 | + }.to raise_error(SystemExit) |
| 670 | + .and output("Error: Invalid timestamp format. Use ISO 8601 format (e.g. '2024-01-01T00:00:00Z')\n").to_stderr |
| 671 | + end |
| 672 | + |
| 673 | + it "aborts when start_timestamp is after end_timestamp" do |
| 674 | + expect { |
| 675 | + task.invoke(form_id, "2024-01-02T00:00:00Z", "2024-01-01T00:00:00Z", dry_run) |
| 676 | + }.to raise_error(SystemExit) |
| 677 | + .and output("Error: Start timestamp must be before end timestamp\n").to_stderr |
| 678 | + end |
| 679 | + |
| 680 | + it "aborts when start_timestamp equals end_timestamp" do |
| 681 | + expect { |
| 682 | + task.invoke(form_id, start_time, start_time, dry_run) |
| 683 | + }.to raise_error(SystemExit) |
| 684 | + .and output("Error: Start timestamp must be before end timestamp\n").to_stderr |
| 685 | + end |
| 686 | + |
| 687 | + it "aborts when dry_run is an invalid value" do |
| 688 | + expect { |
| 689 | + task.invoke(form_id, start_time, start_time, "foo") |
| 690 | + }.to raise_error(SystemExit) |
| 691 | + .and output("usage: rake submissions:redeliver_daily_batches_by_date[<form_id>,<start_timestamp>,<end_timestamp>,<dry_run>]\n").to_stderr |
| 692 | + end |
| 693 | + end |
| 694 | + end |
| 695 | + |
538 | 696 | describe "submissions:file_answers:fix_missing_original_filenames" do |
539 | 697 | subject(:task) do |
540 | 698 | Rake::Task["submissions:file_answers:fix_missing_original_filenames"] |
|
0 commit comments