Merge pull request #5604 from betagouv/feat/5595

feat/5595 - Add iban type de champ
This commit is contained in:
Kara Diaby 2020-09-23 16:14:01 +02:00 committed by GitHub
commit 2dc745b459
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 72 additions and 1 deletions

View file

@ -42,6 +42,7 @@ gem 'groupdate'
gem 'haml-rails'
gem 'hashie'
gem 'http_accept_language'
gem 'iban-tools'
gem 'jquery-rails' # Use jquery as the JavaScript library
gem 'jwt'
gem 'kaminari', '1.2.1' # Pagination

View file

@ -341,6 +341,7 @@ GEM
httpclient (2.8.3)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
iban-tools (1.1.0)
ice_nine (0.11.2)
ipaddress (0.8.3)
jaro_winkler (1.5.4)
@ -813,6 +814,7 @@ DEPENDENCIES
haml-rails
hashie
http_accept_language
iban-tools
jquery-rails
jwt
kaminari (= 1.2.1)

View file

@ -1272,6 +1272,11 @@ enum TypeDeChamp {
"""
header_section
"""
Iban
"""
iban
"""
Nombre entier
"""

View file

@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: champs
#
# id :integer not null, primary key
# private :boolean default(FALSE), not null
# row :integer
# type :string
# value :string
# created_at :datetime
# updated_at :datetime
# dossier_id :integer
# etablissement_id :integer
# parent_id :bigint
# type_de_champ_id :integer
#
class Champs::IbanChamp < Champ
validates_with IbanValidator
end

View file

@ -46,7 +46,8 @@ class TypeDeChamp < ApplicationRecord
siret: 'siret',
carte: 'carte',
repetition: 'repetition',
titre_identite: 'titre_identite'
titre_identite: 'titre_identite',
iban: 'iban'
}
belongs_to :revision, class_name: 'ProcedureRevision', optional: true

View file

@ -0,0 +1,2 @@
class TypesDeChamp::IbanTypeDeChamp < TypesDeChamp::TypeDeChampBase
end

View file

@ -0,0 +1,11 @@
require 'iban-tools'
class IbanValidator < ActiveModel::Validator
def validate(record)
if record.value.present?
unless IBANTools::IBAN.valid?(record.value)
record.errors.add :iban, record.errors.generate_message(:value, :invalid)
end
end
end
end

View file

@ -0,0 +1 @@
%p= champ.blank? ? 'Iban non fourni' : champ

View file

@ -30,6 +30,8 @@
= render partial: "shared/champs/piece_justificative/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:siret)
= render partial: "shared/champs/siret/show", locals: { champ: c, profile: profile }
- when TypeDeChamp.type_champs.fetch(:iban)
= render partial: "shared/champs/iban/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:textarea)
= render partial: "shared/champs/textarea/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:date)

View file

@ -0,0 +1,4 @@
= form.text_field :value,
placeholder: "27 caractères au format FR7630006000011234567890189",
required: champ.mandatory?,
aria: { describedby: describedby_id(champ) }

View file

@ -34,3 +34,4 @@ fr:
carte: 'Carte'
repetition: 'Bloc répétable'
titre_identite: 'Titre identité'
iban: 'Iban'

View file

@ -155,6 +155,10 @@ FactoryBot.define do
type_de_champ { association :type_de_champ_carte, procedure: dossier.procedure }
end
factory :champ_iban, class: 'Champs::IbanChamp' do
type_de_champ { association :type_de_champ_iban, procedure: dossier.procedure }
end
factory :champ_siret, class: 'Champs::SiretChamp' do
association :type_de_champ, factory: [:type_de_champ_siret]
association :etablissement, factory: [:etablissement]

View file

@ -139,6 +139,9 @@ FactoryBot.define do
factory :type_de_champ_siret do
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
end
factory :type_de_champ_iban do
type_champ { TypeDeChamp.type_champs.fetch(:iban) }
end
factory :type_de_champ_carte do
type_champ { TypeDeChamp.type_champs.fetch(:carte) }
end

View file

@ -0,0 +1,12 @@
describe Champs::IbanChamp do
describe '#valid?' do
it do
expect(build(:champ_iban, value: nil)).to be_valid
expect(build(:champ_iban, value: "FR35 KDSQFDJQSMFDQMFDQ")).to_not be_valid
expect(build(:champ_iban, value: "FR7630006000011234567890189")).to be_valid
expect(build(:champ_iban, value: "FR76 3000 6000 0112 3456 7890 189")).to be_valid
expect(build(:champ_iban, value: "FR76 3000 6000 0112 3456 7890 189DSF")).to_not be_valid
end
end
end

View file

@ -74,6 +74,7 @@ describe ProcedureExportService do
"siret",
"carte",
"titre_identite",
"iban",
"text"
]
end
@ -158,6 +159,7 @@ describe ProcedureExportService do
"siret",
"carte",
"titre_identite",
"iban",
"text"
]
end
@ -238,6 +240,7 @@ describe ProcedureExportService do
"siret",
"carte",
"titre_identite",
"iban",
"text"
]
end