Skip to content

Commit 4fea392

Browse files
authored
Add mass unreconiling ff (#5661)
1 parent 31a54ba commit 4fea392

File tree

5 files changed

+97
-83
lines changed

5 files changed

+97
-83
lines changed

app/controllers/facility_journals_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def reconcile
141141
end
142142

143143
def unreconcile
144+
unless SettingsHelper.feature_on?(:allow_mass_unreconciling)
145+
raise CanCan::AccessDenied, I18n.t("controllers.facility_journals.unreconcile.feature_disabled")
146+
end
147+
144148
process_reconciliation(:unreconcile)
145149
end
146150

app/views/facility_journals/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
- has_reconciled = @journal.order_details.where(state: "reconciled").any?
4646
- has_unreconciled = @journal.order_details.where.not(state: "reconciled").any?
4747
- journal_can_reconcile = @journal.successful? && has_unreconciled
48-
- journal_can_unreconcile = @journal.successful? && has_reconciled
48+
- journal_can_unreconcile = @journal.successful? && has_reconciled && SettingsHelper.feature_on?(:allow_mass_unreconciling)
4949
- show_checkboxes = journal_is_submittable || journal_can_unreconcile || journal_can_reconcile
5050

5151
= form_tag facility_journal_reconcile_path(current_facility, @journal), method: :post, id: "journal-form" do

config/locales/en.controllers.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ en:
7373
success: "%{count} payment(s) successfully unreconciled"
7474
errors:
7575
none_eligible: "No orders were selected or eligible to unreconcile"
76+
feature_disabled: "Mass unreconciling is not enabled"
7677

7778
facility_order_details:
7879
destroy:

config/settings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ feature:
182182
account_tabs: false
183183
user_based_price_groups_exclude_purchaser: false
184184
item_initial_order_status_complete: false
185+
allow_mass_unreconciling: false
185186

186187
split_accounts:
187188
# Roles are allowed to create Split Accounts

spec/controllers/facility_journals_controller_spec.rb

Lines changed: 90 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -512,107 +512,115 @@ def perform(order_detail_params = nil)
512512
@journal.create_journal_rows!([@order_detail1, @order_detail2, @order_detail3])
513513
end
514514

515-
describe "when all order details are reconciled" do
516-
before do
517-
@order_detail1.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
518-
@order_detail2.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
519-
@order_detail3.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
515+
context "when feature flag is disabled", feature_setting: { allow_mass_unreconciling: false } do
516+
it "raises access denied error" do
517+
expect { perform }.to raise_error(CanCan::AccessDenied)
520518
end
519+
end
521520

522-
it "unreconciles all order details" do
523-
perform
524-
expect(@order_detail1.reload.state).to eq("complete")
525-
expect(@order_detail2.reload.state).to eq("complete")
526-
expect(@order_detail3.reload.state).to eq("complete")
527-
end
521+
context "when feature flag is enabled", feature_setting: { allow_mass_unreconciling: true } do
522+
describe "when all order details are reconciled" do
523+
before do
524+
@order_detail1.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
525+
@order_detail2.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
526+
@order_detail3.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
527+
end
528528

529-
it "clears reconciled_at for all order details" do
530-
perform
531-
expect(@order_detail1.reload.reconciled_at).to be_nil
532-
expect(@order_detail2.reload.reconciled_at).to be_nil
533-
expect(@order_detail3.reload.reconciled_at).to be_nil
534-
end
529+
it "unreconciles all order details" do
530+
perform
531+
expect(@order_detail1.reload.state).to eq("complete")
532+
expect(@order_detail2.reload.state).to eq("complete")
533+
expect(@order_detail3.reload.state).to eq("complete")
534+
end
535535

536-
it "sets flash notice with correct count" do
537-
perform
538-
expect(flash[:notice]).to eq("3 payment(s) successfully unreconciled")
539-
end
540-
end
536+
it "clears reconciled_at for all order details" do
537+
perform
538+
expect(@order_detail1.reload.reconciled_at).to be_nil
539+
expect(@order_detail2.reload.reconciled_at).to be_nil
540+
expect(@order_detail3.reload.reconciled_at).to be_nil
541+
end
541542

542-
describe "when some order details are not reconciled" do
543-
before do
544-
@order_detail1.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
545-
@order_detail2.update!(state: "complete")
546-
@order_detail3.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
543+
it "sets flash notice with correct count" do
544+
perform
545+
expect(flash[:notice]).to eq("3 payment(s) successfully unreconciled")
546+
end
547547
end
548548

549-
it "only unreconciles the reconciled ones" do
550-
perform
551-
expect(@order_detail1.reload.state).to eq("complete")
552-
expect(@order_detail2.reload.state).to eq("complete")
553-
expect(@order_detail3.reload.state).to eq("complete")
554-
end
549+
describe "when some order details are not reconciled" do
550+
before do
551+
@order_detail1.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
552+
@order_detail2.update!(state: "complete")
553+
@order_detail3.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
554+
end
555555

556-
it "shows correct count in flash notice" do
557-
perform
558-
expect(flash[:notice]).to eq("2 payment(s) successfully unreconciled")
559-
end
560-
end
556+
it "only unreconciles the reconciled ones" do
557+
perform
558+
expect(@order_detail1.reload.state).to eq("complete")
559+
expect(@order_detail2.reload.state).to eq("complete")
560+
expect(@order_detail3.reload.state).to eq("complete")
561+
end
561562

562-
describe "when no order details are reconciled" do
563-
before do
564-
@order_detail1.update!(state: "complete")
565-
@order_detail2.update!(state: "complete")
566-
@order_detail3.update!(state: "complete")
563+
it "shows correct count in flash notice" do
564+
perform
565+
expect(flash[:notice]).to eq("2 payment(s) successfully unreconciled")
566+
end
567567
end
568568

569-
it "does not change any states" do
570-
perform
571-
expect(@order_detail1.reload.state).to eq("complete")
572-
expect(@order_detail2.reload.state).to eq("complete")
573-
expect(@order_detail3.reload.state).to eq("complete")
574-
end
569+
describe "when no order details are reconciled" do
570+
before do
571+
@order_detail1.update!(state: "complete")
572+
@order_detail2.update!(state: "complete")
573+
@order_detail3.update!(state: "complete")
574+
end
575575

576-
it "shows appropriate flash error" do
577-
perform
578-
expect(flash[:error]).to eq("No orders were selected or eligible to unreconcile")
576+
it "does not change any states" do
577+
perform
578+
expect(@order_detail1.reload.state).to eq("complete")
579+
expect(@order_detail2.reload.state).to eq("complete")
580+
expect(@order_detail3.reload.state).to eq("complete")
581+
end
582+
583+
it "shows appropriate flash error" do
584+
perform
585+
expect(flash[:error]).to eq("No orders were selected or eligible to unreconcile")
586+
end
579587
end
580-
end
581588

582-
describe "when unreconcile fails for one order detail" do
583-
before do
584-
@order_detail1.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
585-
@order_detail2.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
586-
@order_detail3.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
587-
588-
allow_any_instance_of(OrderDetail).to receive(:update!).and_call_original
589-
590-
call_count = 0
591-
allow_any_instance_of(OrderDetail).to receive(:update!).and_wrap_original do |original, receiver, *args|
592-
call_count += 1
593-
if call_count == 2 # Fail on the second order detail
594-
raise StandardError, "Failed to update order detail"
595-
else
596-
original.call(receiver, *args)
589+
describe "when unreconcile fails for one order detail" do
590+
before do
591+
@order_detail1.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
592+
@order_detail2.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
593+
@order_detail3.update!(state: "reconciled", reconciled_at: 1.day.ago, order_status: OrderStatus.reconciled)
594+
595+
allow_any_instance_of(OrderDetail).to receive(:update!).and_call_original
596+
597+
call_count = 0
598+
allow_any_instance_of(OrderDetail).to receive(:update!).and_wrap_original do |original, receiver, *args|
599+
call_count += 1
600+
if call_count == 2 # Fail on the second order detail
601+
raise StandardError, "Failed to update order detail"
602+
else
603+
original.call(receiver, *args)
604+
end
597605
end
598606
end
599-
end
600607

601-
it "rolls back all changes" do
602-
perform
603-
expect(@order_detail1.reload.state).to eq("reconciled")
604-
expect(@order_detail2.reload.state).to eq("reconciled")
605-
expect(@order_detail3.reload.state).to eq("reconciled")
606-
end
608+
it "rolls back all changes" do
609+
perform
610+
expect(@order_detail1.reload.state).to eq("reconciled")
611+
expect(@order_detail2.reload.state).to eq("reconciled")
612+
expect(@order_detail3.reload.state).to eq("reconciled")
613+
end
607614

608-
it "shows error message with the failing order detail" do
609-
perform
610-
expect(flash[:error]).to include("Failed to update order detail")
611-
end
615+
it "shows error message with the failing order detail" do
616+
perform
617+
expect(flash[:error]).to include("Failed to update order detail")
618+
end
612619

613-
it "does not show success message" do
614-
perform
615-
expect(flash[:notice]).to be_nil
620+
it "does not show success message" do
621+
perform
622+
expect(flash[:notice]).to be_nil
623+
end
616624
end
617625
end
618626
end

0 commit comments

Comments
 (0)