|
|
|
@ -1825,6 +1825,11 @@ RSpec.describe LocationsController, type: :request do |
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-reactivation") |
|
|
|
expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-reactivation") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not render delete this location" do |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "with location that's deactivating soon" do |
|
|
|
context "with location that's deactivating soon" do |
|
|
|
@ -1883,6 +1888,86 @@ RSpec.describe LocationsController, type: :request do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when signed in as a support user" do |
|
|
|
|
|
|
|
let(:user) { create(:user, :support) } |
|
|
|
|
|
|
|
let(:scheme) { create(:scheme) } |
|
|
|
|
|
|
|
let(:location) { create(:location, scheme:) } |
|
|
|
|
|
|
|
let(:add_deactivations) { location.location_deactivation_periods << location_deactivation_period } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.utc(2022, 10, 10)) |
|
|
|
|
|
|
|
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
|
|
|
|
|
|
|
sign_in user |
|
|
|
|
|
|
|
add_deactivations |
|
|
|
|
|
|
|
location.save! |
|
|
|
|
|
|
|
get "/schemes/#{scheme.id}/locations/#{location.id}" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with active location" do |
|
|
|
|
|
|
|
let(:add_deactivations) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not render delete this location" do |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with deactivated location" do |
|
|
|
|
|
|
|
let(:location_deactivation_period) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), location:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "renders delete this location" do |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with incomplete location" do |
|
|
|
|
|
|
|
let(:add_deactivations) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
location.update!(units: nil) |
|
|
|
|
|
|
|
get "/schemes/#{scheme.id}/locations/#{location.id}" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "renders delete this location" do |
|
|
|
|
|
|
|
expect(location.reload.status).to eq(:incomplete) |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with location that's deactivating soon" do |
|
|
|
|
|
|
|
let(:location_deactivation_period) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 12), location:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not render delete this location" do |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with location that's deactivating in more than 6 months" do |
|
|
|
|
|
|
|
let(:location_deactivation_period) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 12), location:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not render delete this location" do |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with location that's reactivating soon" do |
|
|
|
|
|
|
|
let(:location_deactivation_period) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 12), reactivation_date: Time.zone.local(2022, 10, 12), location:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not render delete this location" do |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
|
|
|
|
expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "#reactivate" do |
|
|
|
describe "#reactivate" do |
|
|
|
@ -2057,11 +2142,18 @@ RSpec.describe LocationsController, type: :request do |
|
|
|
|
|
|
|
|
|
|
|
context "when signed in" do |
|
|
|
context "when signed in" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.utc(2022, 10, 10)) |
|
|
|
|
|
|
|
location.location_deactivation_periods << create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), location:) |
|
|
|
|
|
|
|
location.save! |
|
|
|
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
|
|
|
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
|
|
|
sign_in user |
|
|
|
sign_in user |
|
|
|
get "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation" |
|
|
|
get "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "with a data provider user" do |
|
|
|
context "with a data provider user" do |
|
|
|
let(:user) { create(:user) } |
|
|
|
let(:user) { create(:user) } |
|
|
|
|
|
|
|
|
|
|
|
@ -2116,9 +2208,16 @@ RSpec.describe LocationsController, type: :request do |
|
|
|
let(:location) { create(:location, scheme:, name: "Location to delete", created_at: Time.zone.local(2022, 4, 1)) } |
|
|
|
let(:location) { create(:location, scheme:, name: "Location to delete", created_at: Time.zone.local(2022, 4, 1)) } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.utc(2022, 10, 10)) |
|
|
|
|
|
|
|
location.location_deactivation_periods << create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 9), location:) |
|
|
|
|
|
|
|
location.save! |
|
|
|
delete "/schemes/#{scheme.id}/locations/#{location.id}/delete" |
|
|
|
delete "/schemes/#{scheme.id}/locations/#{location.id}/delete" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when not signed in" do |
|
|
|
context "when not signed in" do |
|
|
|
it "redirects to the sign in page" do |
|
|
|
it "redirects to the sign in page" do |
|
|
|
expect(response).to redirect_to("/account/sign-in") |
|
|
|
expect(response).to redirect_to("/account/sign-in") |
|
|
|
|