2021-12-15 19:36:02 +01:00
|
|
|
describe UpdateZoneToProceduresService do
|
2021-12-21 10:49:36 +01:00
|
|
|
before(:each) do
|
2022-09-22 18:16:19 +02:00
|
|
|
Flipper.enable :zonage
|
|
|
|
Rake::Task['after_party:populate_zones'].invoke
|
2021-12-15 19:36:02 +01:00
|
|
|
end
|
|
|
|
|
2021-12-21 10:49:36 +01:00
|
|
|
after(:each) do
|
2022-09-22 18:16:19 +02:00
|
|
|
Rake::Task['after_party:populate_zones'].reenable
|
2021-12-15 19:36:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#call' do
|
|
|
|
let(:procedure1) { create(:procedure, zone: nil) }
|
|
|
|
let(:procedure2) { create(:procedure, zone: nil) }
|
|
|
|
|
|
|
|
subject { described_class.call(lines) }
|
|
|
|
|
|
|
|
context 'nominal case' do
|
|
|
|
let(:lines) do
|
|
|
|
[
|
|
|
|
{ "id" => procedure1.id, "POL_PUB_MINISTERE RATTACHEMENT" => "PM" },
|
|
|
|
{ "id" => procedure2.id, "POL_PUB_MINISTERE RATTACHEMENT" => "MI" }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates zone to procedures' do
|
|
|
|
errors = subject
|
|
|
|
|
|
|
|
expect(errors).to eq []
|
|
|
|
expect(procedure1.reload.zone.acronym).to eq("PM")
|
|
|
|
expect(procedure2.reload.zone.acronym).to eq("MI")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unknown procedure' do
|
|
|
|
let(:lines) do
|
|
|
|
[
|
|
|
|
{ "id" => procedure1.id + procedure2.id, "POL_PUB_MINISTERE RATTACHEMENT" => "PM" }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
it 'returns errors' do
|
|
|
|
errors = subject
|
|
|
|
expect(errors).to eq ["Procedure #{procedure1.id + procedure2.id} introuvable"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unknown zone' do
|
|
|
|
let(:lines) do
|
|
|
|
[
|
|
|
|
{ "id" => procedure1.id, "POL_PUB_MINISTERE RATTACHEMENT" => "YOUPI" }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
it 'returns errors' do
|
|
|
|
errors = subject
|
|
|
|
expect(errors).to eq ["Zone YOUPI introuvable"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|