fix test
This commit is contained in:
parent
7f23449f24
commit
5767c9b97e
3 changed files with 61 additions and 33 deletions
|
@ -28,7 +28,10 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe 'with_champs' do
|
||||
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ, libelle: 'l1', position: 1), build(:type_de_champ, libelle: 'l3', position: 3), build(:type_de_champ, libelle: 'l2', position: 2)]) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:tdc_1) { create(:type_de_champ, libelle: 'l1', position: 1, procedure: procedure) }
|
||||
let!(:tdc_3) { create(:type_de_champ, libelle: 'l3', position: 3, procedure: procedure) }
|
||||
let!(:tdc_2) { create(:type_de_champ, libelle: 'l2', position: 2, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it do
|
||||
|
@ -392,14 +395,20 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe '#champs' do
|
||||
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ, :private, libelle: 'l1', position: 1), build(:type_de_champ, :private, libelle: 'l3', position: 3), build(:type_de_champ, :private, libelle: 'l2', position: 2)]) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:tdc_1) { create(:type_de_champ, libelle: 'l1', position: 1, procedure: procedure) }
|
||||
let!(:tdc_3) { create(:type_de_champ, libelle: 'l3', position: 3, procedure: procedure) }
|
||||
let!(:tdc_2) { create(:type_de_champ, libelle: 'l2', position: 2, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it { expect(dossier.champs.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
|
||||
end
|
||||
|
||||
describe '#champs_private' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_private: [build(:type_de_champ, :private, libelle: 'l1', position: 1), build(:type_de_champ, :private, libelle: 'l3', position: 3), build(:type_de_champ, :private, libelle: 'l2', position: 2)]) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:tdc_1) { create(:type_de_champ, :private, libelle: 'l1', position: 1, procedure: procedure) }
|
||||
let!(:tdc_3) { create(:type_de_champ, :private, libelle: 'l3', position: 3, procedure: procedure) }
|
||||
let!(:tdc_2) { create(:type_de_champ, :private, libelle: 'l2', position: 2, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it { expect(dossier.champs_private.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
|
||||
|
|
|
@ -9,40 +9,54 @@ describe ProcedureRevision do
|
|||
end
|
||||
|
||||
describe '#add_type_de_champ' do
|
||||
# tdc: public: text, repetition ; private: text ; +1 text child of repetition
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) }
|
||||
let(:text_params) { { type_champ: :text, libelle: 'text' } }
|
||||
let(:tdc_params) { text_params }
|
||||
let(:last_coordinate) { draft.revision_types_de_champ.last }
|
||||
|
||||
it 'type_de_champ' do
|
||||
expect(draft.types_de_champ_public.size).to eq(2)
|
||||
new_type_de_champ = draft.add_type_de_champ({
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||
libelle: "Un champ text"
|
||||
})
|
||||
draft.reload
|
||||
expect(draft.types_de_champ_public.size).to eq(3)
|
||||
expect(draft.types_de_champ_public.last).to eq(new_type_de_champ)
|
||||
expect(draft.revision_types_de_champ_public.last.position).to eq(2)
|
||||
expect(draft.revision_types_de_champ_public.last.type_de_champ).to eq(new_type_de_champ)
|
||||
subject { draft.add_type_de_champ(tdc_params) }
|
||||
|
||||
context 'with a text tdc' do
|
||||
it 'public' do
|
||||
expect { subject }.to change { draft.types_de_champ_public.size }.from(2).to(3)
|
||||
expect(draft.types_de_champ_public.last).to eq(subject)
|
||||
|
||||
expect(last_coordinate.position).to eq(2)
|
||||
expect(last_coordinate.type_de_champ).to eq(subject)
|
||||
end
|
||||
end
|
||||
|
||||
it 'type_de_champ_private' do
|
||||
expect(draft.types_de_champ_private.size).to eq(1)
|
||||
draft.add_type_de_champ({
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||
libelle: "Un champ text",
|
||||
private: true
|
||||
})
|
||||
draft.reload
|
||||
expect(draft.types_de_champ_private.size).to eq(2)
|
||||
context 'with a private tdc' do
|
||||
let(:tdc_params) { text_params.merge(private: true) }
|
||||
|
||||
it { expect { subject }.to change { draft.types_de_champ_private.count }.from(1).to(2) }
|
||||
end
|
||||
|
||||
it 'type_de_champ_repetition' do
|
||||
expect(type_de_champ_repetition.types_de_champ.size).to eq(1)
|
||||
draft.add_type_de_champ({
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||
libelle: "Un champ text",
|
||||
parent_id: type_de_champ_repetition.stable_id
|
||||
})
|
||||
expect(type_de_champ_repetition.types_de_champ.size).to eq(2)
|
||||
context 'with a repetition child' do
|
||||
let(:tdc_params) { text_params.merge(parent_id: type_de_champ_repetition.stable_id) }
|
||||
|
||||
it do
|
||||
expect { subject }.to change { draft.reload.types_de_champ.count }.from(4).to(5)
|
||||
expect(draft.children_of(type_de_champ_repetition).last).to eq(subject)
|
||||
|
||||
expect(last_coordinate.position).to eq(1)
|
||||
|
||||
parent_coordinate = draft.revision_types_de_champ.find_by(type_de_champ: type_de_champ_repetition)
|
||||
expect(last_coordinate.parent).to eq(parent_coordinate)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a libelle is missing' do
|
||||
let(:tdc_params) { text_params.except(:libelle) }
|
||||
|
||||
it { expect(subject.errors.full_messages).to eq(["Libelle doit être rempli"]) }
|
||||
end
|
||||
|
||||
context 'when a parent is incorrect' do
|
||||
let(:tdc_params) { text_params.merge(parent_id: 123456789) }
|
||||
|
||||
it { expect(subject.errors.full_messages).not_to be_empty }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -246,12 +246,17 @@ describe 'fetch API Particulier Data', js: true do
|
|||
let(:api_particulier_token) { '29eb50b65f64e8e00c0847a8bbcbd150e1f847' }
|
||||
|
||||
let(:procedure) do
|
||||
create(:procedure, :for_individual, :with_service, :with_cnaf, :with_dgfip, :with_pole_emploi, :with_mesri, :published,
|
||||
create(:procedure, :for_individual, :with_service, :published,
|
||||
libelle: 'libellé de la procédure',
|
||||
path: 'libelle-de-la-procedure',
|
||||
instructeurs: [instructeur],
|
||||
api_particulier_sources: expected_sources,
|
||||
api_particulier_token: api_particulier_token)
|
||||
api_particulier_token: api_particulier_token).tap do |p|
|
||||
p.active_revision.add_type_de_champ(type_champ: :cnaf, libelle: 'cnaf')
|
||||
p.active_revision.add_type_de_champ(type_champ: :dgfip, libelle: 'dgfip')
|
||||
p.active_revision.add_type_de_champ(type_champ: :pole_emploi, libelle: 'pole_emploi')
|
||||
p.active_revision.add_type_de_champ(type_champ: :mesri, libelle: 'mesri')
|
||||
end
|
||||
end
|
||||
|
||||
before { login_as user, scope: :user }
|
||||
|
|
Loading…
Reference in a new issue