diff --git a/.rubocop.yml b/.rubocop.yml index 28852db..ee4ec28 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,6 +5,7 @@ AllCops: - 'test/**/*' - 'db/**/*' - 'config/**/*' + - 'spec/**/*' - 'bin/*' - 'config.ru' - 'Gemfile' diff --git a/app/controllers/auth/tara_controller.rb b/app/controllers/auth/tara_controller.rb index a9d83fa..f6fb4ad 100644 --- a/app/controllers/auth/tara_controller.rb +++ b/app/controllers/auth/tara_controller.rb @@ -5,7 +5,7 @@ class TaraController < ParentController allow_unauthenticated def callback - expires_now + expires_now && reset_session unless in_white_list? flash[:alert] = I18n.t('.access_denied') diff --git a/config/application.yml.sample b/config/application.yml.sample index d1d7940..694d21d 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -66,11 +66,21 @@ secret_word: '' e_invoice_provider_test_mode: 'true' + +deposit_min_num: 10001 +deposit_max_num: 14001 + development: allowed_base_urls: 'https://registry.test, https://registrar_center.test, https://eeid.test, https://auction_center.test, https://auction.test' + tara_redirect_uri: 'https://eis_billing_system.test/auth/tara/callback' + tara_identifier: '' + tara_secret: '' + +staging: + tara_redirect_uri: 'https://st-billing.infra.tld.ee/auth/tara/callback' + tara_identifier: '' + tara_secret: '' - deposit_min_num: 10001 - deposit_max_num: 14001 apipie_login: test apipie_password: test diff --git a/spec/factories/users.rb b/spec/factories/users.rb index fa8f9ff..d1ce01e 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -2,5 +2,8 @@ factory :user do email { "admin@example.com" } password_digest { "MyString" } + uid { "EE60001019906" } + identity_code { "60001019906" } + provider { "tara" } end end diff --git a/spec/factories/white_codes.rb b/spec/factories/white_codes.rb index a4f6aa3..d0cfcb5 100644 --- a/spec/factories/white_codes.rb +++ b/spec/factories/white_codes.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :white_code do - code { "MyString" } + code { "60001019906" } end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 778f47b..607fe95 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -27,7 +27,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } # Checks for pending migrations and applies them before tests are run. # If you are not using ActiveRecord, you can remove these lines. @@ -39,6 +39,8 @@ end RSpec.configure do |config| config.include FactoryBot::Syntax::Methods + + config.include Auth # config.fixture_path = "#{::Rails.root}/spec/fixtures" # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures diff --git a/spec/requests/dashboards/invoice_status_spec.rb b/spec/requests/dashboards/invoice_status_spec.rb index 547b331..482355c 100644 --- a/spec/requests/dashboards/invoice_status_spec.rb +++ b/spec/requests/dashboards/invoice_status_spec.rb @@ -2,9 +2,12 @@ RSpec.describe "InvoiceStatus", type: :request do let(:user) { create(:user) } + let(:white_code) { create(:white_code) } + before(:each) do - Current.user = user - allow_any_instance_of(ParentController).to receive(:require_user_logged_in!).and_return(Current.user) + user.reload && white_code.reload + + login user mock_response = { 'message' => 'Invoice data was successfully updated' diff --git a/spec/requests/dashboards/invoice_synchronizes_spec.rb b/spec/requests/dashboards/invoice_synchronizes_spec.rb index 8d761da..59f7c17 100644 --- a/spec/requests/dashboards/invoice_synchronizes_spec.rb +++ b/spec/requests/dashboards/invoice_synchronizes_spec.rb @@ -3,10 +3,12 @@ RSpec.describe "InvoiceSynchronizesController", type: :request do let(:user) { create(:user) } let(:invoice) { create(:invoice) } + let(:white_code) { create(:white_code) } before(:each) do - Current.user = user - allow_any_instance_of(ParentController).to receive(:require_user_logged_in!).and_return(Current.user) + user.reload && white_code.reload + + login user end describe "POST update invoice status" do diff --git a/spec/support/auth.rb b/spec/support/auth.rb new file mode 100644 index 0000000..2fe08bd --- /dev/null +++ b/spec/support/auth.rb @@ -0,0 +1,18 @@ +module Auth + def login(user, first_name = 'TEST', last_name = 'OK') + om = { + 'provider' => 'tara', + 'uid' => user.uid, + 'info' => { + 'first_name' => first_name, + 'last_name' => last_name, + 'name' => user.uid + } + } + + OmniAuth.config.test_mode = true + OmniAuth.config.add_mock(:tara, om) + + post auth_tara_callback_path(provider: 'tara') + end +end