fix(dossier): add value_json to dossier projection

This commit is contained in:
Paul Chavard 2023-04-03 16:05:18 +02:00
parent 8945777b56
commit b3f58a24cb
2 changed files with 36 additions and 1 deletions

View file

@ -35,7 +35,7 @@ class DossierProjectionService
types_de_champ: { stable_id: fields.map { |f| f[COLUMN] } },
dossier_id: dossiers_ids
)
.select(:dossier_id, :value, :type_de_champ_id, :stable_id, :type, :external_id, :data) # we cannot pluck :value, as we need the champ.to_s method
.select(:dossier_id, :value, :type_de_champ_id, :stable_id, :type, :external_id, :data, :value_json) # we cannot pluck :value, as we need the champ.to_s method
.group_by(&:stable_id) # the champs are redispatched to their respective fields
.map do |stable_id, champs|
field = fields.find { |f| f[COLUMN] == stable_id.to_s }

View file

@ -1,4 +1,11 @@
describe DossierProjectionService do
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
allow(Rails).to receive(:cache).and_return(memory_store)
Rails.cache.clear
end
describe '#project' do
subject { described_class.project(dossiers_ids, fields) }
@ -47,6 +54,34 @@ describe DossierProjectionService do
end
end
context 'with commune champ', vcr: { cassette_name: 'api_geo_communes' } do
let!(:procedure) { create(:procedure, types_de_champ_public: [{ type: :communes }]) }
let!(:dossier) { create(:dossier, procedure:) }
let(:dossiers_ids) { [dossier.id] }
let(:fields) do
[
{
"table" => "type_de_champ",
"column" => procedure.active_revision.types_de_champ_public[0].stable_id.to_s
}
]
end
before do
dossier.champs_public.first.update(code_postal: '63290')
dossier.champs_public.first.update(value: '63102')
end
let(:result) { subject }
it 'returns champ value' do
expect(result.length).to eq(1)
expect(result[0].dossier_id).to eq(dossier.id)
expect(result[0].columns[0]).to eq('Châteldon (63290)')
end
end
context 'attributes by attributes' do
let(:fields) { [{ "table" => table, "column" => column }] }
let(:dossiers_ids) { [dossier.id] }