Skip to content

Commit

Permalink
CAPT-1702 Add smoke test (#2875)
Browse files Browse the repository at this point in the history
* Add smoke test
* Run in workflow
* Update rspec command to not run smoke tests automatically
  • Loading branch information
AbigailMcP committed Jun 21, 2024
1 parent aeb2723 commit e9bc91a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -552,6 +554,7 @@ PLATFORMS

DEPENDENCIES
activerecord-copy
activerecord-nulldb-adapter
application_insights!
bootsnap (>= 1.1.0)
brakeman
Expand Down
19 changes: 12 additions & 7 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions spec/smoke/start_a_claim_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e9bc91a

Please sign in to comment.