Skip to content

Commit

Permalink
payment requests: block if the student's rib is reused
Browse files Browse the repository at this point in the history
  • Loading branch information
freesteph committed Apr 4, 2024
1 parent 0eb5bfe commit 3c2d9e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/asp/payment_request_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class PaymentRequestStateMachine
request.schooling.student?
end

guard_transition(to: :ready) do |request|
!request.student.rib.reused?
end

guard_transition(to: :ready) do |request|
!request.student.lost
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/asp/payment_request_state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
end
end

context "when the RIB has been reused somewhere else" do
before { create(:rib, iban: asp_payment_request.student.rib.iban) }

it "blocks the transition" do
expect { asp_payment_request.mark_ready! }.to raise_error Statesman::GuardFailedError
end
end

context "when the request is missing information" do
before { student.rib&.destroy }

Expand Down

0 comments on commit 3c2d9e1

Please sign in to comment.