Skip to content

Commit

Permalink
RST-2548 API home office number (#1061)
Browse files Browse the repository at this point in the history
* Home office number to online applicaiton table

* Updating validation for ni_number

when the online application is created

* Removing the mandatory flag fo Ni number

at the online_application table so we can use ho_number instead.

* Rubocop fix
  • Loading branch information
zaparka authored Mar 30, 2020
1 parent 43d6baf commit b5044a0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def public_app_params
:case_number,
:form_name,
:ni_number,
:ho_number,
:date_of_birth,
:title,
:first_name,
Expand Down
4 changes: 3 additions & 1 deletion app/models/online_application.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class OnlineApplication < ActiveRecord::Base
belongs_to :jurisdiction, optional: true

validates :ni_number, :date_of_birth, :first_name, :last_name, :address,
validates :date_of_birth, :first_name, :last_name, :address,
:postcode, presence: true
validates :married, :min_threshold_exceeded, :benefits, :refund, :email_contact,
:phone_contact, :post_contact, :feedback_opt_in, inclusion: [true, false]
validates :reference, uniqueness: true

validates :ni_number, presence: true, if: ->(app) { app.ho_number.blank? }

def full_name
[title, first_name, last_name].compact.join(' ')
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHoNumberToOnlineApplication < ActiveRecord::Migration[5.2]
def change
add_column :online_applications, :ho_number, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveMandatoryFlagForNiNumberFromOnlineApplication < ActiveRecord::Migration[5.2]
def up
change_column_null :online_applications, :ni_number, :true
end
end
7 changes: 5 additions & 2 deletions 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.define(version: 2020_02_27_115846) do
ActiveRecord::Schema.define(version: 2020_03_25_110607) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -26,6 +26,7 @@
t.boolean "married"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "litigation_friend_details"
t.index ["application_id"], name: "index_applicants_on_application_id"
t.index ["first_name"], name: "index_applicants_on_first_name"
t.index ["last_name"], name: "index_applicants_on_last_name"
Expand Down Expand Up @@ -260,7 +261,7 @@
t.date "date_of_death"
t.string "case_number"
t.string "form_name"
t.string "ni_number", null: false
t.string "ni_number"
t.date "date_of_birth", null: false
t.string "title"
t.string "first_name", null: false
Expand All @@ -287,6 +288,8 @@
t.boolean "income_max_threshold_exceeded"
t.string "fee_manager_firstname"
t.string "fee_manager_lastname"
t.text "litigation_friend_details"
t.string "ho_number"
t.index ["jurisdiction_id"], name: "index_online_applications_on_jurisdiction_id"
t.index ["reference"], name: "index_online_applications_on_reference", unique: true
end
Expand Down
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#Define global variables
ENV['zap_proxy'] = "localhost"
ENV['zap_proxy_port'] = '8099'
ENV['HOSTNAME'] = 'localhost'

#Below lines are our driver profile settings to reach internet through a proxy
#You can set security=true as environment variable or declare it on command window
Expand Down
27 changes: 26 additions & 1 deletion spec/models/online_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
RSpec.describe OnlineApplication, type: :model do
subject(:online_application) { build :online_application }

it { is_expected.to validate_presence_of(:ni_number) }
it { is_expected.to validate_presence_of(:date_of_birth) }
it { is_expected.to validate_presence_of(:first_name) }
it { is_expected.to validate_presence_of(:last_name) }
Expand All @@ -23,6 +22,32 @@

it { is_expected.to validate_uniqueness_of(:reference) }

describe '#ni_number validation' do
context 'ho_number and ni_number is empty' do
before { online_application.ni_number = nil }

it { is_expected.not_to be_valid }
end

context 'ho_number has a value and ni_number is empty' do
before do
online_application.ni_number = nil
online_application.ho_number = 'L123456'
end

it { is_expected.to be_valid }
end

context 'ho_number in empty and ni_number is is valid' do
before do
online_application.ni_number = 'SN123456C'
online_application.ho_number = nil
end

it { is_expected.to be_valid }
end
end

describe '#full_name' do
subject { online_application.full_name }

Expand Down

0 comments on commit b5044a0

Please sign in to comment.