Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienMLD committed Jun 3, 2024
1 parent 71e06b7 commit f8d7af1
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 60 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require:
- rubocop-i18n
- rubocop-capybara
- rubocop-factory_bot
- rubocop-rspec_rails

AllCops:
TargetRubyVersion: 2.7
Expand Down
201 changes: 141 additions & 60 deletions spec/services/create_diagnosis/find_relevant_expert_subjects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,70 @@
require 'rails_helper'
describe CreateDiagnosis::FindRelevantExpertSubjects do
describe 'apply_match_filters' do
subject{ described_class.new(need).apply_match_filters(ExpertSubject.all) }

let(:institution) { create :institution }
let!(:es_temoin) { create :expert_subject }
let(:antenne) { create :antenne, institution: institution }

subject{ described_class.new(need).apply_match_filters(ExpertSubject.all) }

describe 'accepting_years_of_existence' do
context 'accepting_years_of_existence' do
let(:diagnosis) { create :diagnosis, company: company }
let(:need) { create :need, diagnosis: diagnosis }
let!(:es_01) { create :expert_subject }

context 'min_years_of_existence' do
let(:match_filter_01) { create :match_filter, :for_antenne, min_years_of_existence: 3 }
describe 'min_years_of_existence' do
let(:match_filter_01) { create :match_filter, antenne: antenne, min_years_of_existence: 5 }
let(:match_filter_02) { create :match_filter, institution: institution, min_years_of_existence: 3 }

before { es_01.expert.antenne.match_filters << match_filter_01 }
context 'with antenne filter only' do
before { es_01.expert.antenne.match_filters << match_filter_01 }

context 'young company' do
let(:company) { create :company, date_de_creation: 2.years.ago }
context 'young company' do
let(:company) { create :company, date_de_creation: 4.years.ago }

it { is_expected.to contain_exactly(es_temoin) }
it { is_expected.to contain_exactly(es_temoin) }
end

context 'old company' do
let(:company) { create :company, date_de_creation: 7.years.ago }

it { is_expected.to contain_exactly(es_01, es_temoin) }
end
end

context 'old company' do
let(:company) { create :company, date_de_creation: 7.years.ago }
context 'with institution filter only' do
before { es_01.expert.institution.match_filters << match_filter_02 }

it { is_expected.to contain_exactly(es_01, es_temoin) }
context 'young company' do
let(:company) { create :company, date_de_creation: 2.years.ago }

it { is_expected.to contain_exactly(es_temoin) }
end

context 'old company' do
let(:company) { create :company, date_de_creation: 4.years.ago }

it { is_expected.to contain_exactly(es_01, es_temoin) }
end
end

context 'with institution and antenne filter' do
before do
es_01.expert.antenne.match_filters << match_filter_01
es_01.expert.institution.match_filters << match_filter_02
end

context 'young company' do
let(:company) { create :company, date_de_creation: 2.years.ago }

it { is_expected.to contain_exactly(es_temoin) }
end

context 'old company' do
let(:company) { create :company, date_de_creation: 5.years.ago }

it { is_expected.to contain_exactly(es_01, es_temoin) }
end
end
end

Expand Down Expand Up @@ -54,37 +94,107 @@
let(:need) { create :need, diagnosis: diagnosis, subject: need_subject }

let!(:tresorerie_subject) { create :subject }
let(:match_filter_01) { create :match_filter, :for_antenne, effectif_max: 20, subjects: [tresorerie_subject] }
let(:match_filter_01) { create :match_filter, antenne: antenne, effectif_max: 10, subjects: [tresorerie_subject] }
let(:match_filter_02) { create :match_filter, institution: institution, effectif_max: 50, subjects: [tresorerie_subject] }
let!(:es_01) { create :expert_subject }

before { es_01.expert.antenne.match_filters << match_filter_01 }
context 'with antenne filter only' do
before { es_01.expert.antenne.match_filters << match_filter_01 }

context 'matching nothing' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '12' }
context 'matching nothing' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '12' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end
it { is_expected.to contain_exactly(es_temoin, es_01) }
end

context 'matching subject only' do
let(:facility) { create :facility, code_effectif: '12' }
let(:need_subject) { tresorerie_subject }
context 'matching subject only' do
let(:facility) { create :facility, code_effectif: '12' }
let(:need_subject) { tresorerie_subject }

it { is_expected.to contain_exactly(es_temoin) }
it { is_expected.to contain_exactly(es_temoin) }
end

context 'matching effectif only' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '03' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end

context 'matching subject and effectif' do
let(:need_subject) { tresorerie_subject }
let(:facility) { create :facility, code_effectif: '03' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end
end

context 'matching effectif only' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '11' }
context 'with antenne and institution filter' do
before do
es_01.expert.antenne.match_filters << match_filter_01
es_01.expert.institution.match_filters << match_filter_02
end

it { is_expected.to contain_exactly(es_temoin, es_01) }
context 'matching nothing' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '12' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end

context 'matching subject only' do
let(:facility) { create :facility, code_effectif: '12' }
let(:need_subject) { tresorerie_subject }

it { is_expected.to contain_exactly(es_temoin) }
end

context 'matching effectif only' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '03' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end

context 'matching subject and effectif' do
let(:need_subject) { tresorerie_subject }
let(:facility) { create :facility, code_effectif: '03' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end
end

context 'matching subject and effectif' do
let(:need_subject) { tresorerie_subject }
let(:facility) { create :facility, code_effectif: '11' }
context 'with institution filter only' do
before { es_01.expert.institution.match_filters << match_filter_02 }

it { is_expected.to contain_exactly(es_temoin, es_01) }
context 'matching nothing' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '32' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end

context 'matching subject only' do
let(:facility) { create :facility, code_effectif: '32' }
let(:need_subject) { tresorerie_subject }

it { is_expected.to contain_exactly(es_temoin) }
end

context 'matching effectif only' do
let(:need_subject) { create :subject }
let(:facility) { create :facility, code_effectif: '12' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end

context 'matching subject and effectif' do
let(:need_subject) { tresorerie_subject }
let(:facility) { create :facility, code_effectif: '12' }

it { is_expected.to contain_exactly(es_temoin, es_01) }
end
end
end

Expand Down Expand Up @@ -380,35 +490,6 @@
end
end
end

describe 'With institution and antenne filters take antenne filter' do
context 'min_years_of_existence' do
let(:diagnosis) { create :diagnosis, company: company }
let(:need) { create :need, diagnosis: diagnosis }
let!(:es_01) { create :expert_subject }
let(:institution) { create :institution }
let(:antenne) { create :antenne, institution: institution }
let(:match_filter_01) { create :match_filter, antenne: antenne, min_years_of_existence: 10 }
let(:match_filter_02) { create :match_filter, institution: institution, min_years_of_existence: 5 }

before do
es_01.expert.antenne.match_filters << match_filter_01
es_01.expert.institution.match_filters << match_filter_02
end

context 'young company' do
let(:company) { create :company, date_de_creation: 7.years.ago }

it { is_expected.to contain_exactly(es_temoin) }
end

context 'old company' do
let(:company) { create :company, date_de_creation: 11.years.ago }

it { is_expected.to contain_exactly(es_01, es_temoin) }
end
end
end
end

describe 'apply_institution_filters' do
Expand Down

0 comments on commit f8d7af1

Please sign in to comment.