! BREAKING : break previous filter by type_de_champ_private
simplify type_de_champ_private -> type_de_champ, fix spec, add facet_spec
This commit is contained in:
parent
2239172fac
commit
305b8c13c7
4 changed files with 142 additions and 182 deletions
|
@ -1,6 +1,5 @@
|
|||
class Facet
|
||||
TYPE_DE_CHAMP = 'type_de_champ'
|
||||
TYPE_DE_CHAMP_PRIVATE = 'type_de_champ_private'
|
||||
|
||||
def initialize(table:, column:, label: nil, virtual: false, type: :text, value_column: :value, filterable: true, classname: '', scope: '')
|
||||
@table = table
|
||||
|
@ -69,57 +68,38 @@ class Facet
|
|||
new(table: 'etablissement', column: 'entreprise_nom_commercial', type: :text),
|
||||
new(table: 'etablissement', column: 'entreprise_raison_sociale', type: :text),
|
||||
new(table: 'etablissement', column: 'entreprise_siret_siege_social', type: :text),
|
||||
new(table: 'etablissement', column: 'entreprise_date_creation', type: :date)
|
||||
)
|
||||
|
||||
facets.push(
|
||||
new(table: 'etablissement', column: 'entreprise_date_creation', type: :date),
|
||||
new(table: 'etablissement', column: 'siret', type: :text),
|
||||
new(table: 'etablissement', column: 'libelle_naf', type: :text),
|
||||
new(table: 'etablissement', column: 'code_postal', type: :text)
|
||||
)
|
||||
end
|
||||
|
||||
facets.concat(procedure.types_de_champ_for_procedure_presentation
|
||||
.pluck(:type_champ, :libelle, :private, :stable_id)
|
||||
.reject { |(type_champ)| type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map do |(type_champ, libelle, is_private, stable_id)|
|
||||
tdc = TypeDeChamp.new(type_champ:, libelle:, private: is_private, stable_id:)
|
||||
if is_private
|
||||
facets_for_type_de_champ_private(tdc)
|
||||
else
|
||||
facets_for_type_de_champ_public(tdc)
|
||||
end
|
||||
end)
|
||||
facets.concat(types_de_champ_facets(procedure))
|
||||
|
||||
facets
|
||||
end
|
||||
|
||||
def self.facets_for_type_de_champ_public(tdc)
|
||||
tdc.dynamic_type.search_paths.map do |path_struct|
|
||||
new(
|
||||
table: TYPE_DE_CHAMP,
|
||||
column: tdc.stable_id.to_s,
|
||||
label: path_struct[:libelle],
|
||||
type: TypeDeChamp.filter_hash_type(tdc.type_champ),
|
||||
value_column: path_struct[:path]
|
||||
)
|
||||
end
|
||||
def self.types_de_champ_facets(procedure)
|
||||
procedure
|
||||
.types_de_champ_for_procedure_presentation
|
||||
.pluck(:type_champ, :libelle, :stable_id)
|
||||
.reject { |(type_champ)| type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map do |(type_champ, libelle, stable_id)|
|
||||
tdc = TypeDeChamp.new(type_champ:, libelle:, stable_id:)
|
||||
|
||||
tdc.dynamic_type.search_paths.map do |path_struct|
|
||||
new(
|
||||
table: TYPE_DE_CHAMP,
|
||||
column: tdc.stable_id.to_s,
|
||||
label: path_struct[:libelle],
|
||||
type: TypeDeChamp.filter_hash_type(tdc.type_champ),
|
||||
value_column: path_struct[:path]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.facets_for_type_de_champ_private(tdc)
|
||||
tdc.dynamic_type.search_paths.map do |path_struct|
|
||||
new(
|
||||
table: TYPE_DE_CHAMP_PRIVATE,
|
||||
column: tdc.stable_id.to_s,
|
||||
label: path_struct[:libelle],
|
||||
type: TypeDeChamp.filter_hash_type(tdc.type_champ),
|
||||
value_column: path_struct[:path]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def self.sva_svr_facets(procedure:, for_filters: false)
|
||||
return if !procedure.sva_svr_enabled?
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
|
||||
SLASH = '/'
|
||||
TYPE_DE_CHAMP = 'type_de_champ'
|
||||
TYPE_DE_CHAMP_PRIVATE = 'type_de_champ_private'
|
||||
|
||||
FILTERS_VALUE_MAX_LENGTH = 100
|
||||
|
||||
|
@ -73,17 +72,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
else
|
||||
ids
|
||||
end
|
||||
when TYPE_DE_CHAMP_PRIVATE
|
||||
ids = dossiers
|
||||
.with_type_de_champ(column)
|
||||
.order("champs.value #{order}")
|
||||
.pluck(:id)
|
||||
if ids.size != count
|
||||
rest = dossiers.where.not(id: ids).order(id: order).pluck(:id)
|
||||
order == 'asc' ? ids + rest : rest + ids
|
||||
else
|
||||
ids
|
||||
end
|
||||
when 'followers_instructeurs'
|
||||
assert_supported_column(table, column)
|
||||
# LEFT OUTER JOIN allows to keep dossiers without assigned instructeurs yet
|
||||
|
@ -129,9 +117,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
when TYPE_DE_CHAMP
|
||||
dossiers.with_type_de_champ(column)
|
||||
.filter_ilike(:champs, value_column, values)
|
||||
when TYPE_DE_CHAMP_PRIVATE
|
||||
dossiers.with_type_de_champ(column)
|
||||
.filter_ilike(:champs, value_column, values)
|
||||
when 'etablissement'
|
||||
if column == 'entreprise_date_creation'
|
||||
dates = values
|
||||
|
@ -182,7 +167,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def human_value_for_filter(filter)
|
||||
if [TYPE_DE_CHAMP, TYPE_DE_CHAMP_PRIVATE].include?(filter[TABLE])
|
||||
if filter[TABLE] == TYPE_DE_CHAMP
|
||||
find_type_de_champ(filter[COLUMN]).dynamic_type.filter_to_human(filter['value'])
|
||||
elsif filter['column'] == 'state'
|
||||
if filter['value'] == 'pending_correction'
|
||||
|
@ -221,7 +206,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
value_column = facet.value_column
|
||||
|
||||
case table
|
||||
when TYPE_DE_CHAMP, TYPE_DE_CHAMP_PRIVATE
|
||||
when TYPE_DE_CHAMP
|
||||
value = find_type_de_champ(column).dynamic_type.human_to_filter(value)
|
||||
end
|
||||
|
||||
|
|
105
spec/models/facet_spec.rb
Normal file
105
spec/models/facet_spec.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
describe Facet do
|
||||
describe "#facets" do
|
||||
context 'when the procedure can have a SIRET number' do
|
||||
let(:procedure) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: Array.new(4) { { type: :text } },
|
||||
types_de_champ_private: Array.new(4) { { type: :text } })
|
||||
end
|
||||
let(:tdc_1) { procedure.active_revision.types_de_champ_public[0] }
|
||||
let(:tdc_2) { procedure.active_revision.types_de_champ_public[1] }
|
||||
let(:tdc_private_1) { procedure.active_revision.types_de_champ_private[0] }
|
||||
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
|
||||
let(:expected) {
|
||||
[
|
||||
{ label: 'Créé le', table: 'self', column: 'created_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Déposé le', table: 'self', column: 'depose_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'En construction le', table: 'self', column: 'en_construction_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'En instruction le', table: 'self', column: 'en_instruction_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Terminé le', table: 'self', column: 'processed_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Mis à jour depuis", table: "self", column: "updated_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Déposé depuis", table: "self", column: "depose_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "En construction depuis", table: "self", column: "en_construction_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "En instruction depuis", table: "self", column: "en_instruction_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Terminé depuis", table: "self", column: "processed_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Statut", table: "self", column: "state", classname: "", virtual: true, scope: 'instructeurs.dossiers.filterable_state', type: :enum, value_column: :value, filterable: true },
|
||||
{ label: 'Demandeur', table: 'user', column: 'email', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Email instructeur', table: 'followers_instructeurs', column: 'email', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', classname: '', virtual: false, type: :enum, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: false },
|
||||
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Raison sociale', table: 'etablissement', column: 'entreprise_raison_sociale', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Date de création', table: 'etablissement', column: 'entreprise_date_creation', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'SIRET', table: 'etablissement', column: 'siret', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Libellé NAF', table: 'etablissement', column: 'libelle_naf', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Code postal', table: 'etablissement', column: 'code_postal', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_1.libelle, table: 'type_de_champ', column: tdc_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_private_1.libelle, table: 'type_de_champ', column: tdc_private_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_private_2.libelle, table: 'type_de_champ', column: tdc_private_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true }
|
||||
].map { Facet.new(**_1) }
|
||||
}
|
||||
|
||||
subject { Facet.facets(procedure:) }
|
||||
|
||||
context 'with explication/header_sections' do
|
||||
let(:types_de_champ_public) { Array.new(4) { { type: :text } } }
|
||||
let(:types_de_champ_private) { Array.new(4) { { type: :text } } }
|
||||
before do
|
||||
procedure.active_revision.types_de_champ_public[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section))
|
||||
procedure.active_revision.types_de_champ_public[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
procedure.active_revision.types_de_champ_private[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section))
|
||||
procedure.active_revision.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
end
|
||||
|
||||
it { expect(subject).to eq(expected) }
|
||||
end
|
||||
|
||||
xcontext 'with rna' do
|
||||
let(:types_de_champ_public) { [{ type: :rna, libelle: 'rna' }] }
|
||||
let(:types_de_champ_private) { [] }
|
||||
xit { expect(subject.map(&:label)).to include('rna – commune') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the procedure is for individuals' do
|
||||
let(:name_field) { Facet.new(label: "Prénom", table: "individual", column: "prenom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:surname_field) { Facet.new(label: "Nom", table: "individual", column: "nom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:gender_field) { Facet.new(label: "Civilité", table: "individual", column: "gender", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
subject { Facet.facets(procedure:) }
|
||||
|
||||
it { is_expected.to include(name_field, surname_field, gender_field) }
|
||||
end
|
||||
|
||||
context 'when the procedure is sva' do
|
||||
let(:procedure) { create(:procedure, :for_individual, :sva) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
let(:decision_on) { Facet.new(label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Facet.new(label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
|
||||
subject { Facet.facets(procedure:) }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
|
||||
context 'when the procedure is svr' do
|
||||
let(:procedure) { create(:procedure, :for_individual, :svr) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
let(:decision_on) { Facet.new(label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Facet.new(label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
|
||||
subject { Facet.facets(procedure:) }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -51,129 +51,20 @@ describe ProcedurePresentation do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#fields" do
|
||||
context 'when the procedure can have a SIRET number' do
|
||||
let(:procedure) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: Array.new(4) { { type: :text } },
|
||||
types_de_champ_private: Array.new(4) { { type: :text } })
|
||||
end
|
||||
let(:tdc_1) { procedure.active_revision.types_de_champ_public[0] }
|
||||
let(:tdc_2) { procedure.active_revision.types_de_champ_public[1] }
|
||||
let(:tdc_private_1) { procedure.active_revision.types_de_champ_private[0] }
|
||||
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
|
||||
let(:expected) {
|
||||
[
|
||||
{ label: 'Créé le', table: 'self', column: 'created_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Déposé le', table: 'self', column: 'depose_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'En construction le', table: 'self', column: 'en_construction_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'En instruction le', table: 'self', column: 'en_instruction_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Terminé le', table: 'self', column: 'processed_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Mis à jour depuis", table: "self", column: "updated_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Déposé depuis", table: "self", column: "depose_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "En construction depuis", table: "self", column: "en_construction_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "En instruction depuis", table: "self", column: "en_instruction_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Terminé depuis", table: "self", column: "processed_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: "Statut", table: "self", column: "state", classname: "", virtual: true, scope: 'instructeurs.dossiers.filterable_state', type: :enum, value_column: :value, filterable: true },
|
||||
{ label: 'Demandeur', table: 'user', column: 'email', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Email instructeur', table: 'followers_instructeurs', column: 'email', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', classname: '', virtual: false, type: :enum, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: false },
|
||||
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Raison sociale', table: 'etablissement', column: 'entreprise_raison_sociale', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Date de création', table: 'etablissement', column: 'entreprise_date_creation', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'SIRET', table: 'etablissement', column: 'siret', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Libellé NAF', table: 'etablissement', column: 'libelle_naf', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Code postal', table: 'etablissement', column: 'code_postal', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_1.libelle, table: 'type_de_champ', column: tdc_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_private_1.libelle, table: 'type_de_champ_private', column: tdc_private_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_private_2.libelle, table: 'type_de_champ_private', column: tdc_private_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true }
|
||||
].map { Facet.new(**_1) }
|
||||
}
|
||||
|
||||
before do
|
||||
procedure.active_revision.types_de_champ_public[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section))
|
||||
procedure.active_revision.types_de_champ_public[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
procedure.active_revision.types_de_champ_private[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section))
|
||||
procedure.active_revision.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
end
|
||||
|
||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
context 'with explication/header_sections' do
|
||||
let(:types_de_champ_public) { Array.new(4) { { type: :text } } }
|
||||
let(:types_de_champ_private) { Array.new(4) { { type: :text } } }
|
||||
before do
|
||||
procedure.active_revision.types_de_champ_public[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section))
|
||||
procedure.active_revision.types_de_champ_public[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
procedure.active_revision.types_de_champ_private[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section))
|
||||
procedure.active_revision.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
end
|
||||
it { expect(subject.fields).to eq(expected) }
|
||||
end
|
||||
|
||||
context 'with rna' do
|
||||
let(:types_de_champ_public) { [{ type: :rna, libelle: 'rna' }] }
|
||||
let(:types_de_champ_private) { [] }
|
||||
xit { expect(subject.fields.map(&:label)).to include('rna – commune') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the procedure is for individuals' do
|
||||
let(:name_field) { Facet.new(label: "Prénom", table: "individual", column: "prenom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:surname_field) { Facet.new(label: "Nom", table: "individual", column: "nom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:gender_field) { Facet.new(label: "Civilité", table: "individual", column: "gender", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
subject { procedure_presentation.fields }
|
||||
|
||||
it { is_expected.to include(name_field, surname_field, gender_field) }
|
||||
end
|
||||
|
||||
context 'when the procedure is sva' do
|
||||
let(:procedure) { create(:procedure, :for_individual, :sva) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
let(:decision_on) { Facet.new(label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Facet.new(label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
|
||||
subject { procedure_presentation.fields }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
|
||||
context 'when the procedure is svr' do
|
||||
let(:procedure) { create(:procedure, :for_individual, :svr) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
let(:decision_on) { Facet.new(label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Facet.new(label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
|
||||
subject { procedure_presentation.fields }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#displayable_fields_for_select" do
|
||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||
let(:excluded_displayable_field) { Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true) }
|
||||
let(:included_displayable_field) { Facet.new(label: "label1", table: "table1", column: "column1", virtual: false) }
|
||||
|
||||
let(:default_user_email) { Facet.new(label: 'email', table: 'user', column: 'email') }
|
||||
let(:excluded_displayable_field) { Facet.new(label: "label1", table: "table1", column: "column1", virtual: true) }
|
||||
|
||||
before do
|
||||
allow(subject).to receive(:fields).and_return([
|
||||
excluded_displayable_field,
|
||||
included_displayable_field
|
||||
allow(Facet).to receive(:facets).and_return([
|
||||
default_user_email,
|
||||
excluded_displayable_field
|
||||
])
|
||||
end
|
||||
|
||||
it { expect(subject.displayable_fields_for_select).to eq([[["label1", "table1/column1"]], ["user/email"]]) }
|
||||
it { expect(subject.displayable_fields_for_select).to eq([[["email", "user/email"]], ["user/email"]]) }
|
||||
end
|
||||
describe "#filterable_fields_options" do
|
||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
@ -181,13 +72,13 @@ describe ProcedurePresentation do
|
|||
context 'filders' do
|
||||
let(:included_displayable_field) do
|
||||
[
|
||||
Facet.new(label: "label1", table: "table1", column: "column1", virtual: false),
|
||||
Facet.new(label: 'email', table: 'user', column: 'email'),
|
||||
Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true)
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
allow(subject).to receive(:fields).and_return(included_displayable_field)
|
||||
allow(Facet).to receive(:facets).and_return(included_displayable_field)
|
||||
end
|
||||
|
||||
it { expect(subject.filterable_fields_options).to eq([["label1", "table1/column1"], ["depose_since", "self/depose_since"]]) }
|
||||
|
@ -196,9 +87,8 @@ describe ProcedurePresentation do
|
|||
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :rna, libelle: 'rna', stable_id: 1 }]) }
|
||||
it { expect(subject.filterable_fields_options.map { _1[0] }).to include('rna – commune') }
|
||||
it { expect(subject.filterable_fields_options.map { _1[1] }).to include('type_de_champ/1->data.commune') }
|
||||
it { expect(subject.filterable_fields_options).to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) }
|
||||
end
|
||||
|
||||
it { expect(subject.filterable_fields_options).to eq([["label1", "table1/column1"], ["depose_since", "self/depose_since"]]) }
|
||||
end
|
||||
|
||||
describe '#sorted_ids' do
|
||||
|
@ -336,7 +226,7 @@ describe ProcedurePresentation do
|
|||
|
||||
context 'for type_de_champ_private table' do
|
||||
context 'with no revisions' do
|
||||
let(:table) { 'type_de_champ_private' }
|
||||
let(:table) { 'type_de_champ' }
|
||||
let(:column) { procedure.active_revision.types_de_champ_private.first.stable_id.to_s }
|
||||
|
||||
let(:biere_dossier) { create(:dossier, procedure: procedure) }
|
||||
|
@ -362,7 +252,7 @@ describe ProcedurePresentation do
|
|||
|
||||
context 'with a revision adding a new type_de_champ' do
|
||||
let!(:tdc) { { type_champ: :text, private: true, libelle: 'nouveau champ' } }
|
||||
let(:table) { 'type_de_champ_private' }
|
||||
let(:table) { 'type_de_champ' }
|
||||
let(:column) { procedure.active_revision.types_de_champ_private.last.stable_id.to_s }
|
||||
|
||||
let(:nothing_dossier) { create(:dossier, procedure: procedure) }
|
||||
|
@ -675,7 +565,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
context 'for type_de_champ_private table' do
|
||||
let(:filter) { [{ 'table' => 'type_de_champ_private', 'column' => type_de_champ_private.stable_id.to_s, 'value' => 'keep' }] }
|
||||
let(:filter) { [{ 'table' => 'type_de_champ', 'column' => type_de_champ_private.stable_id.to_s, 'value' => 'keep' }] }
|
||||
|
||||
let(:kept_dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:discarded_dossier) { create(:dossier, procedure: procedure) }
|
||||
|
@ -691,8 +581,8 @@ describe ProcedurePresentation do
|
|||
context 'with multiple search values' do
|
||||
let(:filter) do
|
||||
[
|
||||
{ 'table' => 'type_de_champ_private', 'column' => type_de_champ_private.stable_id.to_s, 'value' => 'keep' },
|
||||
{ 'table' => 'type_de_champ_private', 'column' => type_de_champ_private.stable_id.to_s, 'value' => 'and' }
|
||||
{ 'table' => 'type_de_champ', 'column' => type_de_champ_private.stable_id.to_s, 'value' => 'keep' },
|
||||
{ 'table' => 'type_de_champ', 'column' => type_de_champ_private.stable_id.to_s, 'value' => 'and' }
|
||||
]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue