diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 26d20139f..06ed0a064 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -183,7 +183,7 @@ private collection_start_date = FormHandler.instance.current_collection_start_date if [day, month, year].any?(&:blank?) - @location.errors.add(:deactivation_date, message: I18n.t("validations.location.deactivation_date.not_entered")) + @location.errors.add(:deactivation_date, message: I18n.t("validations.location.deactivation_date.not_entered")) elsif !Date.valid_date?(year.to_i, month.to_i, day.to_i) @location.errors.add(:deactivation_date, message: I18n.t("validations.location.deactivation_date.invalid")) elsif !Date.new(year.to_i, month.to_i, day.to_i).between?(collection_start_date, Date.new(2200, 1, 1)) diff --git a/app/helpers/question_attribute_helper.rb b/app/helpers/question_attribute_helper.rb index 020ea1909..601368c22 100644 --- a/app/helpers/question_attribute_helper.rb +++ b/app/helpers/question_attribute_helper.rb @@ -11,7 +11,7 @@ module QuestionAttributeHelper { "data-controller": "conditional-question", "data-action": "click->conditional-question#displayConditional", - "data-info": { conditional_questions: conditional_for, type: type }.to_json, + "data-info": { conditional_questions: conditional_for, type: }.to_json, } end diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index fae7444b0..c2593928e 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -14,7 +14,7 @@ module SchemesHelper { name: "Secondary client group", value: scheme.secondary_client_group }, { name: "Level of support given", value: scheme.support_type }, { name: "Intended length of stay", value: scheme.intended_stay }, - { name: "Availability", value: "Available from #{scheme.available_from.to_formatted_s(:govuk_date)}"}, + { name: "Availability", value: "Available from #{scheme.available_from.to_formatted_s(:govuk_date)}" }, { name: "Status", value: scheme.status }, ] diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 3aa35bda9..2c7556673 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -242,6 +242,46 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:not_found) end end + + context "when looking at scheme details" do + let(:user) { FactoryBot.create(:user, :data_coordinator) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + + before do + Timecop.freeze(Time.utc(2022, 10, 10)) + sign_in user + scheme.deactivation_date = deactivation_date + scheme.save! + get "/schemes/#{scheme.id}" + end + + context "with active scheme" do + let(:deactivation_date) { nil } + + it "renders deactivate this scheme" do + expect(response).to have_http_status(:ok) + expect(page).to have_link("Deactivate this scheme", href: "/schemes/#{scheme.id}/deactivate") + end + end + + context "with deactivated scheme" do + let(:deactivation_date) { Time.utc(2022, 10, 9) } + + it "renders reactivate this scheme" do + expect(response).to have_http_status(:ok) + expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{scheme.id}/reactivate") + end + end + + context "with scheme that's deactivating soon" do + let(:deactivation_date) { Time.utc(2022, 10, 12) } + + it "renders reactivate this scheme" do + expect(response).to have_http_status(:ok) + expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{scheme.id}/reactivate") + end + end + end end context "when signed in as a support user" do @@ -1724,7 +1764,6 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } let(:startdate) { Time.utc(2021, 1, 2) } let(:deactivation_date) { Time.utc(2022, 10, 10) } @@ -1820,68 +1859,4 @@ RSpec.describe SchemesController, type: :request do end end end - - describe "#show" do - context "when not signed in" do - it "redirects to the sign in page" do - get "/schemes/1" - expect(response).to redirect_to("/account/sign-in") - end - end - - context "when signed in as a data provider" do - let(:user) { FactoryBot.create(:user) } - - before do - sign_in user - get "/schemes/1" - end - - it "returns 401 unauthorized" do - request - expect(response).to have_http_status(:unauthorized) - end - end - - context "when signed in as a data coordinator" do - let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } - - before do - Timecop.freeze(Time.utc(2022, 10, 10)) - sign_in user - scheme.deactivation_date = deactivation_date - scheme.save! - get "/schemes/#{scheme.id}" - end - - context "with active scheme" do - let(:deactivation_date) { nil } - - it "renders deactivate this scheme" do - expect(response).to have_http_status(:ok) - expect(page).to have_link("Deactivate this scheme", href: "/schemes/#{scheme.id}/deactivate") - end - end - - context "with deactivated scheme" do - let(:deactivation_date) { Time.utc(2022, 10, 9) } - - it "renders reactivate this scheme" do - expect(response).to have_http_status(:ok) - expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{scheme.id}/reactivate") - end - end - - context "with scheme that's deactivating soon" do - let(:deactivation_date) { Time.utc(2022, 10, 12) } - - it "renders reactivate this scheme" do - expect(response).to have_http_status(:ok) - expect(page).to have_link("Reactivate this scheme", href: "/schemes/#{scheme.id}/reactivate") - end - end - end - end end