2022-12-19 12:32:09 +01:00
|
|
|
describe PrefillDescriptionsController, type: :controller do
|
|
|
|
describe '#edit' do
|
|
|
|
subject(:edit_request) do
|
|
|
|
get :edit, params: { path: procedure.path }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure is found' do
|
|
|
|
context 'when the procedure is publiee' do
|
|
|
|
context 'when the procedure is opendata' do
|
|
|
|
let(:procedure) { create(:procedure, :published, opendata: true) }
|
|
|
|
|
|
|
|
it { expect(edit_request).to render_template(:edit) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure is not opendata' do
|
|
|
|
let(:procedure) { create(:procedure, :published, opendata: false) }
|
|
|
|
|
|
|
|
it { expect { edit_request }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure is brouillon' do
|
|
|
|
context 'when the procedure is opendata' do
|
|
|
|
let(:procedure) { create(:procedure, :draft, opendata: true) }
|
|
|
|
|
|
|
|
it { expect(edit_request).to render_template(:edit) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure is not opendata' do
|
|
|
|
let(:procedure) { create(:procedure, :draft, opendata: false) }
|
|
|
|
|
|
|
|
it { expect { edit_request }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure is not publiee and not brouillon' do
|
|
|
|
let(:procedure) { create(:procedure, :closed) }
|
|
|
|
|
|
|
|
it { expect { edit_request }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the procedure is not found' do
|
|
|
|
let(:procedure) { double(Procedure, path: "wrong path") }
|
|
|
|
|
|
|
|
it { expect { edit_request }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:procedure) { create(:procedure, :published, opendata: true) }
|
|
|
|
let(:type_de_champ) { create(:type_de_champ_text, procedure: procedure) }
|
|
|
|
let(:type_de_champ2) { create(:type_de_champ_text, procedure: procedure) }
|
|
|
|
|
|
|
|
subject(:update_request) do
|
2023-02-13 09:17:22 +01:00
|
|
|
patch :update, params: { path: procedure.path, type_de_champ: params }, format: :turbo_stream
|
2022-12-19 12:32:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
before { update_request }
|
|
|
|
|
|
|
|
context 'when adding a type_de_champ_id' do
|
|
|
|
let(:type_de_champ_to_add) { create(:type_de_champ_text, procedure: procedure) }
|
2023-02-13 09:17:22 +01:00
|
|
|
let(:params) { { selected_type_de_champ_ids: [type_de_champ.id, type_de_champ_to_add.id].join(' ') } }
|
2022-12-19 12:32:09 +01:00
|
|
|
|
|
|
|
it { expect(response).to render_template(:update) }
|
|
|
|
|
|
|
|
it "includes the prefill URL" do
|
|
|
|
expect(response.body).to include(commencer_path(path: procedure.path))
|
2022-12-20 11:04:42 +01:00
|
|
|
expect(response.body).to include(
|
|
|
|
{
|
|
|
|
"champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
|
|
|
|
}.to_query
|
|
|
|
)
|
|
|
|
expect(response.body).to include({
|
|
|
|
"champ_#{type_de_champ_to_add.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
|
|
|
|
}.to_query)
|
2022-12-19 12:32:09 +01:00
|
|
|
end
|
2023-01-04 08:31:31 +01:00
|
|
|
|
|
|
|
it "includes the prefill query" do
|
|
|
|
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
|
|
|
|
type_de_champ_to_add_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
|
|
|
|
|
|
|
|
expect(response.body).to include(api_public_v1_dossiers_path(procedure))
|
|
|
|
expect(response.body).to include(
|
|
|
|
""champ_#{type_de_champ.to_typed_id}": "#{type_de_champ_value}", "champ_#{type_de_champ_to_add.to_typed_id}": "#{type_de_champ_to_add_value}""
|
|
|
|
)
|
|
|
|
end
|
2022-12-19 12:32:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing a type_de_champ_id' do
|
|
|
|
let(:type_de_champ_to_remove) { type_de_champ2 }
|
2023-02-13 09:17:22 +01:00
|
|
|
let(:params) { { selected_type_de_champ_ids: type_de_champ } }
|
2022-12-19 12:32:09 +01:00
|
|
|
|
|
|
|
it { expect(response).to render_template(:update) }
|
|
|
|
|
|
|
|
it "includes the prefill URL" do
|
|
|
|
expect(response.body).to include(commencer_path(path: procedure.path))
|
2022-12-20 11:04:42 +01:00
|
|
|
expect(response.body).to include({
|
|
|
|
"champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
|
|
|
|
}.to_query)
|
|
|
|
expect(response.body).not_to include({
|
|
|
|
"champ_#{type_de_champ_to_remove.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
|
|
|
|
}.to_query)
|
2022-12-19 12:32:09 +01:00
|
|
|
end
|
2023-01-04 08:31:31 +01:00
|
|
|
|
|
|
|
it "includes the prefill query" do
|
|
|
|
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
|
|
|
|
type_de_champ_to_remove_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
|
|
|
|
|
|
|
|
expect(response.body).to include(api_public_v1_dossiers_path(procedure))
|
|
|
|
expect(response.body).to include(
|
|
|
|
""champ_#{type_de_champ.to_typed_id}": "#{type_de_champ_value}""
|
|
|
|
)
|
|
|
|
expect(response.body).not_to include(
|
|
|
|
""champ_#{type_de_champ_to_remove.to_typed_id}": "#{type_de_champ_to_remove_value}""
|
|
|
|
)
|
|
|
|
end
|
2022-12-19 12:32:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when removing the last type de champ' do
|
|
|
|
let(:type_de_champ_to_remove) { type_de_champ }
|
2023-02-13 09:17:22 +01:00
|
|
|
let(:params) { { selected_type_de_champ_ids: '' } }
|
2022-12-19 12:32:09 +01:00
|
|
|
|
|
|
|
it { expect(response).to render_template(:update) }
|
|
|
|
|
|
|
|
it "does not include the prefill URL" do
|
|
|
|
expect(response.body).not_to include(commencer_path(path: procedure.path))
|
|
|
|
end
|
2023-01-04 08:31:31 +01:00
|
|
|
|
|
|
|
it "does not include the prefill query" do
|
|
|
|
expect(response.body).not_to include(api_public_v1_dossiers_path(procedure))
|
|
|
|
end
|
2022-12-19 12:32:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|