From 057d50976dc409b1db07265ac5907b91709dc592 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 2 Dec 2022 10:24:56 +0000 Subject: [PATCH] test: add more startdate tests --- spec/requests/locations_controller_spec.rb | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index dda30db3b..5a721aa01 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1081,6 +1081,36 @@ RSpec.describe LocationsController, type: :request do end end + context "when startdate is submitted with leading zeroes" do + let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "01", "startdate(3i)": "02" } } } + + before do + patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: + end + + it "adds startdate correctly " do + expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) + end + + it "redirects correctly" do + follow_redirect! + expect(page).to have_content("Check your answers") + end + end + + context "when startdate is missing" do + let(:params) { { location: { "startdate(1i)": "", "startdate(2i)": "", "startdate(3i)": "" } } } + + before do + patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: + end + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.location.startdate_blank")) + end + end + context "when trying to edit startdate of location that belongs to another organisation" do let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_location) { FactoryBot.create(:location, scheme: another_scheme) } @@ -1125,6 +1155,36 @@ RSpec.describe LocationsController, type: :request do end end + context "when startdate is submitted with leading zeroes" do + let(:params) { { location: { "startdate(1i)": "2000", "startdate(2i)": "01", "startdate(3i)": "02" } } } + + before do + patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: + end + + it "adds startdate correctly " do + expect(Location.last.startdate).to eq(Time.zone.local(2000, 1, 2)) + end + + it "redirects correctly" do + follow_redirect! + expect(page).to have_content("Check your answers") + end + end + + context "when startdate is missing" do + let(:params) { { location: { "startdate(1i)": "", "startdate(2i)": "", "startdate(3i)": "" } } } + + before do + patch "/schemes/#{scheme.id}/locations/#{location.id}/availability", params: + end + + it "displays the new page with an error message" do + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.location.startdate_blank")) + end + end + context "when the requested location does not exist" do let(:location) { OpenStruct.new(id: (Location.maximum(:id) || 0) + 1, scheme:) }