Skip to content

Commit

Permalink
Add the passport number screen
Browse files Browse the repository at this point in the history
Adds a screen for the passport number. Again like, the nationality, this
is a question we show in the personal details part of the journey but we
store it on the eligiblity, as this is the only journey that asks this
question and the claim is shared with all journeys.
  • Loading branch information
rjlynch committed Jun 26, 2024
1 parent 0d76fa9 commit 02e7bab
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Journeys
module GetATeacherRelocationPayment
class PassportNumberForm < Form
attribute :passport_number, :string

validates :passport_number, presence: {
message: i18n_error_message(:presence)
}

validates :passport_number, format: {
with: /\A[a-zA-Z0-9]{1,20}\z/,
message: i18n_error_message(:invalid)
}, if: :passport_number

def save
return false unless valid?

journey_session.answers.assign_attributes(
passport_number: passport_number
)

journey_session.save!
end
end
end
end
3 changes: 2 additions & 1 deletion app/models/journeys/get_a_teacher_relocation_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module GetATeacherRelocationPayment
"subject" => SubjectForm,
"visa" => VisaForm,
"entry-date" => EntryDateForm,
"nationality" => NationalityForm
"nationality" => NationalityForm,
"passport-number" => PassportNumberForm
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def eligibility_answers
def identity_answers
super.tap do |a|
a << nationality
a << passport_number
end
end

Expand Down Expand Up @@ -86,6 +87,14 @@ def nationality
"nationality"
]
end

def passport_number
[
t("get_a_teacher_relocation_payment.forms.passport_number.question"),
answers.passport_number,
"passport-number"
]
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SessionAnswers < Journeys::SessionAnswers
attribute :visa_type, :string
attribute :date_of_entry, :date
attribute :nationality, :string
attribute :passport_number, :string
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SlugSequence

PERSONAL_DETAILS_SLUGS = [
"nationality",
"passport-number"
]

RESULTS_SLUGS = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<% content_for(
:page_title,
page_title(
t("get_a_teacher_relocation_payment.forms.passport_number.question"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for(
@form,
url: claim_path(current_journey_routing_name),
builder: GOVUKDesignSystemFormBuilder::FormBuilder
) do |f| %>
<%= f.govuk_error_summary %>

<%= f.govuk_text_field(
:passport_number,
label: {
text: t("get_a_teacher_relocation_payment.forms.passport_number.question"),
size: "l"
},
) %>

<%= f.govuk_submit %>
<% end %>
</div>
</div>

2 changes: 2 additions & 0 deletions config/analytics_blocklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@
- created_at
- updated_at
- gender_digit
:international_relocation_payments_eligibilities:
- passport_number

5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ en:
question: "Select your nationality"
errors:
inclusion: "Choose your nationality"
passport_number:
question: "Enter your passport number, as it appears on your passport"
errors:
presence: "Enter your passport number"
invalid: "Invalid passport number"


check_your_answers:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPassportNumberToInternationalRelocationPaymentsEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :international_relocation_payments_eligibilities, :passport_number, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_06_24_102011) do
ActiveRecord::Schema[7.0].define(version: 2024_06_24_105924) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -196,6 +196,7 @@
t.string "visa_type"
t.date "date_of_entry"
t.string "nationality"
t.string "passport_number"
end

create_table "journey_configurations", primary_key: "routing_name", id: :string, force: :cascade do |t|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
nationality { "Australian" }
end

trait :with_passport_number do
passport_number { "1234567890123456789A" }
end

trait :with_email_details do
email_address { generate(:email_address) }
email_verified { true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
then_the_check_your_answers_part_one_page_shows_my_answers
and_i_dont_change_my_answers
and_i_complete_the_nationality_step_with(option: "Australian")
and_i_complete_the_passport_number_step_with(options: "123456789")
and_the_personal_details_section_has_been_temporarily_stubbed
then_the_check_your_answers_part_page_shows_my_answers
and_i_submit_the_application
Expand Down Expand Up @@ -77,5 +78,9 @@ def then_the_check_your_answers_part_one_page_shows_my_answers

def then_the_check_your_answers_part_page_shows_my_answers
expect(page).to have_text("Select your nationality Australian")

expect(page).to have_text(
"Enter your passport number, as it appears on your passport 123456789"
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require "rails_helper"

RSpec.describe Journeys::GetATeacherRelocationPayment::PassportNumberForm, type: :model do
let(:journey_session) { create(:get_a_teacher_relocation_payment_session) }

let(:params) do
ActionController::Parameters.new(
claim: {
passport_number: option
}
)
end

let(:option) { nil }

let(:form) do
described_class.new(
journey_session: journey_session,
journey: Journeys::GetATeacherRelocationPayment,
params: params
)
end

describe "validations" do
subject { form }

it do
is_expected.to(
validate_presence_of(:passport_number)
.with_message("Enter your passport number")
)
end

# Passport number contains non alphanumeric characters
it do
is_expected.not_to(
allow_value("123456789012345$")
.for(:passport_number)
.with_message("Invalid passport number")
)
end

# Passport number at max allowed length
it do
is_expected.to(
allow_value("1234567890ABCDEfghij").for(:passport_number)
)
end

# Passport number too long
it do
is_expected.not_to(
allow_value("12345678901234567890A")
.for(:passport_number)
.with_message("Invalid passport number")
)
end
end

describe "#save" do
let(:option) { "123456789012345" }

it "updates the journey session" do
expect { expect(form.save).to be(true) }.to(
change { journey_session.reload.answers.passport_number }
.to("123456789012345")
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
let(:answers) do
build(
:get_a_teacher_relocation_payment_answers,
:with_nationality
:with_nationality,
:with_passport_number
)
end

Expand All @@ -81,6 +82,11 @@
"Select your nationality",
"Australian",
"nationality"
],
[
"Enter your passport number, as it appears on your passport",
"1234567890123456789A",
"passport-number"
]
)
end
Expand Down
17 changes: 17 additions & 0 deletions spec/support/get_a_teacher_relocation_payment/step_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ def and_i_complete_the_nationality_step_with(option:)
click_button("Continue")
end

def and_i_complete_the_passport_number_step_with(options:)
assert_on_passport_number_page!

fill_in(
"Enter your passport number, as it appears on your passport",
with: options
)

click_button("Continue")
end

def then_the_application_is_submitted_successfully
assert_application_is_submitted!
end
Expand Down Expand Up @@ -151,6 +162,12 @@ def assert_on_nationality_page!
expect(page).to have_text("Select your nationality")
end

def assert_on_passport_number_page!
expect(page).to have_text(
"Enter your passport number, as it appears on your passport"
)
end

def assert_application_is_submitted!
expect(page).to have_content("Claim submitted")
expect(page).to have_content(
Expand Down

0 comments on commit 02e7bab

Please sign in to comment.