Browse Source

Add test case for controller, check if the scheme is confirmed before displaying

pull/775/head
Kat 3 years ago
parent
commit
074e4dffb1
  1. 2
      app/models/form/setup/questions/scheme_id.rb
  2. 2
      spec/features/schemes_spec.rb
  3. 1
      spec/requests/schemes_controller_spec.rb

2
app/models/form/setup/questions/scheme_id.rb

@ -21,7 +21,7 @@ class Form::Setup::Questions::SchemeId < ::Form::Question
def displayed_answer_options(case_log)
organisation = case_log.owning_organisation || case_log.created_by&.organisation
schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id).where.not(managing_organisation_id: nil) : Scheme.select(:id).where.not(managing_organisation_id: nil)
schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id).where(confirmed: true) : Scheme.select(:id).where(confirmed: true)
filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id)
answer_options.select do |k, _v|
filtered_scheme_ids.include?(k.to_i) || k.blank?

2
spec/features/schemes_spec.rb

@ -888,7 +888,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does display the schemes that are not completed" do
schemes[2].update!(managing_organisation_id: nil)
schemes[2].update!(confirmed: false)
visit("/logs/#{case_log.id}/scheme")
expect(find("#case-log-scheme-id-field").all("option").count).to eq(3)
end

1
spec/requests/schemes_controller_spec.rb

@ -1078,6 +1078,7 @@ RSpec.describe SchemesController, type: :request do
expect(scheme_to_update.reload.scheme_type).to eq("Foyer")
expect(scheme_to_update.reload.sensitive).to eq("Yes")
expect(scheme_to_update.reload.registered_under_care_act).to eq("No")
expect(scheme_to_update.reload.managing_organisation_id).to eq(scheme_to_update.owning_organisation_id)
end
end
end

Loading…
Cancel
Save