Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
18 KiB

require "rails_helper"
RSpec.describe LocationsHelper do
describe "mobility type selection" do
Cldc 1669 add location redesign (#1034) * feat: wip postcode page * feat: wip add new flow * feat: add check answers page, continue updating flow * feat: add back behaviour * feat: more flow work * feat: further flow work and flash notice, name tidying * feat: add check_answers referrer linking * feat: add controller and details linking and lint * refactor: erblinting * feat: add local_authority page (currenlty separate from edit_local_authority to avoid conflict with add location to newly created scheme path, to be fixed later). also copy and routing updates * feat: add validations to controller (could later be added to model) * fix: correct date order * feat: validate on model (except startdate) * feat: copy update * refactor: railsification * feat: add date model validation * feat: add updated availability text in check_answers * feat: more updated dynamic text and linking * refactor: erblinting * refactor: cleanup of redundant code * refactor: remove redundant create * feat: use rails route * test: wip tests * test: wip tests * feat: add new back behaviour for new scheme path and tests wip * feat: add more back behaviour for new scheme path and fix local auth validation * feat: further linking behaviour with routes and referrers, don't add new location automatically to new schemes * feat: if location with no details added, route to normal path rather than check answers * test: update model and helper location tests * test: more test updates * test: more test updates and remove redundant files * test: remove redundant tests, add postcode test * test: add new #new tests * test: add test for all new controller methods * test: add more startdate tests * refactor: erblinting * test: fix failing tests * test: update scheme test * feat: respond to PR comments * feat: make postcode clear only if changed * feat: add _update methods * refactor: simplify validation and location_edit_path method * refactor: add helper method for action text * refactor: remove redundant logic * refactor: simplify routing * refactor: reintroduce location_params * refactor: use presence validation for postcode * refactor: use presence validation for la * feat: validate confirmed * tests: make tests pass with new startdate validation * WIP * refactor: simplify display attributes helpers and update tests * refactor: linting * feat: design change to save behaviour * test: fix failing tests * feat: location code copy tweak * refactor: remove redundant function * refactor: remove add_another_location and new location page * feat: simplify startdate validations to move to model, use scheme available_from date for in range validation * test: fix failing tests * refactor: linting * feat: remove name validation as a result of PO review * test: update tests * refactor: remove redundant context Co-authored-by: James Rose <james@jbpr.net>
2 years ago
expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."),
OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "Fitted with stairlifts, ramps, level access showers or grab rails."),
OpenStruct.new(id: "None", name: "None", description: "Not designed to wheelchair-user standards or fitted with any equipment or adaptations.")]
it "returns correct selection to display" do
expect(mobility_type_selection).to eq(expected_selection)
end
end
describe "another location selection" do
it "returns correct selection to display" do
expected_selection = [OpenStruct.new(id: "Yes", name: "Yes"), OpenStruct.new(id: "No", name: "No")]
expect(another_location_selection).to eq(expected_selection)
end
end
describe "type of units selection" do
it "returns correct selection to display" do
expected_selection = [OpenStruct.new(id: "Bungalow", name: "Bungalow"),
OpenStruct.new(id: "Self-contained flat or bedsit", name: "Self-contained flat or bedsit"),
OpenStruct.new(id: "Self-contained flat or bedsit with common facilities", name: "Self-contained flat or bedsit with common facilities"),
OpenStruct.new(id: "Self-contained house", name: "Self-contained house"),
OpenStruct.new(id: "Shared flat", name: "Shared flat"),
OpenStruct.new(id: "Shared house or hostel", name: "Shared house or hostel")]
expect(type_of_units_selection).to eq(expected_selection)
end
end
describe "selection options" do
it "returns empty array for nil" do
expect(selection_options(nil)).to eq([])
end
it "returns empty array for empty string" do
expect(selection_options("")).to eq([])
end
it "returns empty array for empty object" do
expect(selection_options({})).to eq([])
end
it "can map a resource with values" do
expect(selection_options(%w[example])).to eq([OpenStruct.new(id: "example", name: "Example")])
end
end
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
describe "Active periods" do
let(:location) { FactoryBot.create(:location, startdate: nil) }
before do
Timecop.freeze(2022, 10, 10)
end
after do
Timecop.unfreeze
end
it "returns one active period without to date" do
expect(location_active_periods(location).count).to eq(1)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: nil)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "ignores reactivations that were deactivated on the same day" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
location.reload
expect(location_active_periods(location).count).to eq(1)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "returns sequential non reactivated active periods" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), location:)
location.reload
expect(location_active_periods(location).count).to eq(2)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
expect(location_active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 6, 4), to: Time.zone.local(2022, 7, 6))
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "returns sequential reactivated active periods" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), reactivation_date: Time.zone.local(2022, 8, 5), location:)
location.reload
expect(location_active_periods(location).count).to eq(3)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
expect(location_active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 6, 4), to: Time.zone.local(2022, 7, 6))
expect(location_active_periods(location).third).to have_attributes(from: Time.zone.local(2022, 8, 5), to: nil)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "returns non sequential non reactivated active periods" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), reactivation_date: Time.zone.local(2022, 8, 5), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: nil, location:)
location.reload
expect(location_active_periods(location).count).to eq(2)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
expect(location_active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 8, 5), to: nil)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "returns non sequential reactivated active periods" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 7, 6), reactivation_date: Time.zone.local(2022, 8, 5), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 4), location:)
location.reload
expect(location_active_periods(location).count).to eq(3)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 5, 5))
expect(location_active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 6, 4), to: Time.zone.local(2022, 7, 6))
expect(location_active_periods(location).third).to have_attributes(from: Time.zone.local(2022, 8, 5), to: nil)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "returns correct active periods when reactivation happends during a deactivated period" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 11, 11), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 6), reactivation_date: Time.zone.local(2022, 7, 7), location:)
location.reload
expect(location_active_periods(location).count).to eq(2)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 4, 6))
expect(location_active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 11, 11), to: nil)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
it "returns correct active periods when a full deactivation period happens during another deactivation period" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 11), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 6), reactivation_date: Time.zone.local(2022, 7, 7), location:)
location.reload
expect(location_active_periods(location).count).to eq(2)
expect(location_active_periods(location).first).to have_attributes(from: Time.zone.local(2022, 4, 1), to: Time.zone.local(2022, 4, 6))
expect(location_active_periods(location).second).to have_attributes(from: Time.zone.local(2022, 7, 7), to: nil)
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
end
end
Cldc 1671 deactivate scheme (#980) * feat: wip update scheme summary page * feat: wip deactivate scheme schemes page * feat: wip toggle active page * feat: wip set deactivation_date to a datetime (to be more specific times later_ * Change conditional question controller to accommodate all models * feat: add specific datetimes for deactivation * feat: correct date and add notice * feat: wip error behaviour * feat: wip errors * feat: wip errors refactoring * feat: wip errors more refactoring * refactor: linting * feat: add second error in correct position and wip date range error * feat: remove unneccessary db field * feat: change type values to strings * refactor: tidy up controller logic * refactor: use same structure as locations deactivation * feat: add general partially missing date input error * feat: add tests ("updates existing scheme with valid deactivation date and renders scheme page" still wip) and add new partially nil date behaviour to locations controller * feat: fix tests, add status tag behaviour and remove unnecessary nils * refactor: linting * refactor: erblinting * refactor: remove redundant line * refactor: respond to PR comments 1 * refactor: respond to PR comments 2 * refactor: respond to PR comments 3 * refactor: respond to PR comments 3 (locations side) * fix: remove @locations in location model * fix: remove @locations in location model * fix: update status names * feat: wip validation update * feat: add validation to model layer * feat: further separate scheme deactivation behaviour * test: update tests to new flow * feat: respond to pr comments and add dynamic success text * feat: duplicate behaviour schemes -> locations (+ tests) * refactor: linting * refactor: typo and remove unnecessary line for this PR * refactor: feature toggle simplification * Refactor locations and schemes controller actions - Rename confirmation partials to `deactivate_confirm.html.erb` so that they match the actions in which they belong to - Make all deactivation date comparision UTC time * feat: update deactivation_date validation and add tests * refactor: linting Co-authored-by: Kat <katrina@kosiak.co.uk> Co-authored-by: James Rose <james@jbpr.net>
2 years ago
describe "display_location_attributes" do
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2022, 3, 16), startdate: Time.zone.local(2022, 4, 1)) }
it "returns correct display attributes" do
attributes = [
Cldc 1669 add location redesign (#1034) * feat: wip postcode page * feat: wip add new flow * feat: add check answers page, continue updating flow * feat: add back behaviour * feat: more flow work * feat: further flow work and flash notice, name tidying * feat: add check_answers referrer linking * feat: add controller and details linking and lint * refactor: erblinting * feat: add local_authority page (currenlty separate from edit_local_authority to avoid conflict with add location to newly created scheme path, to be fixed later). also copy and routing updates * feat: add validations to controller (could later be added to model) * fix: correct date order * feat: validate on model (except startdate) * feat: copy update * refactor: railsification * feat: add date model validation * feat: add updated availability text in check_answers * feat: more updated dynamic text and linking * refactor: erblinting * refactor: cleanup of redundant code * refactor: remove redundant create * feat: use rails route * test: wip tests * test: wip tests * feat: add new back behaviour for new scheme path and tests wip * feat: add more back behaviour for new scheme path and fix local auth validation * feat: further linking behaviour with routes and referrers, don't add new location automatically to new schemes * feat: if location with no details added, route to normal path rather than check answers * test: update model and helper location tests * test: more test updates * test: more test updates and remove redundant files * test: remove redundant tests, add postcode test * test: add new #new tests * test: add test for all new controller methods * test: add more startdate tests * refactor: erblinting * test: fix failing tests * test: update scheme test * feat: respond to PR comments * feat: make postcode clear only if changed * feat: add _update methods * refactor: simplify validation and location_edit_path method * refactor: add helper method for action text * refactor: remove redundant logic * refactor: simplify routing * refactor: reintroduce location_params * refactor: use presence validation for postcode * refactor: use presence validation for la * feat: validate confirmed * tests: make tests pass with new startdate validation * WIP * refactor: simplify display attributes helpers and update tests * refactor: linting * feat: design change to save behaviour * test: fix failing tests * feat: location code copy tweak * refactor: remove redundant function * refactor: remove add_another_location and new location page * feat: simplify startdate validations to move to model, use scheme available_from date for in range validation * test: fix failing tests * refactor: linting * feat: remove name validation as a result of PO review * test: update tests * refactor: remove redundant context Co-authored-by: James Rose <james@jbpr.net>
2 years ago
{ attribute: "postcode", name: "Postcode", value: location.postcode },
{ attribute: "name", name: "Location name", value: location.name },
{ attribute: "local_authority", name: "Local authority", value: location.location_admin_district },
{ attribute: "units", name: "Number of units", value: location.units },
{ attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ attribute: "location_code", name: "Location code", value: location.location_code },
{ attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
{ attribute: "status", name: "Status", value: :active },
]
Cldc 1671 deactivate scheme (#980) * feat: wip update scheme summary page * feat: wip deactivate scheme schemes page * feat: wip toggle active page * feat: wip set deactivation_date to a datetime (to be more specific times later_ * Change conditional question controller to accommodate all models * feat: add specific datetimes for deactivation * feat: correct date and add notice * feat: wip error behaviour * feat: wip errors * feat: wip errors refactoring * feat: wip errors more refactoring * refactor: linting * feat: add second error in correct position and wip date range error * feat: remove unneccessary db field * feat: change type values to strings * refactor: tidy up controller logic * refactor: use same structure as locations deactivation * feat: add general partially missing date input error * feat: add tests ("updates existing scheme with valid deactivation date and renders scheme page" still wip) and add new partially nil date behaviour to locations controller * feat: fix tests, add status tag behaviour and remove unnecessary nils * refactor: linting * refactor: erblinting * refactor: remove redundant line * refactor: respond to PR comments 1 * refactor: respond to PR comments 2 * refactor: respond to PR comments 3 * refactor: respond to PR comments 3 (locations side) * fix: remove @locations in location model * fix: remove @locations in location model * fix: update status names * feat: wip validation update * feat: add validation to model layer * feat: further separate scheme deactivation behaviour * test: update tests to new flow * feat: respond to pr comments and add dynamic success text * feat: duplicate behaviour schemes -> locations (+ tests) * refactor: linting * refactor: typo and remove unnecessary line for this PR * refactor: feature toggle simplification * Refactor locations and schemes controller actions - Rename confirmation partials to `deactivate_confirm.html.erb` so that they match the actions in which they belong to - Make all deactivation date comparision UTC time * feat: update deactivation_date validation and add tests * refactor: linting Co-authored-by: Kat <katrina@kosiak.co.uk> Co-authored-by: James Rose <james@jbpr.net>
2 years ago
expect(display_location_attributes(location)).to eq(attributes)
end
context "when location has different local authorities for different years" do
before do
LocalAuthorityLink.create!(local_authority_id: LocalAuthority.find_by(code: "E07000030").id, linked_local_authority_id: LocalAuthority.find_by(code: "E06000063").id)
location.update!(location_code: "E07000030")
end
it "returns correct display attributes" do
attributes = [
{ attribute: "postcode", name: "Postcode", value: location.postcode },
{ attribute: "name", name: "Location name", value: location.name },
{ attribute: "local_authority", name: "Local authority", value: "Eden (until 31 March 2023)\nCumberland (1 April 2023 - present)" },
{ attribute: "units", name: "Number of units", value: location.units },
{ attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ attribute: "location_code", name: "Location code", value: "E07000030 (until 31 March 2023)\nE06000063 (1 April 2023 - present)" },
{ attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
{ attribute: "status", name: "Status", value: :active },
]
expect(display_location_attributes(location)).to eq(attributes)
end
end
context "when location has no local authority" do
before do
LocalAuthorityLink.create!(local_authority_id: LocalAuthority.find_by(code: "E07000030").id, linked_local_authority_id: LocalAuthority.find_by(code: "E06000063").id)
location.update!(location_code: nil)
end
it "returns correct display attributes" do
attributes = [
{ attribute: "postcode", name: "Postcode", value: location.postcode },
{ attribute: "name", name: "Location name", value: location.name },
{ attribute: "local_authority", name: "Local authority", value: "" },
{ attribute: "units", name: "Number of units", value: location.units },
{ attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ attribute: "location_code", name: "Location code", value: "" },
{ attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
{ attribute: "status", name: "Status", value: :incomplete },
]
expect(display_location_attributes(location)).to eq(attributes)
end
end
context "when viewing availability" do
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
context "with no deactivations" do
it "displays previous collection start date as availability date if created_at is earlier than collection start date" do
location.update!(startdate: nil)
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2021")
end
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
it "displays current collection start date as availability date if created_at is later than collection start date" do
location.update!(startdate: nil, created_at: Time.zone.local(2022, 4, 16))
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022")
end
end
context "with previous deactivations" do
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
context "and all reactivated deactivations" do
before do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), location:)
location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
end
end
context "and non reactivated deactivation" do
before do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, location:)
location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
end
end
end
context "with out of order deactivations" do
context "and all reactivated deactivations" do
before do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), location:)
location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
end
end
context "and one non reactivated deactivation" do
before do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:)
location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
end
end
end
context "with multiple out of order deactivations" do
context "and one non reactivated deactivation" do
before do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:)
location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
end
end
end
context "with intersecting deactivations" do
before do
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), location:)
location.reload
end
it "displays the timeline of availability" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
Cldc 1670 reactivate locations (#1007) * route deactivated scheme to reactivation page * Render correct reactivate question content * refactor into a helper * display successful reactivation banner for default date * Save reactivation date * Add reactivation errors * lint and fix url in tests * make toggle translations generic * Add reactivation status * Reuse date validation messages * Show deactivate this location when location is reactivating soon * Display correct confirmation banner * Add validation for reactivation date before deactivation date * Improve availability label * Use current collection start date if created at is later than that * Update paths * Fix controller and don't display the previous day if location availability start afterwards * refactor availability label * Filter out active periods * lint * Refactor active_period method into the model * Allow deactivations and reactivations from available from date instead of start of the collection date * Prevent deactivations during deactivated periods * lint * typo * Remove active periods that last 1 day (because they get deactivated on the same day) * Move the active_periods into helper * extract remove_overlapping_and_empty_periods into a separate method * Remove nested deactivation periods * Make deactivate/reactvate location form use location_deactivation_period model * refactor toggle date methods * extract shared condition * update validations * refactor validations * Update schemes deactivation form to use dectivation model * Refactor * lint * remove redundant location_id and update scheme controller * update active_periods
2 years ago
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end
end
end
end
end