fix(revision): fix tests to use new revison system
This commit is contained in:
parent
a36672239d
commit
02675a104d
12 changed files with 45 additions and 82 deletions
|
@ -48,7 +48,6 @@ describe API::V1::ProceduresController, type: :controller do
|
|||
it { expect(subject[:id]).to eq(champ.id) }
|
||||
it { expect(subject[:libelle]).to eq(champ.libelle) }
|
||||
it { expect(subject[:type_champ]).to eq(champ.type_champ) }
|
||||
it { expect(subject[:order_place]).to eq(champ.order_place) }
|
||||
it { expect(subject[:description]).to eq(champ.description) }
|
||||
end
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ describe API::V2::GraphqlController do
|
|||
type: tdc.type_champ,
|
||||
description: tdc.description,
|
||||
required: tdc.mandatory?,
|
||||
champDescriptors: tdc.repetition? ? tdc.reload.types_de_champ.map { |tdc| { id: tdc.to_typed_id, type: tdc.type_champ } } : nil,
|
||||
champDescriptors: tdc.repetition? ? procedure.active_revision.children_of(tdc.reload).map { |tdc| { id: tdc.to_typed_id, type: tdc.type_champ } } : nil,
|
||||
options: tdc.drop_down_list? ? tdc.drop_down_list_options.reject(&:empty?) : nil
|
||||
}
|
||||
end,
|
||||
|
|
|
@ -222,31 +222,19 @@ FactoryBot.define do
|
|||
type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
|
||||
if !type_de_champ_text
|
||||
type_de_champ_text = build(:type_de_champ_text,
|
||||
procedure: champ_repetition.type_de_champ.procedure,
|
||||
position: 0,
|
||||
parent: champ_repetition.type_de_champ,
|
||||
libelle: 'Nom')
|
||||
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ_text,
|
||||
parent: parent,
|
||||
position: 0)
|
||||
|
||||
champ_repetition.type_de_champ.types_de_champ << type_de_champ_text
|
||||
libelle: 'Nom')
|
||||
end
|
||||
|
||||
type_de_champ_number = types_de_champ.find { |tdc| tdc.libelle == 'Age' }
|
||||
if !type_de_champ_number
|
||||
type_de_champ_number = build(:type_de_champ_number,
|
||||
procedure: champ_repetition.type_de_champ.procedure,
|
||||
position: 1,
|
||||
parent: champ_repetition.type_de_champ,
|
||||
libelle: 'Age')
|
||||
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ_number,
|
||||
parent: parent,
|
||||
position: 1)
|
||||
|
||||
champ_repetition.type_de_champ.types_de_champ << type_de_champ_number
|
||||
libelle: 'Age')
|
||||
end
|
||||
|
||||
evaluator.rows.times do |row|
|
||||
|
|
|
@ -3,7 +3,6 @@ FactoryBot.define do
|
|||
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
||||
sequence(:description) { |n| "description du champ #{n}" }
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:text) }
|
||||
order_place { 1 }
|
||||
mandatory { false }
|
||||
add_attribute(:private) { false }
|
||||
|
||||
|
@ -14,22 +13,16 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
after(:build) do |type_de_champ, evaluator|
|
||||
if evaluator.procedure
|
||||
revision = evaluator.procedure.active_revision
|
||||
revision = evaluator.procedure&.active_revision || build(:procedure_revision)
|
||||
evaluator.procedure&.save
|
||||
|
||||
evaluator.procedure.save
|
||||
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
|
||||
position: evaluator.position || 0,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ,
|
||||
parent: evaluator.parent)
|
||||
|
||||
create(:procedure_revision_type_de_champ,
|
||||
position: evaluator.position || 0,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ)
|
||||
|
||||
elsif evaluator.parent
|
||||
type_de_champ.order_place = evaluator.position || evaluator.parent.types_de_champ.size
|
||||
evaluator.parent.types_de_champ << type_de_champ
|
||||
else
|
||||
type_de_champ.order_place = evaluator.position
|
||||
end
|
||||
revision.save
|
||||
end
|
||||
|
||||
trait :private do
|
||||
|
@ -177,36 +170,28 @@ FactoryBot.define do
|
|||
|
||||
after(:build) do |type_de_champ_repetition, evaluator|
|
||||
evaluator.procedure&.save!
|
||||
evaluator.types_de_champ.each do |type_de_champ|
|
||||
revision = evaluator.procedure&.active_revision || build(:procedure_revision)
|
||||
parent = revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ == type_de_champ_repetition }
|
||||
types_de_champ = revision.revision_types_de_champ.filter { |rtdc| rtdc.parent == parent }
|
||||
position = types_de_champ.size
|
||||
revision = evaluator.procedure&.active_revision || build(:procedure_revision)
|
||||
parent = revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ == type_de_champ_repetition }
|
||||
types_de_champ = revision.revision_types_de_champ.filter { |rtdc| rtdc.parent == parent }
|
||||
position = types_de_champ.size
|
||||
|
||||
evaluator.types_de_champ.each.with_index(position) do |type_de_champ, position|
|
||||
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ,
|
||||
parent: parent,
|
||||
position: position)
|
||||
|
||||
# old system
|
||||
type_de_champ.order_place = position
|
||||
type_de_champ_repetition.types_de_champ << type_de_champ
|
||||
end
|
||||
|
||||
revision.save
|
||||
end
|
||||
|
||||
trait :with_types_de_champ do
|
||||
after(:build) do |type_de_champ_repetition, evaluator|
|
||||
type_de_champ = build(:type_de_champ, libelle: 'sub type de champ', parent: type_de_champ_repetition)
|
||||
revision = evaluator.procedure.active_revision
|
||||
parent = revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ == type_de_champ_repetition }
|
||||
|
||||
evaluator.procedure.save!
|
||||
revision.revision_types_de_champ << build(:procedure_revision_type_de_champ,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ,
|
||||
parent: parent,
|
||||
position: 0)
|
||||
build(:type_de_champ, procedure: evaluator.procedure, libelle: 'sub type de champ', parent: parent, position: 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -174,14 +174,12 @@ describe ProcedureRevision do
|
|||
it 'reorders' do
|
||||
children = draft.children_of(type_de_champ_repetition)
|
||||
expect(children.pluck(:position)).to eq([0, 1, 2])
|
||||
expect(children.pluck(:order_place)).to eq([0, 1, 2])
|
||||
|
||||
draft.remove_type_de_champ(children[1].stable_id)
|
||||
|
||||
children.reload
|
||||
|
||||
expect(children.pluck(:position)).to eq([0, 1])
|
||||
expect(children.pluck(:order_place)).to eq([0, 1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -193,7 +191,6 @@ describe ProcedureRevision do
|
|||
it 'can remove its children' do
|
||||
draft.remove_type_de_champ(child.stable_id)
|
||||
|
||||
expect(type_de_champ_repetition.types_de_champ).to be_empty
|
||||
expect { child.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
expect(draft.types_de_champ_public.size).to eq(1)
|
||||
end
|
||||
|
@ -444,7 +441,7 @@ describe ProcedureRevision do
|
|||
private: false,
|
||||
from: "text",
|
||||
to: "drop_down_list",
|
||||
stable_id: new_draft.types_de_champ_public.last.types_de_champ.first.stable_id
|
||||
stable_id: new_draft.children_of(new_draft.types_de_champ_public.last).first.stable_id
|
||||
},
|
||||
{
|
||||
model: :type_de_champ,
|
||||
|
@ -454,7 +451,7 @@ describe ProcedureRevision do
|
|||
private: false,
|
||||
from: [],
|
||||
to: ["one", "two"],
|
||||
stable_id: new_draft.types_de_champ_public.last.types_de_champ.first.stable_id
|
||||
stable_id: new_draft.children_of(new_draft.types_de_champ_public.last).first.stable_id
|
||||
}
|
||||
])
|
||||
end
|
||||
|
@ -464,7 +461,7 @@ describe ProcedureRevision do
|
|||
let(:procedure) { create(:procedure, :with_repetition) }
|
||||
|
||||
before do
|
||||
child = new_draft.types_de_champ_public.last.types_de_champ.first
|
||||
child = new_draft.children_of(new_draft.types_de_champ_public.last).first
|
||||
new_draft.find_and_ensure_exclusive_use(child.stable_id).update(type_champ: :carte, options: { cadastres: true, znieff: true })
|
||||
end
|
||||
|
||||
|
@ -478,7 +475,7 @@ describe ProcedureRevision do
|
|||
private: false,
|
||||
from: "text",
|
||||
to: "carte",
|
||||
stable_id: new_draft.types_de_champ_public.last.types_de_champ.first.stable_id
|
||||
stable_id: new_draft.children_of(new_draft.types_de_champ_public.last).first.stable_id
|
||||
},
|
||||
{
|
||||
model: :type_de_champ,
|
||||
|
@ -488,7 +485,7 @@ describe ProcedureRevision do
|
|||
private: false,
|
||||
from: [],
|
||||
to: [:cadastres, :znieff],
|
||||
stable_id: new_draft.types_de_champ_public.last.types_de_champ.first.stable_id
|
||||
stable_id: new_draft.children_of(new_draft.types_de_champ_public.last).first.stable_id
|
||||
}
|
||||
])
|
||||
end
|
||||
|
@ -578,13 +575,13 @@ describe ProcedureRevision do
|
|||
end
|
||||
|
||||
context 'when there are repetitions' do
|
||||
let(:types_de_champ) do
|
||||
[
|
||||
build(:type_de_champ_repetition, position: 1, mandatory: true, types_de_champ: [
|
||||
build(:type_de_champ_text, position: 1, mandatory: true),
|
||||
build(:type_de_champ_piece_justificative, position: 2, mandatory: true)
|
||||
])
|
||||
]
|
||||
let(:procedure) do
|
||||
procedure = create(:procedure, types_de_champ: [])
|
||||
create(:type_de_champ_repetition, position: 1, mandatory: true, procedure: procedure, types_de_champ: [
|
||||
build(:type_de_champ_text, position: 1, mandatory: true),
|
||||
build(:type_de_champ_piece_justificative, position: 2, mandatory: true)
|
||||
])
|
||||
procedure
|
||||
end
|
||||
|
||||
it 'estimates that between 2 and 3 rows will be filled for each repetition' do
|
||||
|
|
|
@ -486,22 +486,24 @@ describe Procedure do
|
|||
expect(subject.draft_types_de_champ_private.size).to eq(procedure.draft_types_de_champ_private.size)
|
||||
|
||||
procedure.draft_types_de_champ.zip(subject.draft_types_de_champ).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
|
||||
expect(stc).to have_same_attributes_as(ptc)
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition).zip(TypeDeChamp.where(parent: subject.draft_types_de_champ.repetition)).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id", "migrated_parent"])
|
||||
public_repetition = procedure.draft_types_de_champ.repetition.first
|
||||
procedure.draft_revision.children_of(public_repetition).zip(subject.draft_revision.children_of(public_repetition)).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc)
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
procedure.draft_types_de_champ_private.zip(subject.draft_types_de_champ_private).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
|
||||
expect(stc).to have_same_attributes_as(ptc)
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
TypeDeChamp.where(parent: procedure.draft_types_de_champ_private.repetition).zip(TypeDeChamp.where(parent: subject.draft_types_de_champ_private.repetition)).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id", "migrated_parent"])
|
||||
private_repetition = procedure.draft_types_de_champ_private.repetition.first
|
||||
procedure.draft_revision.children_of(private_repetition).zip(subject.draft_revision.children_of(private_repetition)).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc)
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
|
|
|
@ -27,12 +27,6 @@ shared_examples 'type_de_champ_spec' do
|
|||
end
|
||||
end
|
||||
|
||||
context 'order_place' do
|
||||
# it { is_expected.not_to allow_value(nil).for(:order_place) }
|
||||
# it { is_expected.not_to allow_value('').for(:order_place) }
|
||||
it { is_expected.to allow_value(1).for(:order_place) }
|
||||
end
|
||||
|
||||
context 'description' do
|
||||
it { is_expected.to allow_value(nil).for(:description) }
|
||||
it { is_expected.to allow_value('').for(:description) }
|
||||
|
|
|
@ -65,7 +65,6 @@ describe ChampSerializer do
|
|||
}
|
||||
let(:serialized_id) { champ.type_de_champ.stable_id }
|
||||
let(:serialized_description) { champ.description }
|
||||
let(:serialized_order_place) { champ.order_place }
|
||||
let(:serialized_libelle) { champ.libelle }
|
||||
let(:serialized_type_champ) { champ.type_champ }
|
||||
let(:serialized_value) { nil }
|
||||
|
|
|
@ -73,7 +73,7 @@ describe DossierSerializer do
|
|||
"libelle" => cloned_type_de_champ.libelle,
|
||||
"description" => 'Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.',
|
||||
"lien_demarche" => 'https://www.dance-academy.gouv.fr',
|
||||
"order_place" => cloned_type_de_champ.order_place
|
||||
"order_place" => 0
|
||||
}
|
||||
],
|
||||
pieces_justificatives: [
|
||||
|
|
|
@ -30,7 +30,7 @@ describe ProcedureSerializer do
|
|||
"libelle" => cloned_type_de_champ.libelle,
|
||||
"description" => 'Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.',
|
||||
"lien_demarche" => 'https://www.dance-academy.gouv.fr',
|
||||
"order_place" => cloned_type_de_champ.order_place
|
||||
"order_place" => 0
|
||||
}
|
||||
]
|
||||
)
|
||||
|
|
|
@ -353,8 +353,7 @@ describe ProcedureExportService do
|
|||
let(:other_parent) { create(:type_de_champ_repetition, stable_id: champ_repetition.stable_id) }
|
||||
|
||||
before do
|
||||
create(:procedure_revision_type_de_champ, type_de_champ: other_parent, revision: create(:procedure).active_revision, position: 0)
|
||||
create(:type_de_champ, parent: other_parent)
|
||||
create(:type_de_champ, parent: create(:procedure_revision_type_de_champ, type_de_champ: other_parent, revision: create(:procedure).active_revision, position: 0))
|
||||
end
|
||||
|
||||
it 'should have headers' do
|
||||
|
|
|
@ -203,7 +203,7 @@ describe 'The user' do
|
|||
|
||||
let(:old_procedure_with_disabled_pj_validation) do
|
||||
tdcs = [
|
||||
create(:type_de_champ_piece_justificative, mandatory: true, libelle: 'Pièce justificative 1', order_place: 1, skip_pj_validation: true)
|
||||
create(:type_de_champ_piece_justificative, mandatory: true, libelle: 'Pièce justificative 1', position: 1, skip_pj_validation: true)
|
||||
]
|
||||
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue