Browse Source

CLDC-2057 Telephone number confirmation (#1595)

* CLDC-2057 Merge request: ask to confirm number

* address comments
pull/1601/head
Jack 2 years ago committed by GitHub
parent
commit
751f8661db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      app/controllers/merge_requests_controller.rb
  2. 7
      app/views/merge_requests/absorbing_organisation.html.erb
  3. 23
      app/views/merge_requests/confirm_telephone_number.html.erb
  4. 8
      app/views/merge_requests/merge_date.html.erb
  5. 4
      app/views/merge_requests/organisations.html.erb
  6. 2
      config/locales/en.yml
  7. 1
      config/routes.rb
  8. 6
      db/migrate/20230427130334_add_phone_number_to_merge_request.rb
  9. 4
      db/schema.rb
  10. 144
      spec/requests/merge_requests_controller_spec.rb

26
app/controllers/merge_requests_controller.rb

@ -7,6 +7,7 @@ class MergeRequestsController < ApplicationController
absorbing_organisation
confirm_telephone_number
new_org_name
merge_date
]
before_action :authenticate_user!
before_action :authenticate_scope!, except: [:create]
@ -15,6 +16,7 @@ class MergeRequestsController < ApplicationController
def absorbing_organisation; end
def confirm_telephone_number; end
def new_org_name; end
def merge_date; end
def create
ActiveRecord::Base.transaction do
@ -70,6 +72,8 @@ private
end
when "organisations"
absorbing_organisation_merge_request_path(@merge_request)
when "confirm_telephone_number"
merge_date_merge_request_path(@merge_request)
end
end
@ -96,6 +100,8 @@ private
:other_merging_organisations,
:status,
:absorbing_organisation_id,
:telephone_number_correct,
:new_telephone_number,
)
if merge_params[:requesting_organisation_id].present? && (current_user.data_coordinator? || current_user.data_provider?)
@ -111,13 +117,31 @@ private
end
end
if merge_params[:telephone_number_correct] == "1"
merge_params[:new_telephone_number] = nil
end
merge_params
end
def validate_response
if page == "absorbing_organisation" && merge_request_params[:absorbing_organisation_id].blank? && merge_request_params[:new_absorbing_organisation].blank?
@merge_request.errors.add(:absorbing_organisation_id, I18n.t("validations.merge_request.absorbing_organisation_blank"))
render previous_template
render previous_template, status: :unprocessable_entity
end
if page == "confirm_telephone_number"
if merge_request_params[:telephone_number_correct].blank? && merge_request_params[:new_telephone_number].blank?
if @merge_request.absorbing_organisation.phone.present?
@merge_request.errors.add(:telephone_number_correct, I18n.t("validations.merge_request.telephone_number_correct_blank"))
else
@merge_request.errors.add(:telephone_number_correct, I18n.t("validations.merge_request.new_telephone_number_blank"))
end
render previous_template, status: :unprocessable_entity
elsif merge_request_params[:telephone_number_correct] == "0" && merge_request_params[:new_telephone_number].blank?
@merge_request.errors.add(:new_telephone_number, I18n.t("validations.merge_request.new_telephone_number_blank"))
render previous_template, status: :unprocessable_entity
end
end
end

7
app/views/merge_requests/absorbing_organisation.html.erb

@ -4,15 +4,14 @@
<%= govuk_back_link href: organisations_merge_request_path(id: @merge_request) %>
<% end %>
<h2 class="govuk-heading-l">Which organisation is absorbing the others?</h2>
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<h2 class="govuk-heading-l">Which organisation is absorbing the others?</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<p class="govuk-body">Select the organisation that the other organisations are merging into.</p>
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset(
:absorbing_organisation_id,
hint: { text: "For example, if Skype and Yammer merged into Microsoft, you would select Microsoft." },

23
app/views/merge_requests/confirm_telephone_number.html.erb

@ -4,10 +4,33 @@
<%= govuk_back_link href: absorbing_organisation_merge_request_path(id: @merge_request) %>
<% end %>
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<h2 class="govuk-heading-l">What is <%= @merge_request.absorbing_organisation.name %>'s telephone number?</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<% if @merge_request.absorbing_organisation.phone.present? %>
<p class="govuk-body">Confirm the telephone number on file, or enter a new one.</p>
<div class="govuk-inset-text">
<%= @merge_request.absorbing_organisation.phone %>
</div>
<% end %>
<% if @merge_request.absorbing_organisation.phone.present? %>
<%= f.govuk_radio_buttons_fieldset(:telephone_number_correct, legend: nil) do %>
<%= f.govuk_radio_button :telephone_number_correct, 1, checked: @merge_request.telephone_number_correct?, label: { text: "This telephone number is correct" }, link_errors: true %>
<%= f.govuk_radio_button :telephone_number_correct, 0, checked: @merge_request.new_telephone_number.present?, label: { text: "Enter a new phone number" } do %>
<%= f.govuk_text_field :new_telephone_number, label: { text: "Telephone number" }, width: "two-thirds" %>
<% end %>
<%= f.hidden_field :page, value: "confirm_telephone_number" %>
<% end %>
<% else %>
<%= f.govuk_text_field :new_telephone_number, label: nil, width: "two-thirds" %>
<%= f.hidden_field :page, value: "confirm_telephone_number" %>
<% end %>
<%= f.govuk_submit %>
<% end %>
</div>
</div>

8
app/views/merge_requests/merge_date.html.erb

@ -0,0 +1,8 @@
<% content_for :before_content do %>
<% title = "Tell us if your organisation is merging" %>
<% content_for :title, title %>
<%# TODO: Update this backlink to also work with the create org flow %>
<%= govuk_back_link href: confirm_telephone_number_merge_request_path(@merge_request) %>
<% end %>
<h2 class="govuk-heading-l">What is the merge date?</h2>

4
app/views/merge_requests/organisations.html.erb

@ -4,6 +4,8 @@
<%= govuk_back_link href: merge_request_organisation_path(id: @merge_request.requesting_organisation_id) %>
<% end %>
<%= form_with model: @merge_request, url: organisations_merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<h2 class="govuk-heading-l">Which organisations are merging?</h2>
<div class="govuk-grid-row">
@ -12,8 +14,6 @@
Add all organisations to be merged - we have already added your own.
</p>
<%= form_with model: @merge_request, url: organisations_merge_request_path, method: :patch do |f| %>
<%= f.govuk_error_summary %>
<p class="govuk-body">Start typing to search</p>
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
field: :merging_organisation,

2
config/locales/en.yml

@ -513,6 +513,8 @@ en:
organisation_part_of_another_merge: "This organisation is part of another merge - select a different one"
organisation_not_selected: "Select an organisation from the search list"
absorbing_organisation_blank: Select the organisation absorbing the others
telephone_number_correct_blank: Select to confirm or enter a new telephone number
new_telephone_number_blank: Enter a valid telephone number
soft_validations:
net_income:

1
config/routes.rb

@ -139,6 +139,7 @@ Rails.application.routes.draw do
get "absorbing-organisation"
get "confirm-telephone-number"
get "new-org-name"
get "merge-date"
end
end

6
db/migrate/20230427130334_add_phone_number_to_merge_request.rb

@ -0,0 +1,6 @@
class AddPhoneNumberToMergeRequest < ActiveRecord::Migration[7.0]
change_table :merge_requests, bulk: true do |t|
t.column :telephone_number_correct, :boolean
t.column :new_telephone_number, :string
end
end

4
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_04_21_124536) do
ActiveRecord::Schema[7.0].define(version: 2023_04_27_130334) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -369,6 +369,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_21_124536) do
t.integer "status"
t.integer "absorbing_organisation_id"
t.boolean "new_absorbing_organisation"
t.boolean "telephone_number_correct"
t.string "new_telephone_number"
end
create_table "organisation_relationships", force: :cascade do |t|

144
spec/requests/merge_requests_controller_spec.rb

@ -233,6 +233,38 @@ RSpec.describe MergeRequestsController, type: :request do
end
end
describe "#confirm_telephone_number" do
let(:merge_request) do
MergeRequest.create!(
absorbing_organisation: create(:organisation, phone: phone_number),
requesting_organisation: organisation,
)
end
before { get "/merge-request/#{merge_request.id}/confirm-telephone-number", headers: }
context "when org has phone number" do
let(:phone_number) { 123 }
it "asks to confirm or provide new number" do
expect(page).to have_content("This telephone number is correct")
expect(page).to have_content("Confirm the telephone number on file, or enter a new one.")
expect(page).to have_content(phone_number)
expect(page).to have_content("What is #{merge_request.absorbing_organisation.name}'s telephone number?")
end
end
context "when org does not have a phone number set" do
let(:phone_number) { nil }
it "asks provide new number" do
expect(page).not_to have_content("This telephone number is correct")
expect(page).not_to have_content("Confirm the telephone number on file, or enter a new one.")
expect(page).to have_content("What is #{merge_request.absorbing_organisation.name}'s telephone number?")
end
end
end
describe "#update" do
before { sign_in user }
@ -260,6 +292,7 @@ RSpec.describe MergeRequestsController, type: :request do
end
end
describe "from absorbing_organisation page" do
context "when not answering the question" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: other_organisation) }
let(:params) do
@ -329,6 +362,117 @@ RSpec.describe MergeRequestsController, type: :request do
end
end
end
describe "from confirm_telephone_number page" do
context "when confirming the number" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, new_absorbing_organisation: true, new_telephone_number: "123") }
let(:params) do
{ merge_request: { telephone_number_correct: "1", page: "confirm_telephone_number" } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "redirects telephone number path" do
request
expect(response).to redirect_to(merge_date_merge_request_path(merge_request))
end
it "updates telephone_number_correct and sets new_telephone_number to nil" do
expect { request }.to change {
merge_request.reload.telephone_number_correct
}.from(nil).to(true).and change {
merge_request.reload.new_telephone_number
}.from("123").to(nil)
end
end
context "when setting new number" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, new_absorbing_organisation: true) }
let(:params) do
{ merge_request: { telephone_number_correct: "0", new_telephone_number: "123", page: "confirm_telephone_number" } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "redirects telephone number path" do
request
expect(response).to redirect_to(merge_date_merge_request_path(merge_request))
end
it "updates telephone_number_correct and sets new_telephone_number to nil" do
expect { request }.to change {
merge_request.reload.new_telephone_number
}.from(nil).to("123")
end
end
context "when not answering the question and the org has phone number" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: create(:organisation, phone: "123")) }
let(:params) do
{ merge_request: { page: "confirm_telephone_number" } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "renders the error" do
request
expect(page).to have_content("Select to confirm or enter a new telephone number")
end
it "does not update the request" do
expect { request }.not_to(change { merge_request.reload.attributes })
end
end
context "when not answering the question and the org does not have a phone number" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: other_organisation) }
let(:params) do
{ merge_request: { page: "confirm_telephone_number" } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "renders the error" do
request
expect(page).to have_content("Enter a valid telephone number")
end
it "does not update the request" do
expect { request }.not_to(change { merge_request.reload.attributes })
end
end
context "when not answering the phone number" do
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: other_organisation) }
let(:params) do
{ merge_request: { page: "confirm_telephone_number", telephone_number_correct: "0" } }
end
let(:request) do
patch "/merge-request/#{merge_request.id}", headers:, params:
end
it "renders the error" do
request
expect(page).to have_content("Enter a valid telephone number")
end
it "does not update the request" do
expect { request }.not_to(change { merge_request.reload.attributes })
end
end
end
end
end
context "when user is signed in as a support user" do

Loading…
Cancel
Save