Tests: feature flip tests that require postgres

This commit is contained in:
Simon Lehericey 2017-02-21 16:47:59 +01:00
parent 15d27f6a7d
commit 382b614095
3 changed files with 125 additions and 118 deletions

View file

@ -174,39 +174,42 @@ describe Backoffice::DossiersController, type: :controller do
end end
end end
describe 'POST #search' do
describe 'by id' do
context 'when I am logged as a gestionnaire' do
before do
sign_in gestionnaire
end
context 'when I own the dossier' do if ENV['PG'] == 'true'
before :each do describe 'POST #search' do
post :search, params: { q: dossier_id } describe 'by id' do
context 'when I am logged as a gestionnaire' do
before do
sign_in gestionnaire
end end
it 'returns http success' do context 'when I own the dossier' do
expect(response).to have_http_status(200) before :each do
post :search, params: { q: dossier_id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns the expected dossier' do
expect(assigns(:dossiers).count).to eq(1)
expect(assigns(:dossiers).first.id).to eq(dossier_id)
end
end end
it 'returns the expected dossier' do context 'when I do not own the dossier' do
expect(assigns(:dossiers).count).to eq(1) before :each do
expect(assigns(:dossiers).first.id).to eq(dossier_id) post :search, params: { q: dossier2_id }
end end
end
context 'when I do not own the dossier' do it 'returns http success' do
before :each do expect(response).to have_http_status(200)
post :search, params: { q: dossier2_id } end
end
it 'returns http success' do it 'returns nothing' do
expect(response).to have_http_status(200) expect(assigns(:dossiers).count).to eq(0)
end end
it 'returns nothing' do
expect(assigns(:dossiers).count).to eq(0)
end end
end end
end end

View file

@ -1,52 +1,54 @@
require 'spec_helper' require 'spec_helper'
feature 'search file on gestionnaire backoffice' do if ENV['PG'] == 'true'
let(:administrateur) { create(:administrateur) } feature 'search file on gestionnaire backoffice' do
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) } let(:administrateur) { create(:administrateur) }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
before do before do
login_as gestionnaire, scope: :gestionnaire login_as gestionnaire, scope: :gestionnaire
end end
context 'when gestionnaire is logged in' do context 'when gestionnaire is logged in' do
context 'when he click on search button' do context 'when he click on search button' do
let(:terms) { '' } let(:terms) { '' }
let!(:procedure) { create(:procedure, administrateur: administrateur) } let!(:procedure) { create(:procedure, administrateur: administrateur) }
before do before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure create :assign_to, gestionnaire: gestionnaire, procedure: procedure
visit backoffice_dossiers_url visit backoffice_dossiers_url
page.find_by_id(:q).set terms page.find_by_id(:q).set terms
page.find_by_id(:search_button).click page.find_by_id(:search_button).click
end
it { expect(page).to have_css('#backoffice_search') }
context 'when terms input is empty' do
it { expect(page).to have_content('Aucun dossier') }
end
context 'when terms input is informed' do
let(:terms) { 'test' }
it 'terms stay in input after search' do
expect(page.find_by_id('q').value).to eq(terms)
end end
context 'when terms input does not return result' do it { expect(page).to have_css('#backoffice_search') }
context 'when terms input is empty' do
it { expect(page).to have_content('Aucun dossier') } it { expect(page).to have_content('Aucun dossier') }
end end
context 'when terms input does return result' do context 'when terms input is informed' do
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') } let(:terms) { 'test' }
let!(:dossier_2) { create(:dossier, procedure: procedure, state: 'initiated') }
let(:terms) { dossier.entreprise.raison_sociale } it 'terms stay in input after search' do
expect(page.find_by_id('q').value).to eq(terms)
end
it { expect(page).to have_content(dossier.entreprise.raison_sociale) } context 'when terms input does not return result' do
it { expect(page).to have_content('Aucun dossier') }
end
context 'when terms input does return result' do
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
let!(:dossier_2) { create(:dossier, procedure: procedure, state: 'initiated') }
let(:terms) { dossier.entreprise.raison_sociale }
it { expect(page).to have_content(dossier.entreprise.raison_sociale) }
end
end end
end end
end end
end end
end end

View file

@ -1,79 +1,81 @@
require 'spec_helper' require 'spec_helper'
describe Search do if ENV['PG'] == 'true'
describe '.results' do describe Search do
subject { liste_dossiers } describe '.results' do
subject { liste_dossiers }
let(:liste_dossiers) do let(:liste_dossiers) do
described_class.new(gestionnaire: gestionnaire_1, query: terms).results described_class.new(gestionnaire: gestionnaire_1, query: terms).results
end end
let(:administrateur_1) { create(:administrateur) } let(:administrateur_1) { create(:administrateur) }
let(:administrateur_2) { create(:administrateur) } let(:administrateur_2) { create(:administrateur) }
let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) } let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) }
let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) } let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) }
before do before do
create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1 create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1
create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2 create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2
end end
let(:procedure_1) { create(:procedure, administrateur: administrateur_1) } let(:procedure_1) { create(:procedure, administrateur: administrateur_1) }
let(:procedure_2) { create(:procedure, administrateur: administrateur_2) } let(:procedure_2) { create(:procedure, administrateur: administrateur_2) }
let!(:dossier_0) { create(:dossier, state: 'draft', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) } let!(:dossier_0) { create(:dossier, state: 'draft', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) }
let!(:dossier_1) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) } let!(:dossier_1) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) }
let!(:dossier_2) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) } let!(:dossier_2) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) }
let!(:dossier_3) { create(:dossier, state: 'initiated', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) } let!(:dossier_3) { create(:dossier, state: 'initiated', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) }
let!(:dossier_archived) { create(:dossier, state: 'initiated', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) } let!(:dossier_archived) { create(:dossier, state: 'initiated', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) }
let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') } let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') }
let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') } let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') }
let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') } let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') }
describe 'search is empty' do describe 'search is empty' do
let(:terms) { '' } let(:terms) { '' }
it { expect(subject.size).to eq(0) } it { expect(subject.size).to eq(0) }
end end
describe 'search draft file' do describe 'search draft file' do
let(:terms) { 'brouillon' } let(:terms) { 'brouillon' }
it { expect(subject.size).to eq(0) } it { expect(subject.size).to eq(0) }
end end
describe 'search on contact email' do describe 'search on contact email' do
let(:terms) { 'clap' } let(:terms) { 'clap' }
it { expect(subject.size).to eq(0) } it { expect(subject.size).to eq(0) }
end end
describe 'search on SIRET' do describe 'search on SIRET' do
context 'when is part of SIRET' do context 'when is part of SIRET' do
let(:terms) { '4181' } let(:terms) { '4181' }
it { expect(subject.size).to eq(1) }
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(2) }
end
describe 'search on multiple fields' do
let(:terms) { 'octo plop' }
it { expect(subject.size).to eq(1) } it { expect(subject.size).to eq(1) }
end 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(2) }
end
describe 'search on multiple fields' do
let(:terms) { 'octo plop' }
it { expect(subject.size).to eq(1) }
end end
end end
end end