diff --git a/spec/fixtures/complete_lettings_log.json b/spec/fixtures/complete_lettings_log.json deleted file mode 100644 index 39be794a4..000000000 --- a/spec/fixtures/complete_lettings_log.json +++ /dev/null @@ -1,179 +0,0 @@ -{ - "lettings_log": { - "tenancycode": "T1245", - "age1": 34, - "sex1": "M", - "ethnic": 1, - "national": 1, - "prevten": 3, - "ecstat1": 1, - "hhmemb": 3, - "age2": 29, - "sex2": "F", - "ecstat2": 2, - "age3": 11, - "sex3": "R", - "ecstat3": 9, - "age4": null, - "sex4": null, - "ecstat4": null, - "age5": null, - "sex5": null, - "ecstat5": null, - "age6": null, - "sex6": null, - "ecstat6": null, - "age7": null, - "sex7": null, - "ecstat7": null, - "age8": null, - "sex8": null, - "ecstat8": null, - "homeless": 1, - "underoccupation_benefitcap": 2, - "leftreg": null, - "reservist": null, - "illness": 2, - "preg_occ": 2, - "startertenancy": 2, - "tenancylength": null, - "tenancy": 2, - "ppostcode_full": "NW18TR", - "rsnvac": 5, - "unittype_gn": 7, - "beds": 2, - "offered": 0, - "wchair": 1, - "earnings": 190, - "incfreq": 1, - "benefits": 3, - "period": 3, - "layear": 7, - "waityear": 2, - "postcode_full": "NW18EE", - "reasonpref": 2, - "cbl": 1, - "chr": 0, - "cap": 0, - "reasonother": "", - "housingneeds": 1, - "housingneeds_type": 2, - "housingneeds_other": 0, - "housingneeds_c": 1, - "illness_type_1": null, - "illness_type_2": null, - "illness_type_3": null, - "illness_type_4": null, - "illness_type_8": null, - "illness_type_5": null, - "illness_type_6": null, - "illness_type_7": null, - "illness_type_9": null, - "illness_type_10": null, - "rp_homeless": null, - "rp_insan_unsat": null, - "rp_medwel": null, - "rp_hardship": null, - "rp_dontknow": null, - "tenancyother": "", - "net_income_value_check": null, - "property_owner_organisation": null, - "property_manager_organisation": null, - "irproduct_other": "", - "purchaser_code": null, - "reason": 42, - "propcode": "PT562", - "majorrepairs": 1, - "la": "E09000007", - "prevloc": "E09000007", - "hb": 9, - "hbrentshortfall": null, - "property_relet": null, - "mrcdate": "2021-05-07T00:00:00.000+01:00", - "incref": null, - "startdate": "2021-06-06T00:00:00.000+01:00", - "armedforces": 2, - "first_time_property_let_as_social_housing": 0, - "unitletas": 1, - "builtype": 1, - "voiddate": "2021-05-05T00:00:00.000+01:00", - "owning_organisation_id": 1, - "managing_organisation_id": 1, - "renttype": 2, - "needstype": 1, - "lettype": 7, - "postcode_known": 1, - "is_la_inferred": true, - "totchild": 1, - "totelder": 0, - "totadult": 2, - "net_income_known": 0, - "nocharge": 0, - "is_carehome": null, - "household_charge": null, - "referral": 2, - "brent": "350.0", - "scharge": "11.0", - "pscharge": "11.0", - "supcharg": "0.0", - "tcharge": "372.0", - "tshortfall": null, - "chcharge": null, - "declaration": 1, - "ppcodenk": 1, - "previous_la_known": null, - "is_previous_la_inferred": true, - "age1_known": 0, - "age2_known": 0, - "age3_known": 0, - "age4_known": null, - "age5_known": null, - "age6_known": null, - "age7_known": null, - "age8_known": null, - "ethnic_group": 0, - "letting_allocation_unknown": 0, - "details_known_2": 0, - "details_known_3": 0, - "details_known_4": null, - "details_known_5": null, - "details_known_6": null, - "details_known_7": null, - "details_known_8": null, - "rent_type": 1, - "has_benefits": 0, - "renewal": 0, - "wrent": "87.5", - "wscharge": "2.75", - "wpschrge": "2.75", - "wsupchrg": "0.0", - "wtcharge": "93.0", - "wtshortfall": null, - "refused": 1, - "wchchrg": null, - "newprop": 2, - "relat2": "P", - "relat3": "C", - "relat4": null, - "relat5": null, - "relat6": null, - "relat7": null, - "relat8": null, - "rent_value_check": null, - "old_form_id": null, - "lar": null, - "irproduct": null, - "old_id": null, - "joint": null, - "assigned_to_id": 2, - "retirement_value_check": null, - "tshortfall_known": null, - "sheltered": null, - "pregnancy_value_check": null, - "hhtype": 6, - "new_old": 1, - "vacdays": 30, - "scheme_id": null, - "location_id": null - } -} diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 5a0e26df0..a3dc1396f 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -21,13 +21,11 @@ RSpec.describe LettingsLogsController, type: :request do "Authorization" => basic_credentials, } end - let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } before do allow(ENV).to receive(:[]) allow(ENV).to receive(:[]).with("API_USER").and_return(api_username) allow(ENV).to receive(:[]).with("API_KEY").and_return(api_password) - allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) end describe "POST #create" do @@ -46,6 +44,12 @@ RSpec.describe LettingsLogsController, type: :request do "managing_organisation_id": managing_organisation.id, "assigned_to_id": user.id, "tenancycode": tenant_code, + "startdate": current_date.strftime("%Y-%m-%d"), + "renewal": 0, + "needstype": 1, + "rent_type": 1, + "declaration": 1, + "manual_address_entry_selected": true, "age1": age1, "postcode_full": postcode_full, "offered": offered, @@ -54,14 +58,9 @@ RSpec.describe LettingsLogsController, type: :request do end before do - Timecop.freeze(Time.utc(2022, 2, 8)) post "/lettings-logs", headers:, params: params.to_json end - after do - Timecop.unfreeze - end - it "returns http success" do expect(response).to have_http_status(:success) end @@ -80,12 +79,11 @@ RSpec.describe LettingsLogsController, type: :request do context "with invalid json parameters" do let(:age1) { 2000 } - let(:offered) { 21 } it "validates lettings log parameters" do json_response = JSON.parse(response.body) expect(response).to have_http_status(:unprocessable_content) - expect(json_response["errors"]).to match_array([["offered", [I18n.t("validations.shared.numeric.within_range", field: "Times previously offered since becoming available", min: 0, max: 20)]], ["age1", [I18n.t("validations.shared.numeric.within_range", field: "Lead tenant’s age", min: 16, max: 120)]]]) + expect(json_response["errors"]).to match_array([["age1", [I18n.t("validations.shared.numeric.within_range", field: "Lead tenant’s age", min: 16, max: 120)]]]) end end @@ -97,21 +95,11 @@ RSpec.describe LettingsLogsController, type: :request do end context "with a complete lettings log submission" do - let(:org_params) do - { - "lettings_log" => { - "owning_organisation_id" => owning_organisation.id, - "managing_organisation_id" => managing_organisation.id, - "assigned_to_id" => user.id, - }, - } - end - let(:lettings_log_params) { JSON.parse(File.open("spec/fixtures/complete_lettings_log.json").read) } let(:params) do - lettings_log_params.merge(org_params) { |_k, a_val, b_val| a_val.merge(b_val) } + create(:lettings_log, :completed).attributes end - xit "marks the record as completed" do + it "marks the record as completed" do json_response = JSON.parse(response.body) expect(json_response).not_to have_key("errors") @@ -1168,8 +1156,6 @@ RSpec.describe LettingsLogsController, type: :request do let(:lettings_log) { create(:lettings_log, status: "not_started", assigned_to: user) } it "shows guidance link" do - allow(Time.zone).to receive(:now).and_return(lettings_log.form.edit_end_date - 1.day) - get lettings_log_path(lettings_log) expect(lettings_log.status).to eq("not_started") expect(page).to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)") end @@ -1287,9 +1273,9 @@ RSpec.describe LettingsLogsController, type: :request do context "when accessing the check answers page" do before do - Timecop.freeze(2021, 4, 1) + Timecop.freeze(previous_collection_start_date) Singleton.__init__(FormHandler) - completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), voiddate: Time.zone.local(2021, 4, 1), mrcdate: Time.zone.local(2021, 4, 1)) + completed_lettings_log.update!(startdate: previous_collection_start_date, voiddate: previous_collection_start_date, mrcdate: previous_collection_start_date) Timecop.unfreeze stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) @@ -1298,6 +1284,7 @@ RSpec.describe LettingsLogsController, type: :request do let(:postcode_lettings_log) do FactoryBot.create(:lettings_log, + :setup_completed, assigned_to: user, postcode_known: "No") end @@ -1306,6 +1293,7 @@ RSpec.describe LettingsLogsController, type: :request do it "shows the inferred la" do lettings_log = FactoryBot.create(:lettings_log, + :setup_completed, assigned_to: user, postcode_known: 1, postcode_full: "PO5 3TE") @@ -1315,21 +1303,6 @@ RSpec.describe LettingsLogsController, type: :request do expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer) end - it "does not show do you know the property postcode question" do - get "/lettings-logs/#{id}/property-information/check-answers" - expect(CGI.unescape_html(response.body)).not_to include("Do you know the property postcode?") - end - - it "shows if the postcode is not known" do - get "/lettings-logs/#{id}/property-information/check-answers" - expect(CGI.unescape_html(response.body)).to include("Not known") - end - - it "shows link to answer question if the question wasn’t answered" do - get "/lettings-logs/#{id}/income-and-benefits/check-answers" - expect(page).to have_link("Enter income", href: "/lettings-logs/#{id}/net-income?referrer=check_answers_new_answer", class: "govuk-link govuk-link--no-visited-state") - end - it "does not allow you to change the answers for previous collection year logs" do get "/lettings-logs/#{completed_lettings_log.id}/setup/check-answers", headers: { "Accept" => "text/html" }, params: {} expect(page).not_to have_link("Change")