2021-01-20 11:07:44 +01:00
|
|
|
|
describe InstructeursImportService do
|
|
|
|
|
describe '#import' do
|
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
|
|
|
|
|
let(:procedure_groupes) do
|
|
|
|
|
procedure
|
|
|
|
|
.groupe_instructeurs
|
|
|
|
|
.map { |gi| [gi.label, gi.instructeurs.map(&:email)] }
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
.to_h
|
2021-01-20 11:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-06-09 17:52:29 +02:00
|
|
|
|
subject { described_class.import(procedure, lines) }
|
2021-01-20 11:07:44 +01:00
|
|
|
|
|
|
|
|
|
context 'nominal case' do
|
|
|
|
|
let(:lines) do
|
|
|
|
|
[
|
|
|
|
|
{ "groupe" => "Auvergne Rhone-Alpes", "email" => "john@lennon.fr" },
|
|
|
|
|
{ "groupe" => " Occitanie ", "email" => "paul@mccartney.uk" },
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "ringo@starr.uk" }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'imports' do
|
|
|
|
|
errors = subject
|
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(procedure_groupes.keys).to contain_exactly("Auvergne Rhone-Alpes", "Occitanie", "défaut")
|
|
|
|
|
expect(procedure_groupes["Auvergne Rhone-Alpes"]).to contain_exactly("john@lennon.fr")
|
|
|
|
|
expect(procedure_groupes["Occitanie"]).to contain_exactly("paul@mccartney.uk", "ringo@starr.uk")
|
|
|
|
|
expect(procedure_groupes["défaut"]).to be_empty
|
2021-01-20 11:07:44 +01:00
|
|
|
|
|
|
|
|
|
expect(errors).to match_array([])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when group already exists' do
|
|
|
|
|
let!(:gi) { create(:groupe_instructeur, label: 'Occitanie', procedure: procedure) }
|
|
|
|
|
let(:lines) do
|
|
|
|
|
[
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "ringo@starr.uk" }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
gi.instructeurs << create(:instructeur, email: 'george@harisson.uk')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'adds instructeur to existing groupe' do
|
|
|
|
|
subject
|
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(procedure_groupes.keys).to contain_exactly("Occitanie", "défaut")
|
|
|
|
|
expect(procedure_groupes["Occitanie"]).to contain_exactly("george@harisson.uk", "ringo@starr.uk")
|
|
|
|
|
expect(procedure_groupes["défaut"]).to be_empty
|
2021-01-20 11:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when an email is malformed' do
|
|
|
|
|
let(:lines) do
|
|
|
|
|
[
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "paul" },
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => " Paul@mccartney.uk " },
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "ringo@starr.uk" }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'ignores or corrects' do
|
|
|
|
|
errors = subject
|
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(procedure_groupes.keys).to contain_exactly("Occitanie", "défaut")
|
|
|
|
|
expect(procedure_groupes["Occitanie"]).to contain_exactly("paul@mccartney.uk", "ringo@starr.uk")
|
|
|
|
|
expect(procedure_groupes["défaut"]).to be_empty
|
2021-01-20 11:07:44 +01:00
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(errors).to contain_exactly("paul")
|
2021-01-20 11:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when an instructeur already exists' do
|
|
|
|
|
let!(:instructeur) { create(:instructeur) }
|
|
|
|
|
let(:lines) do
|
|
|
|
|
[
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => instructeur.email },
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "ringo@starr.uk" }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'reuses instructeur' do
|
|
|
|
|
subject
|
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(procedure_groupes.keys).to contain_exactly("Occitanie", "défaut")
|
|
|
|
|
expect(procedure_groupes["Occitanie"]).to contain_exactly(instructeur.email, "ringo@starr.uk")
|
|
|
|
|
expect(procedure_groupes["défaut"]).to be_empty
|
2021-01-20 11:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when there are 2 emails of same instructeur to be imported' do
|
|
|
|
|
let(:lines) do
|
|
|
|
|
[
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "ringo@starr.uk" },
|
|
|
|
|
{ "groupe" => "Occitanie", "email" => "ringo@starr.uk" }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'ignores duplicated instructeur' do
|
|
|
|
|
subject
|
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(procedure_groupes.keys).to contain_exactly("Occitanie", "défaut")
|
|
|
|
|
expect(procedure_groupes["Occitanie"]).to contain_exactly("ringo@starr.uk")
|
|
|
|
|
expect(procedure_groupes["défaut"]).to be_empty
|
2021-01-20 11:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when label of group is empty' do
|
|
|
|
|
let(:lines) do
|
|
|
|
|
[
|
|
|
|
|
{ "groupe" => "", "email" => "ringo@starr.uk" },
|
|
|
|
|
{ "groupe" => " ", "email" => "paul@starr.uk" }
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'ignores instructeur' do
|
|
|
|
|
errors = subject
|
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(procedure_groupes.keys).to contain_exactly("défaut")
|
|
|
|
|
expect(procedure_groupes["défaut"]).to be_empty
|
2021-01-20 11:07:44 +01:00
|
|
|
|
|
Fix (Instructeur): deal nicely with non-guaranteed elements order in arrays
Use of one-dimension arrays comparison & `contain_exactly` RSpec matcher
to avoid this behaviour:
Failures:
1) InstructeursImportService#import when an email is malformed ignores or corrects
Failure/Error:
expect(procedure_groupes).to match_array([
["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]],
["défaut", []]
])
expected collection contained: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]], ["défaut", []]]
actual collection contained: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]], ["défaut", []]]
the missing elements were: [["Occitanie", ["paul@mccartney.uk", "ringo@starr.uk"]]]
the extra elements were: [["Occitanie", ["ringo@starr.uk", "paul@mccartney.uk"]]]
# ./spec/services/instructeurs_import_service_spec.rb:70:in `block (4 levels) in <main>'
2021-05-21 10:57:00 +02:00
|
|
|
|
expect(errors).to contain_exactly("ringo@starr.uk", "paul@starr.uk")
|
2021-01-20 11:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|