spec: cleanup siret_controller_spec.rb
This commit is contained in:
parent
fd95ea2871
commit
7c1c61248e
1 changed files with 48 additions and 37 deletions
|
@ -20,74 +20,85 @@ describe Champs::SiretController, type: :controller do
|
|||
end
|
||||
let(:siret) { '' }
|
||||
|
||||
context 'when user is connected' do
|
||||
context 'when the user is signed in' do
|
||||
render_views
|
||||
before { sign_in user }
|
||||
|
||||
context 'when siret empty' do
|
||||
before {
|
||||
get :show, params: params, format: 'js'
|
||||
}
|
||||
context 'when the SIRET is empty' do
|
||||
subject! { get :show, params: params, format: 'js' }
|
||||
|
||||
it 'empty info message' do
|
||||
it 'clears the etablissement and SIRET on the model' do
|
||||
champ.reload
|
||||
expect(champ.etablissement).to be_nil
|
||||
expect(champ.value).to be_empty
|
||||
end
|
||||
|
||||
it 'clears any information or error message' do
|
||||
expect(response.body).to include('.siret-info-1')
|
||||
expect(response.body).to include('innerHTML = ""')
|
||||
champ.reload
|
||||
expect(champ.etablissement).to be_nil
|
||||
expect(champ.value).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when siret invalid' do
|
||||
context 'when the SIRET is invalid' do
|
||||
let(:siret) { '1234' }
|
||||
before {
|
||||
get :show, params: params, format: 'js'
|
||||
}
|
||||
|
||||
it 'invalid error' do
|
||||
subject! { get :show, params: params, format: 'js' }
|
||||
|
||||
it 'clears the etablissement and SIRET on the model' do
|
||||
champ.reload
|
||||
expect(champ.etablissement).to be_nil
|
||||
expect(champ.value).to be_empty
|
||||
end
|
||||
|
||||
it 'displays a “SIRET is invalid” error message' do
|
||||
expect(response.body).to include('Le numéro de SIRET doit comporter exactement 14 chiffres.')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the SIRET is valid but unknown' do
|
||||
let(:siret) { '00000000000000' }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:find_etablissement_with_siret).and_return(false)
|
||||
end
|
||||
|
||||
subject! { get :show, params: params, format: 'js' }
|
||||
|
||||
it 'clears the etablissement and SIRET on the model' do
|
||||
champ.reload
|
||||
expect(champ.etablissement).to be_nil
|
||||
expect(champ.value).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when siret not found' do
|
||||
let(:siret) { '0' * 14 }
|
||||
before {
|
||||
expect(subject).to receive(:find_etablisement_with_siret).and_return(false)
|
||||
get :show, params: params, format: 'js'
|
||||
}
|
||||
|
||||
it 'not found error' do
|
||||
it 'displays a “SIRET not found” error message' do
|
||||
expect(response.body).to include('Nous n’avons pas trouvé d’établissement correspondant à ce numéro de SIRET.')
|
||||
champ.reload
|
||||
expect(champ.etablissement).to be_nil
|
||||
expect(champ.value).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when siret found' do
|
||||
context 'when the SIRET informations are retrieved successfully' do
|
||||
let(:siret) { etablissement.siret }
|
||||
let(:etablissement) { build(:etablissement) }
|
||||
before {
|
||||
expect(subject).to receive(:find_etablisement_with_siret).and_return(etablissement)
|
||||
get :show, params: params, format: 'js'
|
||||
}
|
||||
|
||||
it 'etablissement info message' do
|
||||
expect(response.body).to include(etablissement.entreprise_raison_sociale)
|
||||
before do
|
||||
allow(controller).to receive(:find_etablissement_with_siret).and_return(etablissement)
|
||||
end
|
||||
|
||||
subject! { get :show, params: params, format: 'js' }
|
||||
|
||||
it 'populates the etablissement and SIRET on the model' do
|
||||
champ.reload
|
||||
expect(champ.value).to eq(etablissement.siret)
|
||||
expect(champ.etablissement.siret).to eq(etablissement.siret)
|
||||
end
|
||||
|
||||
it 'displays the name of the company' do
|
||||
expect(response.body).to include(etablissement.entreprise_raison_sociale)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not connected' do
|
||||
before {
|
||||
get :show, params: { position: '1' }, format: 'js'
|
||||
}
|
||||
context 'when user is not signed in' do
|
||||
subject! { get :show, params: { position: '1' }, format: 'js' }
|
||||
|
||||
it { expect(response.code).to eq('401') }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue