From 24c53d8e924338c94f0499481d4b4810c0de0313 Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Mon, 16 Oct 2023 10:38:04 +1100 Subject: [PATCH] test: fix tests config for OmniAuth --- .../app/views/shared/_user_links.html.erb | 2 +- spec/features/active_link_spec.rb | 6 ++-- spec/features/logout_spec.rb | 24 --------------- spec/files/auth/auth_hash.json | 30 +++++++++---------- spec/simplecov_helper.rb | 2 ++ spec/support/omniauth.rb | 9 ++++++ 6 files changed, 29 insertions(+), 44 deletions(-) delete mode 100644 spec/features/logout_spec.rb create mode 100644 spec/support/omniauth.rb diff --git a/spec/dummy/app/views/shared/_user_links.html.erb b/spec/dummy/app/views/shared/_user_links.html.erb index b9a7ca2..ff6ca8e 100644 --- a/spec/dummy/app/views/shared/_user_links.html.erb +++ b/spec/dummy/app/views/shared/_user_links.html.erb @@ -3,7 +3,7 @@
  • <%= link_to "About", about_path, class: "#{active_link_class_controller(%w[pages])}" %>
  • <% if current_user %>
  • - <%= link_to t('blacklight.header_links.logout'), destroy_user_session_path, method: :delete, data: { turbo_method: :delete } %> + <%= link_to t('blacklight.header_links.logout'), destroy_user_session_url, method: :delete, data: { turbo_method: :delete } %>
  • <% unless current_user.to_s.blank? %>
  • diff --git a/spec/features/active_link_spec.rb b/spec/features/active_link_spec.rb index 2322ad4..a8d17f6 100644 --- a/spec/features/active_link_spec.rb +++ b/spec/features/active_link_spec.rb @@ -25,13 +25,11 @@ click_link "Login" expect(page).to have_content("Login") - fill_in "user_username", with: "bltest" - fill_in "user_password", with: "test" - click_button "Login" + click_button "Patron Login" visit account_path - expect(page).to have_css("a.active", text: "blacklight test") + expect(page).to have_css("a.active", text: "Blacklight Test") end end end diff --git a/spec/features/logout_spec.rb b/spec/features/logout_spec.rb deleted file mode 100644 index f54bb1d..0000000 --- a/spec/features/logout_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_state_literal: true - -require "rails_helper" - -RSpec.describe "Logout" do - before do - # rubocop:disable RSpec/AnyInstance - allow_any_instance_of(PatronHelper).to receive(:user_location).and_return(:offsite) - # rubocop:enable RSpec/AnyInstance - end - - it "destroys the user session" do - visit new_user_session_path - fill_in "user_username", with: "bltest" - fill_in "user_password", with: "test" - click_button "Login" - - visit root_path - click_link "Log Out" - - expect(page).to have_content(I18n.t("devise.sessions.signed_out")) - expect(page).not_to have_content("blacklight test") - end -end diff --git a/spec/files/auth/auth_hash.json b/spec/files/auth/auth_hash.json index 1babc18..81198d4 100644 --- a/spec/files/auth/auth_hash.json +++ b/spec/files/auth/auth_hash.json @@ -2,28 +2,28 @@ "provider": "keycloakopenid", "uid": "603e26dd-b2d4-4a88-ad9d-406eaec31463", "info": { - "name": "Staff User", - "email": "staff@nla.gov.au", - "first_name": "Staff", - "last_name": "User" + "name": "Blacklight Test", + "email": "test@example.com", + "first_name": "Blacklight", + "last_name": "Test" }, "credentials": { - "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImYyZjVmYjc3OWY4YjhhNjM2NDVlYjcxMTEzOWJhN2VhIn0.eyJleHAiOjE2NzM4NDAyOTYsImlhdCI6MTY3MzgzNjY5NiwiYXV0aF90aW1lIjoxNjczODM2Njk2LCJqdGkiOiI4ZGJmMDg4NS1kNzI3LTQ1YzQtODYwYS05ODE2YWUxOWZmNWYiLCJpc3MiOiJodHRwczovL2xvZ2luLmV4YW1wbGUuY29tL2F1dGgvcmVhbG1zL2V4YW1wbGUiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiZjVhZmFkODEtMDZjNC00OWE2LTgyN2UtMmVmMmRkM2I4ZmRhIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiY2F0YWxvZ3VlIiwic2Vzc2lvbl9zdGF0ZSI6IjgwMjQyNDYwLWVlMjEtNGUyYy1iZmY2LTNjZmM1M2JjOGVmYiIsImFsbG93ZWQtb3JpZ2lucyI6WyJsb2NhbGhvc3QiLCIwLjAuMC4wIiwiY2F0YWxvZ3VlLm5sYS5nb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ZjNTNiYzhlZmIiLCJzY29wZSI6InByb2ZpbGUgZW1haWwgcm9sZXMiLCJzaWQiOiI4MDI0MjQ2MC1lZTIxLTRlMmMtYmZmNi0zY2ZjNTNiYzhlZmIifQ.q_P4zHKyeEHnhlu0FFENX9c6n_YimkaokX7AV9MC-Ag", - "expires_at": 1673840296, + "expires_at": 1728943716, "expires": true }, "extra": { "raw_info": { - "exp": 1673840296, - "iat": 1673836696, + "exp": 1728943716, + "iat": 1697407716, "auth_time": 1673836696, "jti": "8dbf0885-d727-45c4-860a-9816ae19ff5f", - "iss": "https://login.example.com/auth/realms/staff", + "iss": "https://login.example.com/auth/realms/example", "aud": "account", "sub": "603e26dd-b2d4-4a88-ad9d-406eaec31463", "typ": "Bearer", - "azp": "catalogue", + "azp": "join-us", "session_state": "80242460-ee21-4e2c-bff6-3cfc53bc8efb", "allowed-origins": [ "localhost", @@ -52,11 +52,11 @@ "offline_access", "uma_authorization" ], - "name": "Staff User", - "preferred_username": "staff", - "given_name": "Staff", - "family_name": "User", - "email": "staff@nla.gov.au" + "name": "Blacklight Test", + "preferred_username": "c202a7d5-3d30-411a-b0a7-53753801bf98", + "given_name": "Blacklight", + "family_name": "Test", + "email": "test@example.com" }, "id_token": null } diff --git a/spec/simplecov_helper.rb b/spec/simplecov_helper.rb index 19e769d..dfeb33b 100644 --- a/spec/simplecov_helper.rb +++ b/spec/simplecov_helper.rb @@ -23,4 +23,6 @@ # these will be removed soon add_filter "lib/devise/models/getalibrarycard_authenticatable.rb" add_filter "lib/devise/strategies/getalibrarycard_authenticatable.rb" + add_filter "lib/devise/models/user_reg_authenticatable.rb" + add_filter "lib/devise/strategies/user_reg_authenticatable.rb" end diff --git a/spec/support/omniauth.rb b/spec/support/omniauth.rb new file mode 100644 index 0000000..14ec3fd --- /dev/null +++ b/spec/support/omniauth.rb @@ -0,0 +1,9 @@ +require "omniauth" + +OmniAuth.config.test_mode = true + +RSpec.configure do |config| + config.before do + OmniAuth.config.add_mock(:catalogue_patron, JSON.parse(IO.read("spec/files/auth/auth_hash.json"))) + end +end