2016-11-14 18:36:09 +01:00
|
|
|
require 'spec_helper'
|
2016-10-25 18:45:05 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
describe Search do
|
2018-03-20 16:00:30 +01:00
|
|
|
describe '#results' 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
|
|
|
|
described_class.new(gestionnaire: gestionnaire_1, query: terms).results
|
|
|
|
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
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) }
|
|
|
|
let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2017-04-12 17:13:31 +02:00
|
|
|
before do
|
|
|
|
create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1
|
|
|
|
create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2
|
|
|
|
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
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
let!(:dossier_0) { create(:dossier, state: 'brouillon', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) }
|
2017-12-14 15:51:45 +01:00
|
|
|
let!(:dossier_1) { create(:dossier, state: 'en_construction', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) }
|
|
|
|
let!(:dossier_2) { create(:dossier, state: 'en_construction', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) }
|
|
|
|
let!(:dossier_3) { create(:dossier, state: 'en_construction', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) }
|
|
|
|
let!(:dossier_archived) { create(:dossier, state: 'en_construction', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) }
|
2016-10-29 00:53:04 +02:00
|
|
|
|
2018-04-23 11:57:38 +02:00
|
|
|
let!(:etablissement_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', dossier: dossier_1, siret: '41636169600051') }
|
|
|
|
let!(:etablissement_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', dossier: dossier_2, siret: '41816602300012') }
|
|
|
|
let!(:etablissement_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', dossier: dossier_3, siret: '41816609600051') }
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
end
|
2016-10-25 18:45:05 +02:00
|
|
|
end
|