From e9bc91a0b9e68070cbf0023ebfae60c6b452f80a Mon Sep 17 00:00:00 2001 From: AbigailMcP Date: Thu, 20 Jun 2024 14:34:47 +0100 Subject: [PATCH] CAPT-1702 Add smoke test (#2875) * Add smoke test * Run in workflow * Update rspec command to not run smoke tests automatically --- .github/workflows/build_and_deploy.yml | 17 ++++++++++++++++- Gemfile | 2 ++ Gemfile.lock | 3 +++ spec/rails_helper.rb | 19 ++++++++++++------- spec/smoke/start_a_claim_spec.rb | 24 ++++++++++++++++++++++++ spec/support/capybara.rb | 10 ++++++++++ 6 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 spec/smoke/start_a_claim_spec.rb diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 158bf2baa2..16b12afb4b 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -114,7 +114,22 @@ jobs: make ci test-aks get-cluster-credentials kubectl exec -n srtl-test deployment/claim-additional-payments-for-teaching-test-worker -- sh -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bin/prepare-database" - - name: Slack notification + - name: Install Ruby 3.2.4 + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: 3.2.4 + + - name: Run smoke tests + shell: bash + run: bundle exec rspec spec/smoke -t smoke:true -b + env: + RAILS_ENV: test + SMOKE_TEST_APP_HOST: ${{ env.APP_URL }} + BASIC_AUTH_USERNAME: ${{ secrets.BASIC_AUTH_USERNAME }} + BASIC_AUTH_PASSWORD: ${{ secrets.BASIC_AUTH_PASSWORD }} + + - name: Notify on failure if: failure() uses: rtCamp/action-slack-notify@master env: diff --git a/Gemfile b/Gemfile index d2c52351c5..8fb7666f47 100644 --- a/Gemfile +++ b/Gemfile @@ -124,6 +124,8 @@ group :test do gem "launchy" gem "rack_session_access" gem "simplecov", require: false + # Return null object for active record connection rather than raising error + gem "activerecord-nulldb-adapter" end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 70444a0a99..be9e96cf8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,6 +73,8 @@ GEM activesupport (= 7.0.8.4) activerecord-copy (1.1.0) activerecord (>= 3.1) + activerecord-nulldb-adapter (1.0.1) + activerecord (>= 5.2.0, < 7.2) activestorage (7.0.8.4) actionpack (= 7.0.8.4) activejob (= 7.0.8.4) @@ -552,6 +554,7 @@ PLATFORMS DEPENDENCIES activerecord-copy + activerecord-nulldb-adapter application_insights! bootsnap (>= 1.1.0) brakeman diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index b85a68f593..8256c112ff 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -22,13 +22,17 @@ # 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. -begin - ActiveRecord::Migration.maintain_test_schema! -rescue ActiveRecord::PendingMigrationError => e - puts e.to_s.strip - exit 1 +if ENV["SMOKE_TEST_APP_HOST"].present? + ActiveRecord::Base.establish_connection adapter: :nulldb +else + # Checks for pending migrations and applies them before tests are run. + # If you are not using ActiveRecord, you can remove these lines. + begin + ActiveRecord::Migration.maintain_test_schema! + rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 + end end RSpec.configure do |config| @@ -82,6 +86,7 @@ OmniAuth.config.mock_auth[:default] = nil end + config.filter_run_excluding :smoke config.filter_run_excluding flaky: true unless ENV["RUN_FLAKY_SPECS"] == "true" config.filter_run_excluding js: true unless ENV["RUN_JS_SPECS"] == "true" config.filter_run_excluding slow: true unless ENV["RUN_SLOW_SPECS"] == "true" diff --git a/spec/smoke/start_a_claim_spec.rb b/spec/smoke/start_a_claim_spec.rb new file mode 100644 index 0000000000..f334c41f75 --- /dev/null +++ b/spec/smoke/start_a_claim_spec.rb @@ -0,0 +1,24 @@ +require "rails_helper" + +RSpec.describe "Start a claim", :smoke, type: :feature do + # To test this locally you will need to add to your .env file: + # + # SMOKE_TEST_APP_HOST + # BASIC_AUTH_USERNAME + # BASIC_AUTH_PASSWORD + + scenario "User starts a claim" do + visit url_with_basic_auth + expect(page).to have_text("Teachers: claim back your student loan repayments") + end + + def url_with_basic_auth + host = ENV.fetch("SMOKE_TEST_APP_HOST") + path = new_claim_path(Journeys::TeacherStudentLoanReimbursement::ROUTING_NAME) + uri = URI.join(host, path) + + uri.user = ENV.fetch("BASIC_AUTH_USERNAME", nil) + uri.password = ENV.fetch("BASIC_AUTH_PASSWORD", nil) + uri.to_s + end +end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 8c3c34aac2..fc7a14e45e 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -27,3 +27,13 @@ end Capybara.automatic_label_click = true + +RSpec.configure do |config| + config.around(:each, :smoke) do |example| + Capybara.current_driver = Capybara.javascript_driver + Capybara.run_server = false + example.run + Capybara.run_server = true + Capybara.current_driver = Capybara.default_driver + end +end