2017-12-14 15:51:45 +01:00
|
|
|
describe DossierSerializer do
|
|
|
|
describe '#attributes' do
|
|
|
|
subject { DossierSerializer.new(dossier).serializable_hash }
|
|
|
|
|
|
|
|
context 'when the dossier is en_construction' do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
|
|
|
|
it { is_expected.to include(initiated_at: dossier.en_construction_at) }
|
|
|
|
it { is_expected.to include(state: 'initiated') }
|
|
|
|
end
|
2017-12-14 15:53:02 +01:00
|
|
|
|
|
|
|
context 'when the dossier is en instruction' do
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction) }
|
|
|
|
|
|
|
|
it { is_expected.to include(received_at: dossier.en_instruction_at) }
|
2017-12-04 20:23:57 +01:00
|
|
|
end
|
2018-11-13 18:48:04 +01:00
|
|
|
|
|
|
|
context 'champs' do
|
|
|
|
subject { super()[:champs] }
|
|
|
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_two_quartier_prioritaires, procedure: create(:procedure, :published, :with_api_carto, :with_type_de_champ)) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
dossier.champs << create(:champ_carte)
|
|
|
|
dossier.champs << create(:champ_siret)
|
|
|
|
dossier.champs << create(:champ_integer_number)
|
|
|
|
dossier.champs << create(:champ_decimal_number)
|
|
|
|
dossier.champs << create(:champ_linked_drop_down_list)
|
|
|
|
end
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect(subject.size).to eq(8)
|
|
|
|
|
|
|
|
expect(subject[0][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:text))
|
|
|
|
expect(subject[1][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:carte))
|
|
|
|
expect(subject[2][:type_de_champ][:type_champ]).to eq(TypeDeChamp.type_champs.fetch(:siret))
|
|
|
|
expect(subject[7][:type_de_champ][:type_champ]).to eq('quartier_prioritaire')
|
|
|
|
|
|
|
|
expect(subject[1][:geo_areas].size).to eq(0)
|
|
|
|
expect(subject[2][:etablissement]).to be_present
|
|
|
|
expect(subject[2][:entreprise]).to be_present
|
|
|
|
|
|
|
|
expect(subject[3][:value]).to eq(42)
|
|
|
|
expect(subject[4][:value]).to eq(42.1)
|
|
|
|
expect(subject[5][:value]).to eq({ primary: nil, secondary: nil })
|
|
|
|
}
|
|
|
|
end
|
2017-12-14 15:51:45 +01:00
|
|
|
end
|
|
|
|
end
|