add exportables_pieces_jointes_for_all_versions and outdated to pj_list_concern

This commit is contained in:
simon lehericey 2024-07-26 10:06:38 +02:00
parent 106698a242
commit 24109a0128
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 79 additions and 39 deletions

View file

@ -11,14 +11,26 @@ module PiecesJointesListConcern
pieces_jointes(exclude_titre_identite: true)
end
def exportables_pieces_jointes_for_all_versions
pieces_jointes(
exclude_titre_identite: true,
revision: revisions
).sort_by { - _1.id }.uniq(&:stable_id)
end
def outdated_exportables_pieces_jointes
exportables_pieces_jointes_for_all_versions - exportables_pieces_jointes
end
private
def pieces_jointes(
exclude_titre_identite: false,
public_only: false,
wrap_with_parent: false
wrap_with_parent: false,
revision: active_revision
)
coordinates = active_revision.revision_types_de_champ
coordinates = ProcedureRevisionTypeDeChamp.where(revision:)
.includes(:type_de_champ, revision_types_de_champ: :type_de_champ)
coordinates = coordinates.public_only if public_only

View file

@ -1,6 +1,8 @@
describe PiecesJointesListConcern do
describe '#pieces_jointes_list' do
include Logic
describe 'public_wrapped_partionned_pjs and exportables_pieces_jointes' do
let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
let(:types_de_champ_public) do
[
@ -46,5 +48,31 @@ describe PiecesJointesListConcern do
it "returns the list of pieces jointes with private, without parent repetition, without titre identite" do
expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array([pj1, pj2, pjcond, pj5, pjcond2, pj6].map(&:libelle))
end
it "returns the same list but for all versions" do
expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array([pj1, pj2, pjcond, pj5, pjcond2, pj6].map(&:libelle))
end
end
end
describe '#outdated_exportables_pieces_jointes' do
let(:types_de_champ_public) do
[
{ type: :piece_justificative, libelle: "outdated", stable_id: 1 },
{ type: :piece_justificative, libelle: "kept", stable_id: 2 }
]
end
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
before do
procedure.draft_revision.remove_type_de_champ(1)
procedure.draft_revision.add_type_de_champ(type_champ: :piece_justificative, libelle: 'new', mandatory: false)
procedure.publish_revision!
end
it { expect(procedure.exportables_pieces_jointes_for_all_versions.map(&:libelle)).to eq(["new", "kept", "outdated"]) }
it { expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array(["kept", "new"]) }
it { expect(procedure.outdated_exportables_pieces_jointes.map(&:libelle)).to match_array(["outdated"]) }
end
end