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