Skip to content

Commit

Permalink
Merge branch 'main' into chore/add-test-for-end-date
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Oct 17, 2024
2 parents d54d5b5 + fb529ce commit 65cec07
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
11 changes: 11 additions & 0 deletions app/controllers/ribs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def update
@rib = @student.create_new_rib(rib_params)

if @rib.save
retry_rejected_or_unpaid_payment_request!

redirect_to student_path(@student),
notice: t(".success")
else
Expand Down Expand Up @@ -147,4 +149,13 @@ def check_establishment!
def rib_is_readonly
redirect_to student_path(@student), alert: t("flash.ribs.readonly", name: @student.full_name)
end

def retry_rejected_or_unpaid_payment_request!
@student.pfmps.in_state(:validated).each do |pfmp|
if pfmp.latest_payment_request&.eligible_for_rejected_or_unpaid_auto_retry?
p_r = PfmpManager.new(pfmp).create_new_payment_request!
p_r.mark_ready!
end
end
end
end
6 changes: 3 additions & 3 deletions app/controllers/schoolings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SchoolingsController < ApplicationController
def abrogate_decision
GenerateAbrogationDecisionJob.perform_now(@schooling)

retry_eligibile_payment_requests!
retry_incomplete_payment_request!

redirect_to student_path(@schooling.student),
notice: t("flash.da.abrogated", name: @schooling.student.full_name)
Expand Down Expand Up @@ -69,10 +69,10 @@ def set_classe
alert: t("errors.classes.not_found") and return
end

def retry_eligibile_payment_requests!
def retry_incomplete_payment_request!
@schooling.pfmps.in_state(:validated).each do |pfmp|
payment_request = pfmp.latest_payment_request
payment_request.mark_ready! if payment_request&.eligible_for_auto_retry?
payment_request.mark_ready! if payment_request&.eligible_for_incomplete_retry?
end
end

Expand Down
10 changes: 9 additions & 1 deletion app/models/asp/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ def active?
!terminated?
end

def eligible_for_auto_retry?
def eligible_for_incomplete_retry?
return false unless in_state?(:incomplete)

retryable_messages = RETRYABLE_INCOMPLETE_VALIDATION_TYPES.map do |r|
I18n.t("activerecord.errors.models.asp/payment_request.attributes.ready_state_validation.#{r}")
end
last_transition.metadata["incomplete_reasons"]["ready_state_validation"].intersect?(retryable_messages)
end

def eligible_for_rejected_or_unpaid_auto_retry?
return false unless in_state?(:rejected) || in_state?(:unpaid)

decorator = ActiveDecorator::Decorator.instance.decorate(self)
message = in_state?(:rejected) ? decorator.rejected_reason : decorator.unpaid_reason
%w[RIB BIC PAIEMENT].any? { |word| message.upcase.include?(word) }
end
end
end
12 changes: 12 additions & 0 deletions features/saisie_de_coordonnees_bancaires.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ Fonctionnalité: Le personnel de direction saisit des coordonnées bancaires
Et la page contient un bouton "Modifier les coordonnées bancaires" désactivé
Et la page contient un bouton "Supprimer les coordonnées bancaires" désactivé

Scénario: Le personnel de direction peut relancer une demande de paiement en saisissant les coordonnées bancaires
Quand je consulte la classe de "2NDEB"
Et que je renseigne et valide une PFMP de 9 jours pour "Marie Curie"
Sachant que la dernière PFMP de "Marie Curie" en classe de "2NDEB" a une requête de paiement envoyée
Et que l'ASP a rejetté le dossier de "Marie Curie" avec un motif de "Le pays correspondant au code BIC 1234 n'autorise pas le mode de réglement SEPA"
Et que la tâche de lecture des paiements est passée
Quand je clique sur "Modifier les coordonnées bancaires"
Et que je clique sur "Modifier les coordonnées bancaires"
Alors la page contient "Ces coordonnées bancaires ne sont pas modifiables"
Et la page contient un bouton "Modifier les coordonnées bancaires" désactivé
Et la page contient un bouton "Supprimer les coordonnées bancaires" désactivé

Scénario: Le personnel de direction ne peut pas accéder au RIB d'un élève s'il a été déclaré dans un autre établissement
Sachant que je renseigne les coordonnées bancaires de l'élève "Marie Curie" de la classe "2NDEB"
Et que l'élève "Marie Curie" a été transféré dans l'établissement "TEST" en classe "1EREB"
Expand Down
43 changes: 39 additions & 4 deletions spec/models/asp/payment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
end
end

describe "eligible_for_auto_retry?" do
describe "eligible_for_incomplete_retry?" do
let(:p_r_incomplete_for_abrogation) do
create(:asp_payment_request, :incomplete, incomplete_reason: :needs_abrogated_attributive_decision)
end
Expand All @@ -148,19 +148,54 @@

context "when the payment request is in 'incomplete' state with the abrogation specific error message" do
it "returns true" do
expect(p_r_incomplete_for_abrogation.eligible_for_auto_retry?).to be true
expect(p_r_incomplete_for_abrogation.eligible_for_incomplete_retry?).to be true
end
end

context "when the payment request is in 'incomplete' state with the missing DA specific error message" do
it "returns true" do
expect(p_r_incomplete_for_missing_da.eligible_for_auto_retry?).to be true
expect(p_r_incomplete_for_missing_da.eligible_for_incomplete_retry?).to be true
end
end

context "when the payment request is not in 'incomplete' state" do
it "returns false" do
expect(p_r_ready.eligible_for_auto_retry?).to be false
expect(p_r_ready.eligible_for_incomplete_retry?).to be false
end
end
end

describe "eligible_for_rejected_or_unpaid_auto_retry?" do
let(:p_r_rejected) { create(:asp_payment_request, :rejected) }
let(:p_r_rejected_rib) do
create(:asp_payment_request, :rejected, reason: "Test d'une raison de blocage d'un paiement bancaire")
end
let(:p_r_unpaid) { create(:asp_payment_request, :unpaid) }
let(:p_r_unpaid_rib) do
create(:asp_payment_request, :unpaid, reason: "Test d'une raison de blocage d'un paiement bancaire")
end

context "when the payment request is in 'rejected' state without a RIB reason" do
it "returns false" do
expect(p_r_rejected.eligible_for_rejected_or_unpaid_auto_retry?).to be false
end
end

context "when the payment request is in 'rejected' state with a RIB reason" do
it "returns true" do
expect(p_r_rejected_rib.eligible_for_rejected_or_unpaid_auto_retry?).to be true
end
end

context "when the payment request is in 'unpaid' state without a RIB reason" do
it "returns false" do
expect(p_r_unpaid.eligible_for_rejected_or_unpaid_auto_retry?).to be false
end
end

context "when the payment request is in 'unpaid' state with a RIB reason" do
it "returns true" do
expect(p_r_unpaid_rib.eligible_for_rejected_or_unpaid_auto_retry?).to be true
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/schoolings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end
end

describe "retry_eligibile_payment_requests" do
describe "retry_eligible_payment_requests" do
let(:expected_error_message) do
I18n.t(
"asp/payment_request.attributes.ready_state_validation.needs_abrogated_attributive_decision",
Expand Down

0 comments on commit 65cec07

Please sign in to comment.