Browse Source

feat: test when location is confirmed

pull/1455/head
natdeanlewissoftwire 3 years ago
parent
commit
1af137eaf1
  1. 38
      spec/requests/locations_controller_spec.rb

38
spec/requests/locations_controller_spec.rb

@ -1263,6 +1263,8 @@ RSpec.describe LocationsController, type: :request do
patch "/schemes/#{scheme.id}/locations/#{location.id}/confirm", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/confirm", params:
end end
context "when location is complete" do
it "confirms location" do it "confirms location" do
expect(Location.last.confirmed).to eq(true) expect(Location.last.confirmed).to eq(true)
end end
@ -1274,6 +1276,23 @@ RSpec.describe LocationsController, type: :request do
end end
end end
context "when location is not complete" do
let(:location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2000, 1, 1), postcode: nil) }
it "confirms location" do
expect(Location.last.confirmed).to eq(false)
end
it "redirects correctly and does not display success banner" do
follow_redirect!
expect(page).not_to have_content("Success")
expect(page).not_to have_content("added to this scheme")
end
end
end
context "when trying to edit check_answers of location that belongs to another organisation" do context "when trying to edit check_answers of location that belongs to another organisation" do
let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_scheme) { FactoryBot.create(:scheme) }
let(:another_location) { FactoryBot.create(:location, scheme: another_scheme) } let(:another_location) { FactoryBot.create(:location, scheme: another_scheme) }
@ -1308,6 +1327,8 @@ RSpec.describe LocationsController, type: :request do
patch "/schemes/#{scheme.id}/locations/#{location.id}/confirm", params: patch "/schemes/#{scheme.id}/locations/#{location.id}/confirm", params:
end end
context "when location is complete" do
it "confirms location" do it "confirms location" do
expect(Location.last.confirmed).to eq(true) expect(Location.last.confirmed).to eq(true)
end end
@ -1319,6 +1340,23 @@ RSpec.describe LocationsController, type: :request do
end end
end end
context "when location is not complete" do
let(:location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2000, 1, 1), postcode: nil) }
it "confirms location" do
expect(Location.last.confirmed).to eq(false)
end
it "redirects correctly and does not display success banner" do
follow_redirect!
expect(page).not_to have_content("Success")
expect(page).not_to have_content("added to this scheme")
end
end
end
context "when the requested location does not exist" do context "when the requested location does not exist" do
let(:location) { OpenStruct.new(id: (Location.maximum(:id) || 0) + 1, scheme:) } let(:location) { OpenStruct.new(id: (Location.maximum(:id) || 0) + 1, scheme:) }

Loading…
Cancel
Save