add possible and example values

This commit is contained in:
sebastiencarceles 2023-02-06 12:12:23 +01:00
parent f836f57e98
commit 5ac80f968a
4 changed files with 58 additions and 7 deletions

View file

@ -1,6 +1,8 @@
class TypesDeChamp::PrefillEpciTypeDeChamp < TypesDeChamp::PrefillTypeDeChamp
def possible_values
departements.map { |departement| "#{departement[:code]} (#{departement[:name]})" }
departements.map do |departement|
"#{departement[:code]} (#{departement[:name]}) : https://geo.api.gouv.fr/epcis?codeDepartement=#{departement[:code]}"
end
end
def example_value

View file

@ -128,12 +128,13 @@ en:
iban_html: An Iban number
yes_no_html: '"true" for Yes, "false" pour No'
checkbox_html: '"true" to check, "false" to uncheck'
pays_html: An <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank">ISO 3166-2 country code</a>
pays_html: An <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank" rel="noopener noreferrer">ISO 3166-2 country code</a>
departements_html: A <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">department number</a>
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank">INSEE region code</a>
regions_html: An <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">INSEE region code</a>
date_html: ISO8601 date
datetime_html: ISO8601 datetime
drop_down_list_other_html: Any value
epci_html: An array of the department code and the <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">EPCI one</a>.
examples:
title: Example
text: Short text

View file

@ -119,12 +119,13 @@ fr:
iban_html: Un numéro Iban
yes_no_html: '"true" pour Oui, "false" pour Non'
checkbox_html: '"true" pour coché, "false" pour décoché'
pays_html: Un <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank">code pays ISO 3166-2</a>
pays_html: Un <a href="https://en.wikipedia.org/wiki/ISO_3166-2" target="_blank" rel="noopener noreferrer">code pays ISO 3166-2</a>
departements_html: Un <a href="https://fr.wikipedia.org/wiki/Num%C3%A9rotation_des_d%C3%A9partements_fran%C3%A7ais" target="_blank">numéro de département</a>
regions_html: Un <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank">code INSEE de région</a>
regions_html: Un <a href="https://fr.wikipedia.org/wiki/R%C3%A9gion_fran%C3%A7aise" target="_blank" rel="noopener noreferrer">code INSEE de région</a>
datetime_html: Datetime au format ISO8601
date_html: Date au format ISO8601
drop_down_list_other_html: Toute valeur
epci_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">celui de l'EPCI</a>.
examples:
title: Exemple
text: Texte court

View file

@ -2,14 +2,55 @@
RSpec.describe TypesDeChamp::PrefillEpciTypeDeChamp do
let(:type_de_champ) { build(:type_de_champ_epci) }
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 'ancestors' do
subject { described_class.new(type_de_champ) }
it { is_expected.to be_kind_of(TypesDeChamp::PrefillEpciTypeDeChamp) }
end
# TODO: SEB describe '#possible_values'
# TODO: SEB describe '#example_value'
describe '#possible_values' do
let(:expected_values) do
departements.map { |departement| "#{departement[:code]} (#{departement[:name]}) : https://geo.api.gouv.fr/epcis?codeDepartement=#{departement[:code]}" }
end
subject(:possible_values) { described_class.new(type_de_champ).possible_values }
before do
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_epcis')
end
after do
VCR.eject_cassette('api_geo_departements')
VCR.eject_cassette('api_geo_epcis')
end
it { expect(possible_values).to match(expected_values) }
end
describe '#example_value' do
let(:departement_code) { departements.pick(:code) }
let(:epci_code) { APIGeoService.epcis(departement_code).pick(:code) }
subject(:example_value) { described_class.new(type_de_champ).example_value }
before do
VCR.insert_cassette('api_geo_departements')
VCR.insert_cassette('api_geo_epcis')
end
after do
VCR.eject_cassette('api_geo_departements')
VCR.eject_cassette('api_geo_epcis')
end
it { is_expected.to eq([departement_code, epci_code]) }
end
describe '#transform_value_to_assignable_attributes' do
subject(:transform_value_to_assignable_attributes) { described_class.build(type_de_champ).transform_value_to_assignable_attributes(value) }
@ -44,4 +85,10 @@ RSpec.describe TypesDeChamp::PrefillEpciTypeDeChamp do
it { is_expected.to match({ code_departement: '01', value: '200042935' }) }
end
end
private
def departements
APIGeoService.departements.sort_by { |departement| departement[:code] }
end
end