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.
- Loading branch information
Showing
15 changed files
with
241 additions
and
182 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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module ASP | ||
module Mappers | ||
module Adresse | ||
class BaseMapper | ||
PRINCIPAL_ADDRESS_TYPE = "PRINCIPALE" | ||
|
||
MAPPING = { | ||
codecominsee: :address_city_insee_code, | ||
codepostalcedex: :address_postal_code | ||
}.freeze | ||
|
||
attr_reader :student | ||
|
||
def initialize(payment_request) | ||
@student = payment_request.student | ||
end | ||
|
||
MAPPING.each do |name, attr| | ||
define_method(name) { student[attr] } | ||
end | ||
|
||
def codetypeadr | ||
PRINCIPAL_ADDRESS_TYPE | ||
end | ||
|
||
def codeinseepays | ||
InseeCountryCodeMapper.call(student.address_country_code) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 | ||
|
||
module ASP | ||
module Entities | ||
module Adresse | ||
class Base < Entity | ||
attribute :codetypeadr, :string | ||
attribute :codecominsee, :string | ||
attribute :codeinseepays, :string | ||
attribute :codepostalcedex, :string | ||
|
||
validates_presence_of %i[ | ||
codetypeadr | ||
codeinseepays | ||
codepostalcedex | ||
codecominsee | ||
] | ||
|
||
def fragment(xml) | ||
xml.codetypeadr(codetypeadr) | ||
xml.codeinseepays(codeinseepays) | ||
xml.codepostalcedex(codepostalcedex) | ||
xml.codecominsee(codecominsee) | ||
end | ||
|
||
def self.payment_mapper_class | ||
ASP::Mappers::Adresse::BaseMapper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module ASP | ||
module Entities | ||
module Adresse | ||
class Etranger < Base | ||
# NOTE: for students living outside of France we take address attributes from the establishment | ||
def fragment(xml) | ||
establishment = payment_request.pfmp.establishment | ||
|
||
raise ASP::Errors::MissingEstablishmentCommuneCodeError if establishment.commune_code.blank? | ||
raise ASP::Errors::MissingEstablishmentPostalCodeError if establishment.postal_code.blank? | ||
|
||
xml.codetypeadr(Mappers::Adresse::BaseMapper::PRINCIPAL_ADDRESS_TYPE) | ||
xml.codecominsee(establishment.commune_code) | ||
xml.codepostalcedex(establishment.postal_code) | ||
xml.codeinseepays(InseeCodes::FRANCE_INSEE_COUNTRY_CODE) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module ASP | ||
module Entities | ||
module Adresse | ||
class Indu < Base | ||
attribute :pointremise, :string | ||
attribute :cpltdistribution, :string | ||
|
||
validates_presence_of %i[ | ||
pointremise | ||
cpltdistribution | ||
] | ||
|
||
def fragment(xml) | ||
xml.pointremise(payment_request.student.address_line1.slice(0, 38)) # Max 38 characters | ||
xml.cpltdistribution(payment_request.student.address_line2&.slice(0, 38)) # Max 38 characters | ||
xml.codetypeadr(ASP::Mappers::Addresse::BaseMapper::PRINCIPAL_ADDRESS_TYPE) | ||
xml.codeinseepays(InseeCountryCodeMapper.call(payment_request.student.address_country_code)) | ||
xml.codepostalcedex(payment_request.student.address_postal_code) | ||
xml.codecominsee(payment_request.student.address_city_insee_code) | ||
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
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe ASP::Entities::Adresse::Base, type: :model do | ||
subject(:model) { described_class.from_payment_request(request) } | ||
|
||
let(:request) { create(:asp_payment_request, :ready) } | ||
let(:student) { create(:student, :with_all_asp_info, :with_french_address) } | ||
|
||
before do | ||
request.pfmp.update!(student: student) | ||
request.reload | ||
end | ||
|
||
describe "validation" do | ||
it { is_expected.to validate_presence_of(:codepostalcedex) } | ||
it { is_expected.to validate_presence_of(:codecominsee) } | ||
it { is_expected.to validate_presence_of(:codeinseepays) } | ||
it { is_expected.to validate_presence_of(:codetypeadr) } | ||
end | ||
|
||
it_behaves_like "an XML-fragment producer" do | ||
let(:entity) { described_class.from_payment_request(request) } | ||
let(:probe) { ["codecominsee", student.address_city_insee_code] } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe ASP::Entities::Adresse::Etranger, type: :model do | ||
subject(:model) { described_class.from_payment_request(request) } | ||
|
||
let(:request) { create(:asp_payment_request, :ready) } | ||
let(:student) { create(:student, :with_all_asp_info, :with_french_address) } | ||
|
||
describe "validation" do | ||
it { is_expected.to validate_presence_of(:codepostalcedex) } | ||
it { is_expected.to validate_presence_of(:codecominsee) } | ||
it { is_expected.to validate_presence_of(:codeinseepays) } | ||
it { is_expected.to validate_presence_of(:codetypeadr) } | ||
end | ||
|
||
describe "fragment" do | ||
let(:student) { create(:student, :with_all_asp_info, :with_foreign_address) } | ||
let(:establishment) { request.pfmp.establishment } | ||
|
||
before do | ||
establishment.update(commune_code: "12345", postal_code: "54321") | ||
end | ||
|
||
it_behaves_like "an XML-fragment producer" do | ||
let(:entity) { described_class.from_payment_request(request) } | ||
let(:probe) { %w[codetypeadr PRINCIPALE] } | ||
|
||
it "uses the establishment details for the address" do # rubocop:disable RSpec/MultipleExpectations | ||
expect(document.at("codecominsee").text).to eq establishment.commune_code | ||
expect(document.at("codepostalcedex").text).to eq establishment.postal_code | ||
expect(document.at("codeinseepays").text).to eq InseeCodes::FRANCE_INSEE_COUNTRY_CODE | ||
end | ||
end | ||
|
||
context "when establishment commune_code is missing" do | ||
before { establishment.update(commune_code: nil) } | ||
|
||
it "raises MissingEstablishmentCommuneCodeError" do | ||
expect { described_class.from_payment_request(request).to_xml(Nokogiri::XML::Builder.new) } | ||
.to raise_error(ASP::Errors::MissingEstablishmentCommuneCodeError) | ||
end | ||
end | ||
|
||
context "when establishment postal_code is missing" do | ||
before { establishment.update(postal_code: nil) } | ||
|
||
it "raises MissingEstablishmentPostalCodeError" do | ||
expect { described_class.from_payment_request(request).to_xml(Nokogiri::XML::Builder.new) } | ||
.to raise_error(ASP::Errors::MissingEstablishmentPostalCodeError) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe ASP::Entities::Adresse::Indu, type: :model do | ||
describe "fragment" do | ||
let(:request) { create(:asp_payment_request, :ready) } | ||
let(:student) { create(:student, :with_all_asp_info, :with_french_address) } | ||
|
||
let(:pfmp) { create(:pfmp, :rectified) } | ||
|
||
before do | ||
pfmp.student.update( | ||
address_line1: "A" * 50, | ||
address_line2: "B" * 50 | ||
) | ||
end | ||
|
||
it "creates an Adresse instance with truncated attrs" do # rubocop:disable RSpec/ExampleLength | ||
adresse = described_class.from_payment_request(pfmp.latest_payment_request).to_xml(Nokogiri::XML::Builder.new) | ||
expect(adresse).to have_attributes( | ||
codetypeadr: ASP::Mappers::Adresse::BaseMapper::PRINCIPAL_ADDRESS_TYPE, | ||
pointremise: "A" * 38, | ||
cpltdistribution: "B" * 38 | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.