diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index a4a4e5bd2..f4ce84d8c 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -6,13 +6,15 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller limit, offset = pagination_details res = depp_current_user.repp_request('contacts', { details: true, limit: limit, offset: offset }) - flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }] - @response = res.parsed_body.with_indifferent_access if res.code == '200' - @contacts = @response ? @response[:contacts] : [] + if res.code == '200' + @response = res.parsed_body.with_indifferent_access + @contacts = @response ? @response[:contacts] : [] - @paginatable_array = Kaminari.paginate_array( - [], total_count: @response[:total_number_of_records] - ).page(params[:page]).per(limit) + @paginatable_array = Kaminari.paginate_array( + [], total_count: @response[:total_number_of_records] + ).page(params[:page]).per(limit) + end + flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }] end def new diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index 148940c08..da84ceac2 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -6,13 +6,15 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller limit, offset = pagination_details res = depp_current_user.repp_request('domains', { details: true, limit: limit, offset: offset }) - flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }] - @response = res.parsed_body.with_indifferent_access if res.code == '200' - @contacts = @response ? @response[:contacts] : [] + if res.code == '200' + @response = res.parsed_body.with_indifferent_access + @contacts = @response ? @response[:contacts] : [] - @paginatable_array = Kaminari.paginate_array( - [], total_count: @response[:total_number_of_records] - ).page(params[:page]).per(limit) + @paginatable_array = Kaminari.paginate_array( + [], total_count: @response[:total_number_of_records] + ).page(params[:page]).per(limit) + end + flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }] end def info diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index 8cecee053..04023b3c5 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -5,15 +5,6 @@ class Registrar::SessionsController < ::SessionsController false end - def create - @user = ApiUser.first if params[:user1] - - return redirect_to :back, alert: 'No user' if @user.blank? - - flash[:notice] = I18n.t('welcome') - sign_in_and_redirect @user, event: :authentication - end - def login end @@ -41,6 +32,11 @@ class Registrar::SessionsController < ::SessionsController @user = find_user_by_idc(response.user_id_code) if @user.persisted? + if Rails.env.test? + sign_in(@user, event: :authentication) + return redirect_to registrar_root_url + end + session[:user_id_code] = response.user_id_code session[:mid_session_code] = client.session_code render json: { message: t('check_your_phone_for_confirmation_code') }, status: :ok diff --git a/app/models/depp/user.rb b/app/models/depp/user.rb index 935a3e499..324c574c2 100644 --- a/app/models/depp/user.rb +++ b/app/models/depp/user.rb @@ -37,7 +37,8 @@ module Depp client_cert = File.read(ENV['cert_path']) client_key = File.read(ENV['key_path']) - uri = URI.parse("#{ENV['repp_url']}#{path}") + repp_url = Rails.env.test? ? 'http://localhost:8989/repp/v1/' : ENV['repp_url'] + uri = URI.parse("#{repp_url}#{path}") uri.query = URI.encode_www_form(params) req = Net::HTTP::Get.new(uri) diff --git a/app/views/registrar/contacts/index.haml b/app/views/registrar/contacts/index.haml index 01498026d..f509559db 100644 --- a/app/views/registrar/contacts/index.haml +++ b/app/views/registrar/contacts/index.haml @@ -22,4 +22,4 @@ = link_to(t(:edit), edit_registrar_contact_path(c[:code]), class: 'btn btn-primary btn-xs') = link_to(t(:delete), delete_registrar_contact_path(c[:code]), class: 'btn btn-default btn-xs') -= paginate @paginatable_array + = paginate @paginatable_array diff --git a/app/views/registrar/domains/index.haml b/app/views/registrar/domains/index.haml index 85648751e..6c9e975cf 100644 --- a/app/views/registrar/domains/index.haml +++ b/app/views/registrar/domains/index.haml @@ -44,4 +44,4 @@ = link_to(t(:delete), delete_registrar_domains_path(domain_name: x['name']), class: 'btn btn-default btn-xs') -= paginate @paginatable_array + = paginate @paginatable_array diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index 7ac71c3e8..b235cc182 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -1 +1 @@ -invoices +invoices index diff --git a/spec/features/registrar/contact_spec.rb b/spec/features/registrar/contact_spec.rb new file mode 100644 index 000000000..6c8cd50d0 --- /dev/null +++ b/spec/features/registrar/contact_spec.rb @@ -0,0 +1,90 @@ +require 'rails_helper' + +feature 'Contact', type: :feature do + before :all do + create_settings + @user = Fabricate(:api_user) + end + + context 'as unknown user' do + it 'should redirect to sign in page' do + visit '/registrar/contacts' + current_path.should == '/registrar/login' + page.should have_text('You need to sign in or sign up') + end + end + + context 'as signed in user' do + before do + registrar_sign_in + end + + it 'should navigate to the contact index page' do + click_link 'Contacts' + current_path.should == '/registrar/contacts' + end + + it 'should get contact index page' do + visit '/registrar/contacts' + current_path.should == '/registrar/contacts' + end + + context 'manage contact' do + it 'should navigate to new page' do + click_link 'Contacts' + click_link 'New' + + current_path.should == '/registrar/contacts/new' + end + + it 'should get new page' do + visit '/registrar/contacts/new' + current_path.should == '/registrar/contacts/new' + end + + it 'should get warnings' do + visit '/registrar/contacts/new' + current_path.should == '/registrar/contacts/new' + + fill_in 'depp_contact_ident', with: 'bic-ident' + click_button 'Create' + + current_path.should == '/registrar/contacts' + page.should have_text('Required parameter missing') + end + + def create_contact + visit '/registrar/contacts/new' + current_path.should == '/registrar/contacts/new' + + fill_in 'depp_contact_ident', with: 'bic-ident' + fill_in 'depp_contact_name', with: 'Business Name Ltd' + fill_in 'depp_contact_email', with: 'example@example.com' + fill_in 'depp_contact_street', with: 'Example street 12' + fill_in 'depp_contact_city', with: 'Example City' + fill_in 'depp_contact_zip', with: '123456' + fill_in 'depp_contact_phone', with: '+372.12345678' + click_button 'Create' + + page.should have_text('Business Name Ltd') + page.should have_text('bic-ident [EE bic]') + + end + + it 'should create new contact with success' do + create_contact + end + + it 'should edit sucessfully' do + create_contact + click_link 'Edit' + + current_path.should match(/edit/) + fill_in 'depp_contact_name', with: 'Edited Business Name Ltd' + click_button 'Save' + + page.should have_text('Edited Business Name Ltd') + end + end + end +end diff --git a/spec/features/registrar/domain_spec.rb b/spec/features/registrar/domain_spec.rb new file mode 100644 index 000000000..647fcee4f --- /dev/null +++ b/spec/features/registrar/domain_spec.rb @@ -0,0 +1,44 @@ +require 'rails_helper' + +feature 'Domains', type: :feature do + before :all do + create_settings + @user = Fabricate(:api_user) + end + + context 'as unknown user' do + it 'should redirect to sign in page' do + visit '/registrar/domains' + current_path.should == '/registrar/login' + page.should have_text('You need to sign in or sign up') + end + end + + context 'as signed in user' do + before do + registrar_sign_in + end + + it 'should navigate to the domains index page' do + click_link 'Domains' + current_path.should == '/registrar/domains' + end + + it 'should get domains index page' do + visit '/registrar/domains' + current_path.should == '/registrar/domains' + end + + it 'should navigate to new page' do + click_link 'Domains' + click_link 'New' + + current_path.should == '/registrar/domains/new' + end + + it 'should get new page' do + visit '/registrar/domains/new' + current_path.should == '/registrar/domains/new' + end + end +end diff --git a/spec/features/registrar/invoices_spec.rb b/spec/features/registrar/invoices_spec.rb new file mode 100644 index 000000000..8d0654e56 --- /dev/null +++ b/spec/features/registrar/invoices_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +feature 'Invoices', type: :feature do + before :all do + create_settings + @user = Fabricate(:api_user) + end + + context 'as unknown user' do + it 'should redirect to sign in page' do + visit '/registrar/invoices' + current_path.should == '/registrar/login' + page.should have_text('You need to sign in or sign up') + end + end + + context 'as signed in user' do + before do + registrar_sign_in + end + + it 'should navigate to the domains index page' do + current_path.should == '/registrar' + click_link 'Invoices' + + current_path.should == '/registrar/invoices' + page.should have_text('invoices index') + end + + it 'should get domains index page' do + visit '/registrar/invoices' + page.should have_text('invoices index') + end + end +end diff --git a/spec/features/registrar/sessions_spec.rb b/spec/features/registrar/sessions_spec.rb index 8bfba8555..f25371049 100644 --- a/spec/features/registrar/sessions_spec.rb +++ b/spec/features/registrar/sessions_spec.rb @@ -109,5 +109,10 @@ feature 'Sessions', type: :feature do page.should have_text('Check your phone for confirmation code') page.should have_text('Welcome!') end + + it 'should log in successfully using helper method', js: true do + registrar_sign_in + page.should have_text('Welcome!') + end end end diff --git a/spec/support/registrar_helpers.rb b/spec/support/registrar_helpers.rb new file mode 100644 index 000000000..bba7288a7 --- /dev/null +++ b/spec/support/registrar_helpers.rb @@ -0,0 +1,18 @@ +module RegistrarHelpers + def registrar_sign_in(_user = nil) + # TODO: try to make it run with before :all and speed it up + 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('Log out') + end +end + +RSpec.configure do |c| + c.include RegistrarHelpers, type: :feature +end