Added Registrar feature tests

This commit is contained in:
Priit Tark 2015-04-13 16:54:00 +03:00
parent bcb283e2f1
commit 45bed63cad
12 changed files with 218 additions and 25 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -1 +1 @@
invoices
invoices index

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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