fix(rnf): no crash on identifiers with spaces

This commit is contained in:
Paul Chavard 2024-08-01 17:51:46 +02:00
parent 3501208191
commit 25d4e7dfee
No known key found for this signature in database
3 changed files with 27 additions and 1 deletions

View file

@ -17,6 +17,12 @@ class API::Client
timeout: TIMEOUT) timeout: TIMEOUT)
end end
handle_response(response, schema:) handle_response(response, schema:)
rescue StandardError => reason
if reason.is_a?(URI::InvalidURIError)
Failure(Error[:uri, 0, false, reason])
else
Failure(Error[:error, 0, false, reason])
end
end end
private private

View file

@ -2,7 +2,7 @@ class Champs::RNFChamp < Champ
store_accessor :data, :title, :email, :phone, :createdAt, :updatedAt, :dissolvedAt, :address, :status store_accessor :data, :title, :email, :phone, :createdAt, :updatedAt, :dissolvedAt, :address, :status
def rnf_id def rnf_id
external_id external_id&.gsub(/[:space:]/, '')
end end
def value def value

View file

@ -48,6 +48,26 @@ describe Champs::RNFChamp, type: :model do
end end
end end
context 'success (with space)' do
let(:external_id) { '075-FDD- 00003-01 ' }
it {
expect(subject.value!).to include({
id: 3,
rnfId: '075-FDD-00003-01'
})
}
end
context 'success (with tab)' do
let(:external_id) { '075-FDD-0 0003-01 ' }
it {
expect(subject.value!).to include({
id: 3,
rnfId: '075-FDD-00003-01'
})
}
end
context 'failure (schema)' do context 'failure (schema)' do
let(:response_type) { 'invalid' } let(:response_type) { 'invalid' }
it { it {