don't clean the rna champ value

Cleaning the value is useless, when fetching the association,
as the value will be re-written by the dossier update, when the user
fills in the dossier.

Furthermore we need the value to persist when prefilling the champ.
This commit is contained in:
sebastiencarceles 2023-01-13 14:52:16 +01:00
parent 7e55aca107
commit 33fa40eda2
3 changed files with 13 additions and 17 deletions

View file

@ -6,7 +6,9 @@ module RNAChampAssociationFetchableConcern
update!(data: data, value: rna)
nil
rescue APIEntreprise::API::Error, ActiveRecord::RecordInvalid => error
update(data: nil, value: nil)
self.data = nil
self.value = rna
save(validate: false)
if error.try(:network_error?) && !APIEntrepriseService.api_up?
:network_error
else

View file

@ -37,10 +37,8 @@ describe Champs::RNAController, type: :controller do
subject! { get :show, params: params, format: :turbo_stream }
it 'clears the data and value on the model' do
champ.reload
expect(champ.data).to eq({})
expect(champ.value).to eq("")
it 'clears the data on the model' do
expect(champ.reload.data).to eq({})
end
it 'clears any information or error message' do
@ -55,10 +53,8 @@ describe Champs::RNAController, type: :controller do
subject! { get :show, params: params, format: :turbo_stream }
it 'clears the data and value on the model' do
champ.reload
expect(champ.data).to be_nil
expect(champ.value).to be_nil
it 'clears the data on the model' do
expect(champ.reload.data).to be_nil
end
it 'displays a “RNA is invalid” error message' do
@ -94,10 +90,8 @@ describe Champs::RNAController, type: :controller do
subject! { get :show, params: params, format: :turbo_stream }
it 'clears the data and value on the model' do
champ.reload
expect(champ.data).to be_nil
expect(champ.value).to be_nil
it 'clears the data on the model' do
expect(champ.reload.data).to be_nil
end
it 'displays a “API is unavailable” error message' do

View file

@ -10,10 +10,10 @@ RSpec.describe RNAChampAssociationFetchableConcern do
subject(:fetch_association!) { champ.fetch_association!(rna) }
shared_examples "an association fetcher" do |expected_result, expected_value, expected_data|
shared_examples "an association fetcher" do |expected_result, _expected_value, expected_data|
it { expect(fetch_association!).to eq(expected_result) }
it { expect { fetch_association! }.to change { champ.reload.value }.to(expected_value) }
it { expect { fetch_association! }.to change { champ.reload.value }.to(rna) }
it { expect { fetch_association! }.to change { champ.reload.data }.to(expected_data) }
end
@ -31,7 +31,7 @@ RSpec.describe RNAChampAssociationFetchableConcern do
let(:status) { 422 }
let(:body) { '' }
it_behaves_like "an association fetcher", nil, nil, nil
it_behaves_like "an association fetcher", nil, '1234', nil
end
context 'when the RNA is unknow' do
@ -49,7 +49,7 @@ RSpec.describe RNAChampAssociationFetchableConcern do
before { expect(APIEntrepriseService).to receive(:api_up?).and_return(false) }
it_behaves_like "an association fetcher", :network_error, nil, nil
it_behaves_like "an association fetcher", :network_error, 'W595001988', nil
end
context 'when the RNA informations are retrieved successfully' do