Files
nairobi/spec/lib/manager_authenticator_spec.rb
Bertocq de2816a6a5 Enable RSpec/BeforeAfterAll rule and fix all issues
This cop tries to avoid state leaking between examples. The fixes done on the code don't follow the suggested path, since the usage of `before(:all)` was not really useful. By using RSpec's `let` method we achieve same goals but with much better and readable tests.

Check Cop description at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
2018-01-06 21:16:00 +01:00

61 lines
2.5 KiB
Ruby

require 'rails_helper'
describe ManagerAuthenticator do
let(:authenticator) { ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") }
describe 'initialization params' do
it 'should cause auth to return false if blank login' do
blank_login_authenticator = ManagerAuthenticator.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905")
expect(blank_login_authenticator.auth).to be false
end
it 'should cause auth to return false if blank user_key' do
blank_user_key_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905")
expect(blank_user_key_authenticator.auth).to be false
end
it 'should cause auth to return false if blank date' do
blank_date_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "")
expect(blank_date_authenticator.auth).to be false
end
end
describe '#auth' do
it 'should return false if not manager_exists' do
allow(authenticator).to receive(:manager_exists?).and_return(false)
allow(authenticator).to receive(:application_authorized?).and_return(true)
expect(authenticator.auth).to be false
end
it 'should return false if not application_authorized' do
allow(authenticator).to receive(:manager_exists?).and_return(true)
allow(authenticator).to receive(:application_authorized?).and_return(false)
expect(authenticator.auth).to be false
end
it 'should return ok if manager_exists and application_authorized' do
allow(authenticator).to receive(:manager_exists?).and_return(true)
allow(authenticator).to receive(:application_authorized?).and_return(true)
expect(authenticator.auth).to be_truthy
end
end
describe 'SOAP' do
it 'should call the verification user method' do
message = { ub: {user_key: "31415926", date: "20151031135905"} }
allow(authenticator).to receive(:application_authorized?).and_return(true)
expect(authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message)
authenticator.auth
end
it 'should call the permissions check method' do
allow(authenticator).to receive(:manager_exists?).and_return(true)
expect(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} })
authenticator.auth
end
end
end