diff --git a/app/models/concerns/dgfip_extensions/api_impot_particulier_modalities.rb b/app/models/concerns/dgfip_extensions/api_impot_particulier_modalities.rb index 34368a3c9..f64d32f21 100644 --- a/app/models/concerns/dgfip_extensions/api_impot_particulier_modalities.rb +++ b/app/models/concerns/dgfip_extensions/api_impot_particulier_modalities.rb @@ -9,10 +9,8 @@ module DGFIPExtensions::APIImpotParticulierModalities add_attributes :france_connect_authorization_id validates :france_connect_authorization_id, presence: true, - inclusion: { in: organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).pluck(:id), message: 'coucou' }, + inclusion: { in: ->(authorization_request) { authorization_request.organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).pluck(:id) } }, if: -> { modalities == 'with_france_connect' && need_complete_validation?(:modalities) } - - validate :france_connect_authorization_ end def associated_france_connect_authorization diff --git a/spec/models/authorization_request/api_impot_particulier_spec.rb b/spec/models/authorization_request/api_impot_particulier_spec.rb index 3696f3667..14ee1747d 100644 --- a/spec/models/authorization_request/api_impot_particulier_spec.rb +++ b/spec/models/authorization_request/api_impot_particulier_spec.rb @@ -12,7 +12,8 @@ volumetrie_appels_par_minute:, volumetrie_justification:, safety_certification_begin_date:, - safety_certification_end_date: + safety_certification_end_date:, + organization: ) end @@ -24,6 +25,7 @@ let(:volumetrie_justification) { nil } let(:safety_certification_begin_date) { nil } let(:safety_certification_end_date) { nil } + let(:organization) { nil } describe 'volumetrie validation' do before { authorization_request.current_build_step = 'volumetrie' } @@ -106,6 +108,29 @@ it { is_expected.not_to be_valid } end + + context 'with a france connect authorization id from another organization' do + let(:validated_france_connect_authorization_request) { create(:authorization_request, :france_connect, :validated) } + let(:france_connect_authorization_id) { validated_france_connect_authorization_request.authorizations.first.id } + + it { is_expected.not_to be_valid } + end + + context 'with a revoked france connect authorization id from the same organization' do + let(:validated_france_connect_authorization_request) { create(:authorization_request, :france_connect, :revoked) } + let(:organization) { validated_france_connect_authorization_request.organization } + let(:france_connect_authorization_id) { validated_france_connect_authorization_request.authorizations.first.id } + + it { is_expected.not_to be_valid } + end + + context 'with a validated france connect authorization id from the same organization' do + let(:validated_france_connect_authorization_request) { create(:authorization_request, :france_connect, :validated) } + let(:organization) { validated_france_connect_authorization_request.organization } + let(:france_connect_authorization_id) { validated_france_connect_authorization_request.authorizations.first.id } + + it { is_expected.to be_valid } + end end end