2018-07-31 15:47:49 +02:00
|
|
|
describe DossierSearchService do
|
2021-05-06 01:14:57 +02:00
|
|
|
describe '#matching_dossiers' do
|
2017-04-12 17:13:31 +02:00
|
|
|
subject { liste_dossiers }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
let(:liste_dossiers) do
|
2021-05-06 01:14:57 +02:00
|
|
|
described_class.matching_dossiers(instructeur_1.dossiers, terms)
|
2017-04-12 17:13:31 +02:00
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
let(:administrateur_1) { create(:administrateur) }
|
|
|
|
let(:administrateur_2) { create(:administrateur) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
let(:instructeur_1) { create(:instructeur, administrateurs: [administrateur_1]) }
|
|
|
|
let(:instructeur_2) { create(:instructeur, administrateurs: [administrateur_2]) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
before do
|
2019-08-21 16:16:53 +02:00
|
|
|
instructeur_1.assign_to_procedure(procedure_1)
|
|
|
|
instructeur_2.assign_to_procedure(procedure_2)
|
2024-04-03 10:21:50 +02:00
|
|
|
|
|
|
|
# create dossier before performing jobs
|
|
|
|
# because let!() syntax is executed after "before" callback
|
|
|
|
dossier_0
|
|
|
|
dossier_1
|
|
|
|
dossier_2
|
|
|
|
dossier_3
|
|
|
|
dossier_archived
|
|
|
|
|
2024-04-25 17:57:55 +02:00
|
|
|
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
2017-04-12 17:13:31 +02:00
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-07-18 15:26:33 +02:00
|
|
|
let(:procedure_1) { create(:procedure, :published, administrateur: administrateur_1) }
|
|
|
|
let(:procedure_2) { create(:procedure, :published, administrateur: administrateur_2) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:dossier_0) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:etablissement_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', siret: '41636169600051') }
|
|
|
|
let(:dossier_1) { create(:dossier, :en_construction, procedure: procedure_1, user: create(:user, email: 'contact@test.com'), etablissement: etablissement_1) }
|
2018-07-31 15:47:49 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:etablissement_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', siret: '41816602300012') }
|
|
|
|
let(:dossier_2) { create(:dossier, :en_construction, procedure: procedure_1, user: create(:user, email: 'plop@gmail.com'), etablissement: etablissement_2) }
|
2018-07-31 15:47:49 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:etablissement_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', siret: '41816609600051') }
|
|
|
|
let(:dossier_3) { create(:dossier, :en_construction, procedure: procedure_2, user: create(:user, email: 'peace@clap.fr'), etablissement: etablissement_3) }
|
2018-07-31 15:47:49 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:dossier_archived) { create(:dossier, :en_construction, procedure: procedure_1, archived: true, user: create(:user, email: 'archived@clap.fr')) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
describe 'search is empty' do
|
|
|
|
let(:terms) { '' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(0) }
|
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
describe 'search brouillon file' do
|
2017-04-12 17:13:31 +02:00
|
|
|
let(:terms) { 'brouillon' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(0) }
|
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2018-10-18 15:21:13 +02:00
|
|
|
describe 'search archived file' do
|
|
|
|
let(:terms) { 'archived' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
describe 'search on contact email' do
|
|
|
|
let(:terms) { 'clap' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(0) }
|
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
describe 'search on SIRET' do
|
|
|
|
context 'when is part of SIRET' do
|
|
|
|
let(:terms) { '4181' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
context 'when is a complet SIRET' do
|
|
|
|
let(:terms) { '41816602300012' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(1) }
|
2016-10-29 00:53:04 +02:00
|
|
|
end
|
2017-04-12 17:13:31 +02:00
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
describe 'search on raison social' do
|
|
|
|
let(:terms) { 'OCTO' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(2) }
|
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2018-08-22 18:36:24 +02:00
|
|
|
describe 'search terms surrounded with spurious spaces' do
|
|
|
|
let(:terms) { ' OCTO ' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(2) }
|
|
|
|
end
|
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
describe 'search on multiple fields' do
|
|
|
|
let(:terms) { 'octo plop' }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
it { expect(subject.size).to eq(1) }
|
2016-10-29 00:53:04 +02:00
|
|
|
end
|
2019-01-22 17:16:49 +01:00
|
|
|
|
|
|
|
describe 'search with characters disallowed by the tsquery parser' do
|
|
|
|
let(:terms) { "'?\\:&!(OCTO) <plop>" }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
2016-10-29 00:53:04 +02:00
|
|
|
end
|
2020-04-08 17:10:29 +02:00
|
|
|
|
|
|
|
describe '#matching_dossiers_for_user' do
|
|
|
|
subject { liste_dossiers }
|
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
before do
|
|
|
|
dossier_0
|
|
|
|
dossier_0b
|
|
|
|
dossier_1
|
|
|
|
dossier_2
|
|
|
|
dossier_3
|
|
|
|
dossier_archived
|
2024-04-25 17:57:55 +02:00
|
|
|
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
2024-04-03 10:21:50 +02:00
|
|
|
end
|
|
|
|
|
2020-04-08 17:10:29 +02:00
|
|
|
let(:liste_dossiers) do
|
|
|
|
described_class.matching_dossiers_for_user(terms, user_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:user_1) { create(:user, email: 'bidou@clap.fr') }
|
|
|
|
let(:user_2) { create(:user) }
|
|
|
|
|
|
|
|
let(:procedure_1) { create(:procedure, :published) }
|
|
|
|
let(:procedure_2) { create(:procedure, :published) }
|
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:dossier_0) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure_1, user: user_1) }
|
|
|
|
let(:dossier_0b) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure_1, user: user_2) }
|
2020-04-08 17:10:29 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:etablissement_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', siret: '41636169600051') }
|
|
|
|
let(:dossier_1) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, user: user_1, etablissement: etablissement_1) }
|
2020-04-08 17:10:29 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:etablissement_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', siret: '41816602300012') }
|
|
|
|
let(:dossier_2) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, user: user_1, etablissement: etablissement_2) }
|
2020-04-08 17:10:29 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:etablissement_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', siret: '41816609600051') }
|
|
|
|
let(:dossier_3) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_2, user: user_1, etablissement: etablissement_3) }
|
2020-04-08 17:10:29 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
let(:dossier_archived) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, archived: true, user: user_1) }
|
2020-04-08 17:10:29 +02:00
|
|
|
|
|
|
|
describe 'search is empty' do
|
|
|
|
let(:terms) { '' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search by dossier id' do
|
|
|
|
context 'when the user owns the dossier' do
|
|
|
|
let(:terms) { dossier_0.id.to_s }
|
|
|
|
|
2020-05-07 10:19:57 +02:00
|
|
|
it { expect(subject.map(&:id)).to include(dossier_0.id) }
|
2020-04-08 17:10:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user does not own the dossier' do
|
|
|
|
let(:terms) { dossier_0b.id.to_s }
|
|
|
|
|
2020-05-07 10:19:57 +02:00
|
|
|
it { expect(subject.map(&:id)).not_to include(dossier_0b.id) }
|
2020-04-08 17:10:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search brouillon file' do
|
|
|
|
let(:terms) { 'brouillon' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search on contact email' do
|
|
|
|
let(:terms) { 'bidou@clap.fr' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(5) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search on contact name' do
|
|
|
|
let(:terms) { 'bidou@clap.fr' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(5) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search on SIRET' do
|
|
|
|
context 'when is part of SIRET' do
|
|
|
|
let(:terms) { '4181' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(2) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is a complet SIRET' do
|
|
|
|
let(:terms) { '41816602300012' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search on raison social' do
|
|
|
|
let(:terms) { 'OCTO' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search terms surrounded with spurious spaces' do
|
|
|
|
let(:terms) { ' OCTO ' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search on multiple fields' do
|
|
|
|
let(:terms) { 'octo plop' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search with characters disallowed by the tsquery parser' do
|
|
|
|
let(:terms) { "'?\\:&!(OCTO) <plop>" }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
2020-04-20 14:27:43 +02:00
|
|
|
|
|
|
|
describe 'search with a single forbidden character should not crash postgres' do
|
|
|
|
let(:terms) { '? OCTO' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(3) }
|
|
|
|
end
|
2020-04-08 17:10:29 +02:00
|
|
|
end
|
2016-10-25 18:45:05 +02:00
|
|
|
end
|