From 447ea1b9a8c9df174c73c78e02ca75109f9a5b19 Mon Sep 17 00:00:00 2001 From: sebastiencarceles Date: Thu, 16 Feb 2023 14:11:36 +0100 Subject: [PATCH] don't prefill with an incorrect value --- spec/models/prefill_params_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/models/prefill_params_spec.rb b/spec/models/prefill_params_spec.rb index 872cdb5f0..4764a1255 100644 --- a/spec/models/prefill_params_spec.rb +++ b/spec/models/prefill_params_spec.rb @@ -6,6 +6,7 @@ RSpec.describe PrefillParams do let(:dossier) { create(:dossier, :brouillon, procedure: procedure) } let(:types_de_champ_public) { [] } let(:types_de_champ_private) { [] } + let(:api_annuaire_education_body) { File.read('spec/fixtures/files/api_education/annuaire_education.json') } subject(:prefill_params_array) { described_class.new(dossier, params).to_a } @@ -17,6 +18,11 @@ RSpec.describe PrefillParams do VCR.insert_cassette('api_geo_departements') VCR.insert_cassette('api_geo_communes') VCR.insert_cassette('api_geo_epcis') + + stub_request(:get, /https:\/\/data.education.gouv.fr\/api\/records\/1.0/).to_return( + body: api_annuaire_education_body, + status: 200 + ) end after do @@ -225,7 +231,6 @@ RSpec.describe PrefillParams do it_behaves_like "a champ public value that is unauthorized", :regions, "value" it_behaves_like "a champ public value that is unauthorized", :departements, "value" it_behaves_like "a champ public value that is unauthorized", :communes, "value" - # TODO: SEB validation it_behaves_like "a champ public value that is unauthorized", :annuaire_education, "value" it_behaves_like "a champ public value that is unauthorized", :multiple_drop_down_list, ["value"] context "when the public type de champ is unauthorized because of wrong value format (repetition)" do @@ -251,6 +256,12 @@ RSpec.describe PrefillParams do expect(prefill_params_array).to match([]) end end + + context "when the annuaire education can't find the school for the given value" do + let(:api_annuaire_education_body) { File.read('spec/fixtures/files/api_education/annuaire_education_empty.json') } + + it_behaves_like "a champ public value that is unauthorized", :annuaire_education, "value" + end end private