Improve registrar sessions specs

registry-240
This commit is contained in:
Artur Beljajev 2016-11-09 19:12:51 +02:00
parent 576c09b00d
commit 2643df8d21
7 changed files with 43 additions and 13 deletions

View file

@ -101,12 +101,6 @@ class Registrar::SessionsController < Devise::SessionsController
endpoint = "#{ENV['sk_digi_doc_service_endpoint']}"
client = Digidoc::Client.new(endpoint)
if Rails.env.test? && phone == "123"
@user = ApiUser.find_by(identity_code: "14212128025")
sign_in(@user, event: :authentication)
return redirect_to registrar_root_url
end
# country_codes = {'+372' => 'EST'}
phone.gsub!('+372', '')
response = client.authenticate(

View file

@ -8,13 +8,13 @@
- error_class = f.object.errors.any? ? 'has-error' : ''
%div{class: error_class}
= f.text_field :tag, class: 'form-control', placeholder: t(:username), required: true
= f.password_field :password, class: 'form-control',
= f.password_field :password, class: 'form-control',
autocomplete: 'off', placeholder: t(:password), required: true
%button.btn.btn-lg.btn-primary.btn-block{:type => 'submit'}= t(:log_in)
%button.btn.btn-lg.btn-primary.btn-block{:type => 'submit'}= t('.login_btn')
%hr
= link_to '/registrar/login/mid' do
= link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do
= image_tag 'mid.gif'
= link_to '/registrar/id', method: :post do
= image_tag 'id_card.gif'

View file

@ -2,11 +2,11 @@
.form-signin.col-md-4.center-block.text-center
%h2.form-signin-heading.text-center= t(:log_in_with_mid)
%hr
= form_for @user, url: registrar_mid_path, auto_html5_validation: false,
= form_for @user, url: registrar_mid_path, auto_html5_validation: false,
html: {class: 'form-signin'} do |f|
= f.text_field :phone, class: 'form-control',
= f.text_field :phone, class: 'form-control',
placeholder: t(:phone_no), autocomplete: 'off', required: true
%button.btn.btn-lg.btn-primary.btn-block.js-login{:type => 'submit'}= t(:log_in)
%button.btn.btn-lg.btn-primary.btn-block.js-login{:type => 'submit'}= t('.login_btn')
- if ['development', 'alpha'].include?(Rails.env)
%div.text-center

View file

@ -531,7 +531,6 @@ en:
ident_update_error: 'Parameter value policy error. Update of ident data not allowed [ident]'
invoices: 'Invoices'
no_such_user: 'No such user'
log_in: 'Log in'
phone_no: 'Phone number'
log_in_with_mid: 'Log in with mobile-id'
confirmation_sms_was_sent_to_your_phone_verification_code_is: 'Confirmation sms was sent to your phone. Verification code is %{code}.'

View file

@ -0,0 +1,7 @@
en:
registrar:
sessions:
login:
login_btn: Login
login_mid:
login_btn: Login

View file

@ -0,0 +1,21 @@
require 'rails_helper'
RSpec.feature 'Mobile ID login', db: true do
given!(:api_user) { Fabricate(:api_user, identity_code: 1234) }
background do
Setting.registrar_ip_whitelist_enabled = false
digidoc_client = instance_double(Digidoc::Client, authenticate: OpenStruct.new(user_id_code: 1234), session_code: 1234)
allow(Digidoc::Client).to receive(:new).and_return(digidoc_client)
end
scenario 'login with phone number' do
visit registrar_login_path
click_on 'login-with-mobile-id-btn'
fill_in 'user[phone]', with: '1234'
click_button 'Login'
expect(page).to have_text('Confirmation sms was sent to your phone. Verification code is')
end
end

View file

@ -0,0 +1,9 @@
require 'rails_helper'
RSpec.describe Registrar::SessionsController do
describe 'routing' do
it 'routes to #login' do
expect(get: '/registrar/login').to route_to('registrar/sessions#login')
end
end
end