diff --git a/app/assets/images/test.png b/app/assets/images/test.png new file mode 100644 index 000000000..c3f1bf12d Binary files /dev/null and b/app/assets/images/test.png differ diff --git a/spec/fabricators/api_user_fabricator.rb b/spec/fabricators/api_user_fabricator.rb index 361cb1fca..65da9fbab 100644 --- a/spec/fabricators/api_user_fabricator.rb +++ b/spec/fabricators/api_user_fabricator.rb @@ -2,6 +2,7 @@ Fabricator(:api_user) do username { sequence(:username) { |i| "username#{i}" } } password 'ghyt9e4fu' + identity_code '14212128025' registrar active true end diff --git a/spec/features/registrar/sessions_spec.rb b/spec/features/registrar/sessions_spec.rb new file mode 100644 index 000000000..2ca445b15 --- /dev/null +++ b/spec/features/registrar/sessions_spec.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +feature 'Sessions', type: :feature do + before :all do + create_settings + Fabricate(:api_user) + end + + scenario 'Api user should not get in when external service fails' do + client = instance_double("Digidoc::Client") + allow(client).to receive(:authenticate).and_return( + OpenStruct.new( + faultcode: 'Fault', + detail: OpenStruct.new( + message: 'Something is wrong' + ) + ) + ) + + allow(Digidoc::Client).to receive(:new) { client } + + visit registrar_login_path + page.should have_css('a[href="/registrar/login/mid"]') + + page.find('a[href="/registrar/login/mid"]').click + + fill_in 'user_phone', with: '00007' + click_button 'Log in' + page.should have_text('Something is wrong') + end + + scenario 'Api user should not get in when there is not such user' do + client = instance_double("Digidoc::Client") + allow(client).to receive(:authenticate).and_return( + OpenStruct.new( + user_id_code: '123' + ) + ) + + allow(Digidoc::Client).to receive(:new) { client } + + visit registrar_login_path + page.should have_css('a[href="/registrar/login/mid"]') + + page.find('a[href="/registrar/login/mid"]').click + + fill_in 'user_phone', with: '00007' + click_button 'Log in' + page.should have_text('No such user') + end +end