refactor(champs): update specs
This commit is contained in:
parent
474d206ee1
commit
56b0b156bf
19 changed files with 83 additions and 83 deletions
|
@ -40,20 +40,7 @@ describe Champs::PieceJustificativeController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the file is invalid' do
|
||||
let(:file) { fixture_file_upload('spec/fixtures/files/invalid_file_format.json', 'application/json') }
|
||||
|
||||
# TODO: for now there are no validators on the champ piece_justificative_file,
|
||||
# so we have to mock a failing validation.
|
||||
# Once the validators will be enabled, remove those mocks, and let the usual
|
||||
# validation fail naturally.
|
||||
#
|
||||
# See https://github.com/betagouv/demarches-simplifiees.fr/issues/4926
|
||||
before do
|
||||
champ
|
||||
expect_any_instance_of(Champs::PieceJustificativeChamp).to receive(:save).and_return(false)
|
||||
expect_any_instance_of(Champs::PieceJustificativeChamp).to receive(:errors)
|
||||
.and_return(double(full_messages: ['La pièce justificative n’est pas d’un type accepté']))
|
||||
end
|
||||
let(:file) { fixture_file_upload('spec/fixtures/files/invalid_file_format.json', 'bad/bad') }
|
||||
|
||||
it 'doesn’t attach the file' do
|
||||
subject
|
||||
|
@ -64,7 +51,7 @@ describe Champs::PieceJustificativeController, type: :controller do
|
|||
subject
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.header['Content-Type']).to include('application/json')
|
||||
expect(response.parsed_body).to eq({ 'errors' => ['La pièce justificative n’est pas d’un type accepté'] })
|
||||
expect(response.parsed_body).to eq({ 'errors' => ['Le champ « Piece justificative file » n’est pas d’un type accepté'] })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,18 @@
|
|||
describe Champs::RepetitionController, type: :controller do
|
||||
describe '#remove' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, mandatory: true, children: [{ libelle: 'Nom' }, { type: :integer_number, libelle: 'Age' }] }]) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, procedure:) }
|
||||
let(:repetition) { dossier.project_champs_public.find(&:repetition?) }
|
||||
let(:row) { dossier.champs.find(&:row?) }
|
||||
|
||||
before { sign_in dossier.user }
|
||||
it 'removes repetition' do
|
||||
rows, repetitions = dossier.champs.partition(&:child?)
|
||||
repetition = repetitions.first
|
||||
expect { delete :remove, params: { dossier_id: dossier, stable_id: repetition.stable_id, row_id: rows.first.row_id }, format: :turbo_stream }
|
||||
.to change { dossier.reload.champs.size }.from(3).to(1)
|
||||
|
||||
subject { delete :remove, params: { dossier_id: dossier, stable_id: repetition.stable_id, row_id: row.row_id }, format: :turbo_stream }
|
||||
|
||||
context 'removes repetition' do
|
||||
it { expect { subject }.not_to change { dossier.reload.champs.size } }
|
||||
it { expect { subject }.to change { dossier.reload; dossier.project_champs_public.find(&:repetition?).row_ids.size }.from(1).to(0) }
|
||||
it { expect { subject }.to change { row.reload.discarded_at }.from(nil).to(Time) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1002,10 +1002,11 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:another_instructeur) { create(:instructeur) }
|
||||
let(:now) { Time.zone.parse('01/01/2100') }
|
||||
|
||||
let(:champ_repetition) { dossier.project_champs_private.fourth }
|
||||
let(:champ_text) { champ_repetition.rows.first.first }
|
||||
let(:champ_multiple_drop_down_list) { dossier.project_champs_private.first }
|
||||
let(:champ_linked_drop_down_list) { dossier.project_champs_private.second }
|
||||
let(:champ_datetime) { dossier.project_champs_private.third }
|
||||
let(:champ_repetition) { dossier.project_champs_private.fourth }
|
||||
let(:champ_drop_down_list) { dossier.project_champs_private.fifth }
|
||||
|
||||
context 'when no invalid champs_public' do
|
||||
|
@ -1015,12 +1016,12 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
another_instructeur.follow(dossier)
|
||||
Timecop.freeze(now)
|
||||
patch :update_annotations, params: params, format: :turbo_stream
|
||||
|
||||
dossier.reload
|
||||
champ_multiple_drop_down_list.reload
|
||||
champ_linked_drop_down_list.reload
|
||||
champ_datetime.reload
|
||||
champ_repetition.reload
|
||||
champ_drop_down_list.reload
|
||||
champ_text.reload
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -1059,9 +1060,9 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
expect(champ_linked_drop_down_list.primary_value).to eq('primary')
|
||||
expect(champ_linked_drop_down_list.secondary_value).to eq('secondary')
|
||||
expect(champ_datetime.value).to eq(Time.zone.parse('2019-12-21T13:17:00').iso8601)
|
||||
expect(champ_repetition.rows.first.first.value).to eq('text')
|
||||
expect(champ_text.value).to eq('text')
|
||||
expect(champ_drop_down_list.value).to eq('other value')
|
||||
expect(dossier.reload.last_champ_private_updated_at).to eq(now)
|
||||
expect(dossier.last_champ_private_updated_at).to eq(now)
|
||||
expect(response).to have_http_status(200)
|
||||
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
describe Users::CommencerController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:published_procedure) { create(:procedure, :for_individual, :published) }
|
||||
let(:published_procedure) { create(:procedure, :for_individual, :published, types_de_champ_public:) }
|
||||
let(:types_de_champ_public) { [] }
|
||||
let(:draft_procedure) { create(:procedure, :with_path) }
|
||||
|
||||
describe '#commencer' do
|
||||
|
@ -160,7 +161,8 @@ describe Users::CommencerController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when a dossier is being prefilled by GET' do
|
||||
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: published_procedure) }
|
||||
let(:types_de_champ_public) { [{}] }
|
||||
let(:type_de_champ_text) { published_procedure.published_revision.types_de_champ.first }
|
||||
let(:path) { published_procedure.path }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
|
|
|
@ -594,11 +594,11 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:, user:) }
|
||||
let(:types_de_champ_public) { [{ type: :repetition, libelle: 'repetition', children: [{ type: :text, libelle: 'child' }] }] }
|
||||
let(:editing_fork) { dossier.owner_editing_fork }
|
||||
let(:champ_repetition) { editing_fork.champs.find(&:repetition?) }
|
||||
let(:champ_repetition) { editing_fork.project_champs_public.find(&:repetition?) }
|
||||
before do
|
||||
editing_fork
|
||||
|
||||
procedure.draft_revision.remove_type_de_champ(editing_fork.champs.find(&:repetition?).stable_id)
|
||||
procedure.draft_revision.remove_type_de_champ(champ_repetition.stable_id)
|
||||
procedure.publish_revision!
|
||||
|
||||
editing_fork.reload
|
||||
|
@ -611,7 +611,7 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
context 'when dossier was already submitted' do
|
||||
before do
|
||||
expect_any_instance_of(Dossier).to receive(:remove_piece_justificative_file_not_visible!)
|
||||
expect_any_instance_of(Dossier).to receive(:remove_not_visible_or_empty_champs!)
|
||||
post :submit_en_construction, params: payload
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue