Skip to content

Commit

Permalink
spec(normalized_address): add simple spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mfo committed Aug 22, 2024
1 parent 7182a4e commit 70983c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/address_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def initialize(etablissement)

delegate(*ADDRESS_PARTS, to: :@presenter)

def initialize(champs_or_etablissement)
def initialize(champ_or_etablissement)
@presenter = make(champ_or_etablissement)
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
factory :champ_do_not_use_siret, class: 'Champs::SiretChamp' do
association :etablissement, factory: [:etablissement]
value { '44011762001530' }
value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself) }
end

factory :champ_do_not_use_rna, class: 'Champs::RNAChamp' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Maintenance

it 'updates value_json' do
expect { subject }.to change { element.reload.value_json }
.from(nil)
.from(anything)
.to({
"city_code" => "92009",
"city_name" => "Bois-Colombes",
Expand Down
31 changes: 31 additions & 0 deletions spec/views/shared/dossiers/_normalized_address.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

describe 'shared/dossiers/normalized_address', type: :view do
before { render 'shared/dossiers/normalized_address', address: }

context 'given an champ' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
let(:address) { AddressProxy.new(dossier.champs.first) }

it 'render address' do
AddressProxy::ADDRESS_PARTS.each do |address_part|
expect(rendered).to have_text(address_part)
end
end
end

context 'given an etablissement' do
let(:etablissement) { create(:etablissement) }
let(:address) { AddressProxy.new(etablissement) }

it 'render address' do
expect(rendered).to have_text("6 RUE RAOUL NORDLING")
expect(rendered).to have_text("BOIS COLOMBES 92270")
expect(rendered).to have_text("92009")
expect(rendered).to have_text("92270")
expect(rendered).to have_text("Hauts-de-Seine – 92")
expect(rendered).to have_text("Île-de-France – 11")
end
end
end

0 comments on commit 70983c5

Please sign in to comment.