generated from betagouv/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split InduMapper into InduFranceMapper + InduEtrangerMapper
- Loading branch information
Showing
7 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module ASP | ||
module Mappers | ||
module Adresse | ||
class InduEtrangerMapper < FranceMapper | ||
def localiteetranger | ||
student.address_line1 | ||
end | ||
|
||
def bureaudistribetranger | ||
student.address_line2 | ||
end | ||
|
||
def voiepointgeoetranger | ||
student.address_line2 | ||
end | ||
|
||
def districtetranger | ||
student.address_line2 | ||
end | ||
|
||
def regionetranger | ||
student.address_line2 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module ASP | ||
module Entities | ||
module Adresse | ||
class InduEtranger < Entity | ||
ADRESSE_ATTR_MAX_LENGTH = 38 | ||
|
||
attribute :localiteetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH | ||
attribute :bureaudistribetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH | ||
attribute :voiepointgeoetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH | ||
attribute :districtetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH | ||
attribute :regionetranger, :string, limit: ADRESSE_ATTR_MAX_LENGTH | ||
attribute :codetypeadr, :string | ||
attribute :codeinseepays, :string | ||
|
||
validates_presence_of %i[ | ||
localiteetranger | ||
bureaudistribetranger | ||
codetypeadr | ||
codeinseepays | ||
] | ||
|
||
def self.payment_mapper_class | ||
Mappers::Adresse::InduEtrangerMapper | ||
end | ||
|
||
def root_node_name | ||
"adresse" | ||
end | ||
|
||
def fragment(xml) # rubocop:disable Metrics/AbcSize | ||
xml.localiteetranger(localiteetranger) | ||
xml.bureaudistribetranger(bureaudistribetranger) | ||
xml.voiepointgeoetranger(voiepointgeoetranger) if voiepointgeoetranger.present? | ||
xml.districtetranger(districtetranger) if districtetranger.present? | ||
xml.regionetranger(regionetranger) if regionetranger.present? | ||
xml.codetypeadr(codetypeadr) | ||
xml.codeinseepays(codeinseepays) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe ASP::Entities::Adresse::InduEtranger, type: :model do | ||
describe "fragment" do | ||
let(:pfmp) { create(:pfmp, :rectified) } | ||
|
||
before do | ||
pfmp.student.update( | ||
address_line1: "A" * 50, | ||
address_line2: "B" * 50 | ||
) | ||
end | ||
|
||
describe "validation" do | ||
it { is_expected.to validate_presence_of(:localiteetranger) } | ||
it { is_expected.to validate_presence_of(:bureaudistribetranger) } | ||
it { is_expected.to validate_presence_of(:codetypeadr) } | ||
end | ||
|
||
it_behaves_like "an XML-fragment producer" do | ||
let(:entity) { described_class.from_payment_request(pfmp.latest_payment_request) } | ||
let(:probe) { %w[codetypeadr PRINCIPALE] } | ||
|
||
it "uses the establishment details for the address" do # rubocop:disable RSpec/MultipleExpectations | ||
expect(document.at("localiteetranger").text).to eq "A" * 38 | ||
expect(document.at("bureaudistribetranger").text).to eq "B" * 38 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters