refactor(logic): compute sub champ values

This commit is contained in:
Paul Chavard 2024-02-13 11:24:58 +01:00
parent 641a33e1e0
commit 93635b3516
7 changed files with 39 additions and 49 deletions

View file

@ -93,7 +93,7 @@ describe Logic::ChampValue do
let(:champ) { create(:champ_departements, value: '02') }
it { expect(champ_value(champ.stable_id).type([champ.type_de_champ])).to eq(:departement_enum) }
it { is_expected.to eq('02') }
it { is_expected.to eq({ value: '02', code_region: '32' }) }
end
context 'region tdc' do
@ -102,6 +102,23 @@ describe Logic::ChampValue do
it { is_expected.to eq('04') }
end
context 'commune tdc' do
let(:champ) { create(:champ_communes, code_postal: '92500', external_id: '92063') }
it { is_expected.to eq({ code_departement: '92', code_region: '11' }) }
end
context 'epci tdc' do
let(:champ) { build(:champ_epci, code_departement: '43') }
before do
champ.save!
champ.update_columns(external_id: '244301016', value: 'CC des Sucs')
end
it { is_expected.to eq({ code_departement: '43', code_region: '84' }) }
end
describe 'errors' do
let(:champ) { create(:champ) }
@ -140,32 +157,4 @@ describe Logic::ChampValue do
end
end
end
describe '#compute_value_json' do
subject { champ_value(champ.stable_id).compute_value_json([champ]) }
context 'commune tdc' do
let(:champ) { create(:champ_communes, code_postal: '92500', external_id: '92063') }
it { is_expected.to eq({ 'code_departement' => '92', 'code_postal' => '92500', 'code_region' => '11' }) }
end
context 'epci tdc' do
let(:champ) { build(:champ_epci, code_departement: '43') }
before do
champ.save!
champ.update_columns(external_id: '244301016', value: 'CC des Sucs')
end
it { is_expected.to eq({ 'code_departement' => '43', 'code_region' => '84' }) }
end
context 'departement tdc' do
let(:champ) { create(:champ_departements, value: '02') }
it { expect(champ_value(champ.stable_id).type([champ.type_de_champ])).to eq(:departement_enum) }
it { is_expected.to eq({ 'code_region' => '32' }) }
end
end
end