Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow uses actions that are not certified by GitHub. They are
# provided by a third-party and are governed by separate terms of service,
# privacy policy, and support documentation.
#
# This workflow will install a prebuilt Ruby version, install dependencies, and
# run linters.

name: "Lint"

on:
push:
branches: [main]
pull_request:
branches: [main]
merge_group:
types: [checks_requested]
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Add or replace dependency steps here
- name: Install Ruby and gems
# The ruby version is taken from the .ruby-version file, no need to specify here.
uses: ruby/setup-ruby@354a1ad156761f5ee2b7b13fa8e09943a5e8d252 # v1.229.0
with:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
# Add or replace any other lints here
- name: Lint Ruby files
run: bundle exec rubocop --parallel
22 changes: 22 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .rubocop.yml
inherit_gem:
rubocop-govuk:
- config/default.yml
- config/rails.yml
- config/rspec.yml

inherit_mode:
merge:
- Exclude

# **************************************************************
# TRY NOT TO ADD OVERRIDES IN THIS FILE
#
# This repo is configured to follow the RuboCop GOV.UK styleguide.
# Any rules you override here will cause this repo to diverge from
# the way we write code in all other GOV.UK repos.
#
# See https://github.com/alphagov/rubocop-govuk/blob/main/CONTRIBUTING.md
# **************************************************************


7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ source "https://rubygems.org"

ruby file: ".ruby-version"

gem "debug"
gem "rspec"
gem "aws-sdk-s3", "~> 1.183"
gem "capybara"
gem "debug"
gem "notifications-ruby-client"
gem "rspec"
gem "selenium-webdriver"
gem "webdrivers"
gem "aws-sdk-s3", "~> 1.183"

group :development, :test do
gem "rake"
gem "rubocop-govuk", require: false
end
68 changes: 68 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (8.0.2)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.3)
aws-eventstream (1.3.2)
aws-partitions (1.1086.0)
aws-sdk-core (3.222.1)
Expand All @@ -22,6 +36,8 @@ GEM
aws-sigv4 (1.11.0)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.9)
capybara (3.40.0)
addressable
matrix
Expand All @@ -31,22 +47,30 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.3.5)
connection_pool (2.5.2)
date (3.4.1)
debug (1.10.0)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.1)
drb (2.2.1)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
io-console (0.8.0)
irb (1.14.3)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jmespath (1.6.2)
json (2.11.3)
jwt (2.8.2)
base64
language_server-protocol (3.17.0.4)
logger (1.6.6)
matrix (0.4.2)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.5)
nokogiri (1.18.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
Expand All @@ -62,6 +86,10 @@ GEM
racc (~> 1.4)
notifications-ruby-client (6.2.0)
jwt (>= 1.5, < 3)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
psych (5.2.2)
date
stringio
Expand All @@ -70,6 +98,7 @@ GEM
rack (3.0.14)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.10.0)
psych (>= 4.0.0)
Expand All @@ -90,14 +119,52 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.0)
rubocop (1.69.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.36.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-govuk (5.0.4)
rubocop (= 1.69.0)
rubocop-ast (= 1.36.2)
rubocop-capybara (= 2.21.0)
rubocop-rails (= 2.27.0)
rubocop-rake (= 0.6.0)
rubocop-rspec (= 3.2.0)
rubocop-rails (2.27.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.2.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
rubyzip (2.4.1)
securerandom (0.4.1)
selenium-webdriver (4.30.1)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
stringio (3.1.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.3)
webdrivers (5.2.0)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
Expand All @@ -121,6 +188,7 @@ DEPENDENCIES
notifications-ruby-client
rake
rspec
rubocop-govuk
selenium-webdriver
webdrivers

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RSpec::Core::RakeTask.new(:end_to_end) do |task|
ENV["FORMS_ADMIN_URL"] ||= "http://localhost:3000/"
ENV["PRODUCT_PAGES_URL"] ||= "http://localhost:3002/"

task.pattern = %[spec/end_to_end]
task.pattern = %(spec/end_to_end)
task.verbose = false
end

Expand Down
6 changes: 3 additions & 3 deletions services/notify_service.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'notifications/client'
require "notifications/client"

class NotifyService
def initialize
@notify_api_key = ENV["SETTINGS__GOVUK_NOTIFY__API_KEY"]
end

def get_email(notification_id)
if @notify_api_key.nil? || @notify_api_key.empty?
if @notify_api_key.blank?
raise "You must set SETTINGS__GOVUK_NOTIFY__API_KEY"
end

client = Notifications::Client.new(@notify_api_key)
client.get_notifications({reference: notification_id })
client.get_notifications({ reference: notification_id })
end
end
30 changes: 15 additions & 15 deletions spec/end_to_end/end_to_end_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
feature "Full lifecycle of a form", type: :feature do
let(:test_email_address) { "govuk-forms-automation-tests@digital.cabinet-office.gov.uk" }
let(:form_name) { "capybara test form #{Time.now().strftime("%Y-%m-%d %H:%M.%S")}" }
let(:form_name) { "capybara test form #{Time.zone.now.strftime('%Y-%m-%d %H:%M.%S')}" }
let(:selection_question) { "Do you want to remain anonymous?" }
let(:question_text) { "What is your name?" }

Expand All @@ -21,33 +21,33 @@
logger.info
logger.info "Scenario: Form is created, made live by form admin user"

unless bypass_end_to_end_tests('forms-admin', '/')
unless bypass_end_to_end_tests("forms-admin", "/")
start_tracing

build_a_new_form

logger.info("Then I can share the live form")
live_form_link = page.find('[data-copy-target]').text
live_form_link = page.find("[data-copy-target]").text

unless bypass_end_to_end_tests('forms-runner', live_form_link)
unless bypass_end_to_end_tests("forms-runner", live_form_link)
# Testing alternate routes (basic routing with a skip question)
logger.info "Scenario: Form is completed by a member of the public, and they answer all questions"
form_is_filled_in_by_form_filler(live_form_link, skip_question: false)
expect(form_is_filled_in_by_form_filler(live_form_link, skip_question: false)).to be true

logger.info
logger.info "Scenario: Form is completed by a member of the public, and they use a route that skips questions"
form_is_filled_in_by_form_filler(live_form_link, skip_question: true)
expect(form_is_filled_in_by_form_filler(live_form_link, skip_question: true)).to be true

# Testing confirmation email
logger.info
logger.info "Scenario: Form is completed by a member of the public, and they request a confirmation email"
form_is_filled_in_by_form_filler(live_form_link, confirmation_email: test_email_address)
expect(form_is_filled_in_by_form_filler(live_form_link, confirmation_email: test_email_address)).to be true

unless ENV.fetch('SKIP_S3', false)
unless ENV.fetch("SKIP_S3", false)
# Testing s3 submission
logger.info
logger.info "Scenario: Form is completed by a member of the public, and answers are sent to s3"
s3_form_is_filled_in_by_form_filler()
expect(s3_form_is_filled_in_by_form_filler).to be true
end
end

Expand All @@ -57,13 +57,13 @@
end
end

unless ENV.fetch('SKIP_FILE_UPLOAD', false)
unless ENV.fetch("SKIP_FILE_UPLOAD", false)
context "when the form has a file upload question" do
let(:form_name) { "capybara test file upload form #{Time.now().strftime("%Y-%m-%d %H:%M.%S")}" }
let(:form_name) { "capybara test file upload form #{Time.zone.now.strftime('%Y-%m-%d %H:%M.%S')}" }
let(:file_question_text) { "Upload a file" }
let(:test_file) { "/tmp/temp-file.txt" }
let (:status_api_response) {}
let (:submission_reference) {}
let(:status_api_response) {}
let(:submission_reference) {}

before do
File.write(test_file, "Hello file")
Expand All @@ -78,10 +78,10 @@

build_a_new_form_with_file_upload

live_form_link = page.find('[data-copy-target]').text
live_form_link = page.find("[data-copy-target]").text
upload_file_and_submit(live_form_link)

check_submission
expect(check_submission).to be true

visit_admin
visit_end_to_end_tests_group
Expand Down
28 changes: 14 additions & 14 deletions spec/smoke_tests/smoke_test_runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

feature 'Runner Smoke Test', type: :feature do
feature "Runner Smoke Test", type: :feature do
let(:smoke_test_form_url) do
ENV.fetch('SMOKE_TEST_FORM_URL') { raise 'You must set $SMOKE_TEST_FORM_URL' }
ENV.fetch("SMOKE_TEST_FORM_URL") { raise "You must set $SMOKE_TEST_FORM_URL" }
end

before do
Capybara.app_host = smoke_test_form_url
end

scenario 'Complete and submit an existing form' do
scenario "Complete and submit an existing form" do
logger.info "Visiting #{smoke_test_form_url}"
visit smoke_test_form_url

Expand All @@ -20,23 +20,23 @@
current_page = page.current_url
logger.info "#{current_page} answering question: #{question_number}"

question_type = page.first('input')[:name]
fill_in(class: 'govuk-input', with: answer_for(question_type))
click_button 'Continue'
question_type = page.first("input")[:name]
fill_in(class: "govuk-input", with: answer_for(question_type))
click_button "Continue"

expect(page).to have_no_content('There is a problem')
expect(page).to have_no_content("There is a problem")
expect(page.current_url).not_to eq(current_page), "On the same page after clicking 'Continue'"

question_number += 1
end

logger.info 'Confirming answers'
expect(page).to have_content('Check your answers before submitting your form')
logger.info "Confirming answers"
expect(page).to have_content("Check your answers before submitting your form")

choose 'No', visible: false
click_button 'Submit'
logger.info 'Submitted answers'
expect(page).to have_content('Your form has been submitted')
logger.info 'Test complete'
choose "No", visible: false
click_button "Submit"
logger.info "Submitted answers"
expect(page).to have_content("Your form has been submitted")
logger.info "Test complete"
end
end
Loading