Skip to content

Commit

Permalink
I have added the new field for buyer details where buyers now have to…
Browse files Browse the repository at this point in the history
… opt in to be contacted by the category. If the buyer has not answered this new question, they will be forced to before they can do any actions within the service (for example, start a search).
  • Loading branch information
tim-s-ccs committed Apr 25, 2023
1 parent fa61f84 commit 715f199
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def buyer_detail_params
:organisation_address_town,
:organisation_address_county,
:organisation_address_postcode,
:central_government
:central_government,
:contact_opt_in
)
end

Expand Down
10 changes: 10 additions & 0 deletions app/javascript/src/facilitiesManagement/contactDetailsInStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ const initContactDetailsInStorage = (): void => {
name: 'contactDetailsSectorFalse',
$element: $(`#${modelName}_central_government_false`),
type: ContactDetailType.RadioInput
},
{
name: 'contactDetailsContactOptInTrue',
$element: $(`#${modelName}_contact_opt_in_true`),
type: ContactDetailType.RadioInput
},
{
name: 'contactDetailsContactOptInFalse',
$element: $(`#${modelName}_contact_opt_in_false`),
type: ContactDetailType.RadioInput
}
]

Expand Down
3 changes: 2 additions & 1 deletion app/models/facilities_management/buyer_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class BuyerDetail < ApplicationRecord

include AddressValidator

validates :central_government, length: { maximum: MAX_FIELD_LENGTH }, inclusion: { in: [true, false], message: :blank }, on: :update
validates :central_government, inclusion: { in: [true, false] }, on: :update
validates :contact_opt_in, inclusion: { in: [true, false] }, on: :update

delegate :email, to: :user

Expand Down
55 changes: 37 additions & 18 deletions app/views/facilities_management/buyer_details/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,50 @@
address_title: t('.organisation_address')
} %>

<h2 class="govuk-heading-m">
<%= t('.sector') %>
</h2>
<%= form_group_with_error(f.object, :central_government) do |displayed_error| %>
<hr class="govuk-section-break govuk-section-break--m">

<div class="govuk-heading-s govuk-!-margin-bottom-0">
<%= t('.which_type_of_public_sector_org') %>
</div>
<%= form_group_with_error(f.object, :central_government) do |displayed_error| %>
<fieldset class="govuk-fieldset" aria-describedby="central_government-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
<%= t('.central_government.legend') %>
</legend>
<div id="central_government-hint" class="govuk-hint">
<%= t('.search_html', url: 'https://www.gov.uk/government/organisations') %>
</div>
<%= displayed_error %>
<div class="govuk-radios govuk-radios--inline" data-module="govuk-radios">
<div class="govuk-radios__item">
<%= f.radio_button :central_government, true, class: 'govuk-radios__input' %>
<%= f.label :central_government, t('.central_government.options.true'), value: true, class: 'govuk-label govuk-radios__label' %>
</div>
<div class="govuk-radios__item">
<%= f.radio_button :central_government, false, class: 'govuk-radios__input' %>
<%= f.label :central_government, t('.central_government.options.false'), value: false, class: 'govuk-label govuk-radios__label' %>
</div>
</div>
</fieldset>
<% end %>
<div class="govuk-!-margin-top-0 govuk-!-margin-bottom-3">
<span class="govuk-caption-m"><%= t('.search_html', url: 'https://www.gov.uk/government/organisations') %></span>
</div>
<%= displayed_error %>
<div class="govuk-radios govuk-radios--inline govuk-!-margin-bottom-6 govuk-!-margin-top-6">
<div class="govuk-radios govuk-radios--inline">
<%= form_group_with_error(f.object, :contact_opt_in) do |displayed_error| %>
<fieldset class="govuk-fieldset" aria-describedby="contact_opt_in-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
<%= t('.contact_opt_in.legend') %>
</legend>
<div id="contact_opt_in-hint" class="govuk-hint">
<%= t('.contact_opt_in.hint') %>
</div>
<%= displayed_error %>
<div class="govuk-radios govuk-radios--inline" data-module="govuk-radios">
<div class="govuk-radios__item">
<%= f.radio_button :central_government, true, value: true, class: 'govuk-radios__input', required: true %>
<%= f.label :central_government, t('.central_gov'), value: true, class: 'govuk-label govuk-radios__label' %>
<%= f.radio_button :contact_opt_in, true, class: 'govuk-radios__input' %>
<%= f.label :contact_opt_in, t('.contact_opt_in.options.true'), value: true, class: 'govuk-label govuk-radios__label' %>
</div>
<div class="govuk-radios__item">
<%= f.radio_button :central_government, false, value: false, class: 'govuk-radios__input', required: true %>
<%= f.label :central_government, t('.wider_public_sector'), value: false, class: 'govuk-label govuk-radios__label' %>
<%= f.radio_button :contact_opt_in, false, class: 'govuk-radios__input' %>
<%= f.label :contact_opt_in, t('.contact_opt_in.options.false'), value: false, class: 'govuk-label govuk-radios__label' %>
</div>
</div>
</div>
</fieldset>
<% end %>

<div>
Expand Down
18 changes: 13 additions & 5 deletions config/locales/views/facilities_management.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ en:
base:
not_selected: You must select an address to save your details
central_government:
blank: Select the type of public sector organisation you’re buying for
inclusion: Select the type of public sector organisation you’re buying for
contact_opt_in:
inclusion: You must select an option
full_name:
blank: Enter your full name
invalid: Enter your full name
Expand Down Expand Up @@ -310,18 +311,25 @@ en:
back: Return to your account
buyer_details: Manage your details
cant_find_address: Enter address manually, if you can’t find address
central_gov: Central government
central_government:
legend: Which type of public sector organisation are you buying for?
options:
'false': Wider public sector
'true': Central government
contact_opt_in:
hint: You can change these settings at any time.
legend: Can CCS contact you about any searches you save?
options:
'false': 'No'
'true': 'Yes'
job_title: Job title
name: Name
organisation_address: Organisation address
organisation_details: Organisation details
organisation_name: Organisation name
search_html: Search <a href="%{url}" target="_blank">central government departments, agencies and public bodies</a> if you’re unsure.
sector: Sector
submit: Save and continue
telephone_number: Telephone number
which_type_of_public_sector_org: Which type of public sector organisation are you buying for?
wider_public_sector: Wider public sector
your_details: Personal details
edit_address:
add_address: Add address
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddContactOptInForBuyerDetails < ActiveRecord::Migration[7.0]
def change
add_column :facilities_management_buyer_details, :contact_opt_in, :boolean
end
end
20 changes: 9 additions & 11 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[7.0].define(version: 2023_03_14_114915) do
ActiveRecord::Schema[7.0].define(version: 2023_04_25_075107) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -83,6 +83,7 @@
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.uuid "user_id", null: false
t.boolean "contact_opt_in"
t.index ["user_id"], name: "index_facilities_management_buyer_details_on_user_id"
end

Expand Down Expand Up @@ -426,7 +427,6 @@

create_table "facilities_management_rm6232_procurements", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "user_id", null: false
t.string "aasm_state", limit: 30
t.text "service_codes", default: [], array: true
t.text "region_codes", default: [], array: true
t.bigint "annual_contract_value"
Expand All @@ -435,13 +435,14 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "contract_number"
t.boolean "tupe"
t.integer "initial_call_off_period_years"
t.integer "initial_call_off_period_months"
t.date "initial_call_off_start_date"
t.boolean "mobilisation_period_required"
t.integer "mobilisation_period"
t.boolean "extensions_required"
t.integer "mobilisation_period"
t.boolean "mobilisation_period_required"
t.date "initial_call_off_start_date"
t.integer "initial_call_off_period_months"
t.integer "initial_call_off_period_years"
t.boolean "tupe"
t.string "aasm_state", limit: 30
t.index ["user_id", "contract_name"], name: "index_rm6232_procurement_name_and_user_id", unique: true
t.index ["user_id"], name: "index_fm_rm6232_procurements_on_user_id"
end
Expand Down Expand Up @@ -668,9 +669,6 @@
add_foreign_key "facilities_management_rm6232_admin_supplier_data_edits", "facilities_management_rm6232_admin_supplier_data", column: "facilities_management_rm6232_admin_supplier_data_id"
add_foreign_key "facilities_management_rm6232_admin_supplier_data_edits", "users"
add_foreign_key "facilities_management_rm6232_admin_uploads", "users"
add_foreign_key "facilities_management_rm6232_procurement_buildings", "facilities_management_buildings", column: "building_id"
add_foreign_key "facilities_management_rm6232_procurement_buildings", "facilities_management_rm6232_procurements"
add_foreign_key "facilities_management_rm6232_procurement_call_off_extensions", "facilities_management_rm6232_procurements"
add_foreign_key "facilities_management_rm6232_procurements", "users"
add_foreign_key "facilities_management_rm6232_services", "facilities_management_rm6232_work_packages", column: "work_package_code", primary_key: "code"
add_foreign_key "facilities_management_rm6232_supplier_lot_data", "facilities_management_rm6232_suppliers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Buyer details
| Organisation name | Feel Good inc. |
| Postcode | ST16 1AA |
And I check 'Central government' for the sector
And I check 'Yes' for being contacted

Scenario: Save details for the buyer - add address normally
And I click on 'Find address'
Expand All @@ -25,6 +26,7 @@ Feature: Buyer details
| Organisation name | Feel Good inc. |
| Organisation address | Stafford Delivery Office, Newport Road, Stafford ST16 1AA |
| Sector | Central government |
| Contact opt in | Yes |

Scenario: Save details for the buyer - add address manually
And I click on 'Find address'
Expand All @@ -47,3 +49,4 @@ Feature: Buyer details
| Organisation name | Feel Good inc. |
| Organisation address | 112 Test street, Westminister AA1 1AA |
| Sector | Central government |
| Contact opt in | Yes |
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Buyer details - validations
| Enter your organisation name |
| Enter a valid postcode, for example SW1A 1AA |
| Select the type of public sector organisation youre buying for |
| You must select an option |

@javascript
Scenario Outline: Add address - frontend
Expand All @@ -33,6 +34,7 @@ Feature: Buyer details - validations
| Organisation name | Feel Good inc. |
| Postcode | test |
And I check 'Central government' for the sector
And I check 'Yes' for being contacted
And I click on 'Save and continue'
Then I should see the following error messages:
| Enter a valid postcode, for example SW1A 1AA |
Expand All @@ -45,6 +47,7 @@ Feature: Buyer details - validations
| Organisation name | Feel Good inc. |
| Postcode | ST16 1AA |
And I check 'Central government' for the sector
And I check 'Yes' for being contacted
And I click on 'Save and continue'
Then I should see the following error messages:
| You must select an address to save your details |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Buyer details
| Organisation name | Feel Good inc. |
| Postcode | ST16 1AA |
And I check 'Wider public sector' for the sector
And I check 'No' for being contacted

Scenario: Save details for the buyer - add address normally
And I click on 'Find address'
Expand All @@ -25,6 +26,7 @@ Feature: Buyer details
| Organisation name | Feel Good inc. |
| Organisation address | The Goods Shed, Newport Road, Stafford ST16 1AA |
| Sector | Wider public sector |
| Contact opt in | No |

Scenario: Save details for the buyer - add address manually
And I click on 'Find address'
Expand All @@ -47,3 +49,4 @@ Feature: Buyer details
| Organisation name | Feel Good inc. |
| Organisation address | 112 Test street, Westminister AA1 1AA |
| Sector | Wider public sector |
| Contact opt in | No |
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Buyer details - validations
| Enter your organisation name |
| Enter a valid postcode, for example SW1A 1AA |
| Select the type of public sector organisation youre buying for |
| You must select an option |

@javascript
Scenario Outline: Add address - frontend
Expand All @@ -33,6 +34,7 @@ Feature: Buyer details - validations
| Organisation name | Feel Good inc. |
| Postcode | test |
And I check 'Central government' for the sector
And I check 'Yes' for being contacted
And I click on 'Save and continue'
Then I should see the following error messages:
| Enter a valid postcode, for example SW1A 1AA |
Expand All @@ -45,6 +47,7 @@ Feature: Buyer details - validations
| Organisation name | Feel Good inc. |
| Postcode | ST16 1AA |
And I check 'Central government' for the sector
And I check 'Yes' for being contacted
And I click on 'Save and continue'
Then I should see the following error messages:
| You must select an address to save your details |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
buyer_detail_page.sector.send(option.to_sym).choose
end

Then('I check {string} for being contacted') do |option|
buyer_detail_page.contact_opt_in.send(option.to_sym).choose
end

Then('I should see the postcode error message for buyer details') do
expect(buyer_detail_page.postcode_error_message).to have_text('Enter a valid postcode, for example SW1A 1AA')
end
Expand All @@ -11,6 +15,8 @@
case field
when 'Sector'
expect(buyer_detail_page.sector.send(value.to_sym)).to be_checked
when 'Contact opt in'
expect(buyer_detail_page.contact_opt_in.send(value.to_sym)).to be_checked
when 'Organisation address'
expect(buyer_detail_page.buyer_details.send(field.to_sym)).to have_content value
else
Expand Down
5 changes: 5 additions & 0 deletions features/support/pages/buyer_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class BuyerDetail < SitePrism::Page
element :'Wider public sector', '#facilities_management_buyer_detail_central_government_false'
end

section :contact_opt_in, '#contact_opt_in-form-group' do
element :Yes, '#facilities_management_buyer_detail_contact_opt_in_true'
element :No, '#facilities_management_buyer_detail_contact_opt_in_false'
end

element :postcode_error_message, '#organisation_address_postcode-error'
element :change_address, '#change-input-2'
end
Expand Down
1 change: 1 addition & 0 deletions spec/factories/buyer_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
organisation_address_county { 'MyString' }
organisation_address_postcode { 'SW1W 9SZ' }
central_government { true }
contact_opt_in { true }
end
end
Loading

0 comments on commit 715f199

Please sign in to comment.