From 48e20d557a72631a1eb4c4c49be2b91633957ae8 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Thu, 1 Dec 2022 15:09:46 +0000 Subject: [PATCH] test: add test for invalid owning org id (invalid as doesn't hold stock) --- spec/requests/schemes_controller_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index ff27fe821..a2877c415 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -585,6 +585,21 @@ RSpec.describe SchemesController, type: :request do expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid")) end end + + context "when organisation id param refers to a non-stock-owning organisation" do + let(:organisation_which_does_not_own_stock) { FactoryBot.create(:organisation, holds_own_stock: false) } + let(:params) do + { scheme: { + owning_organisation_id: organisation_which_does_not_own_stock.id, + } } + end + + it "displays the new page with an error message" do + post "/schemes", params: params + expect(response).to have_http_status(:unprocessable_entity) + expect(page).to have_content(I18n.t("validations.scheme.owning_organisation.does_not_own_stock")) + end + end end end