Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Sep 21, 2023
1 parent d08b02e commit 5b748db
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AllCops:
- 'test/**/*'
- 'db/**/*'
- 'config/**/*'
- 'spec/**/*'
- 'bin/*'
- 'config.ru'
- 'Gemfile'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/auth/tara_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
14 changes: 12 additions & 2 deletions config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
factory :user do
email { "[email protected]" }
password_digest { "MyString" }
uid { "EE60001019906" }
identity_code { "60001019906" }
provider { "tara" }
end
end
2 changes: 1 addition & 1 deletion spec/factories/white_codes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryBot.define do
factory :white_code do
code { "MyString" }
code { "60001019906" }
end
end
4 changes: 3 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions spec/requests/dashboards/invoice_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions spec/requests/dashboards/invoice_synchronizes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/support/auth.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5b748db

Please sign in to comment.