diff --git a/app/controllers/campaigns/new_controller.rb b/app/controllers/campaigns/edit_controller.rb similarity index 61% rename from app/controllers/campaigns/new_controller.rb rename to app/controllers/campaigns/edit_controller.rb index 5e3392e56f..3715bd1612 100644 --- a/app/controllers/campaigns/new_controller.rb +++ b/app/controllers/campaigns/edit_controller.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true -class Campaigns::NewController < ApplicationController +class Campaigns::EditController < ApplicationController include Wicked::Wizard before_action :set_campaign before_action :set_steps before_action :setup_wizard - skip_after_action :verify_policy_scoped - def show render_wizard end @@ -18,6 +16,12 @@ def update @campaign.assign_attributes(wizard_step: step, **params) + if current_step?(:details) && @campaign.type_changed? + @campaign.vaccines = Vaccine.active.where(type: @campaign.type) + end + + jump_to(:confirm) if @campaign.active && !current_step?(:confirm) + render_wizard(@campaign) end @@ -25,9 +29,7 @@ def update def set_campaign @campaign = - policy_scope(Campaign).where( - active: params[:id] == Wicked::FINISH_STEP - ).find(params[:campaign_id]) + policy_scope(Campaign).includes(:vaccines).find(params[:campaign_id]) end def set_steps @@ -46,7 +48,11 @@ def dates_params params.require(:campaign).permit(:start_date, :end_date) end + def vaccines_params + params.require(:campaign).permit(vaccine_ids: []) + end + def confirm_params - { active: true, vaccines: Vaccine.active.where(type: @campaign.type) } + { active: true } end end diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 489ded091d..6a8c69dd5e 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -13,11 +13,7 @@ def index def create campaign = Campaign.create!(team: current_user.team) - - redirect_to campaign_new_path( - campaign_id: campaign.id, - id: campaign.wizard_steps.first - ) + redirect_to campaign_edit_path(campaign, Wicked::FIRST_STEP) end def show diff --git a/app/models/campaign.rb b/app/models/campaign.rb index dda5fbb6ec..ede63bbb68 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -48,69 +48,73 @@ class Campaign < ApplicationRecord normalizes :name, with: ->(name) { name&.strip } - validates :name, - uniqueness: { - scope: %i[type academic_year team_id], - allow_nil: true - } - - validates :academic_year, - comparison: { - greater_than_or_equal_to: 2000, - less_than_or_equal_to: Time.zone.today.year + 5, - allow_nil: true - } - - validates :start_date, - comparison: { - greater_than_or_equal_to: :first_possible_start_date, - if: :academic_year, - allow_nil: true - } - - validates :end_date, - comparison: { - greater_than_or_equal_to: :start_date, - less_than_or_equal_to: :last_possible_end_date, - if: -> { academic_year && start_date }, - allow_nil: true - } - - validate :vaccines_match_type - on_wizard_step :details do - validates :name, presence: true + validates :name, + presence: true, + uniqueness: { + scope: %i[type academic_year team_id], + allow_nil: true + } + validates :type, presence: true - validates :academic_year, presence: true + + validates :academic_year, + comparison: { + greater_than_or_equal_to: 2000, + less_than_or_equal_to: Time.zone.today.year + 5 + } end on_wizard_step :dates do - validates :start_date, presence: true - validates :end_date, presence: true + validates :start_date, + comparison: { + greater_than_or_equal_to: :first_possible_start_date, + less_than: :end_date + } + + validates :end_date, + comparison: { + greater_than: :start_date, + less_than_or_equal_to: :last_possible_end_date + } + end + + on_wizard_step :vaccines do + validates :vaccines, presence: true end on_wizard_step :confirm do validates :active, presence: true end + validate :vaccines_match_type + def wizard_steps - %i[details dates confirm] + [:details, :dates, (:vaccines if active), :confirm].compact + end + + def vaccine_ids + @vaccine_ids ||= vaccines.map(&:id) + end + + def vaccine_ids=(ids) + self.vaccines = Vaccine.where(id: ids) end private def first_possible_start_date - Date.new(academic_year, 1, 1) + Date.new(academic_year || 2000, 1, 1) end def last_possible_end_date - Date.new(academic_year + 1, 12, 31) + Date.new((academic_year || 2000) + 1, 12, 31) end def vaccines_match_type vaccine_types = vaccines.map(&:type).uniq unless vaccine_types.empty? || vaccine_types == [type] - errors.add(:vaccines, "must match programme type") + errors.add(:vaccines, :match_type) end end end diff --git a/app/views/campaigns/edit/confirm.html.erb b/app/views/campaigns/edit/confirm.html.erb new file mode 100644 index 0000000000..8c66d284b0 --- /dev/null +++ b/app/views/campaigns/edit/confirm.html.erb @@ -0,0 +1,58 @@ +<% content_for :before_main do %> + <%= render AppBacklinkComponent.new( + href: @campaign.active ? campaign_path(@campaign) : previous_wizard_path, + name: @campaign.active ? @campaign.name : "#{@previous_step} page of programme creation", + ) %> +<% end %> + +<%= form_with model: @campaign, url: wizard_path, method: :put do |f| %> + <%= f.govuk_error_summary %> + + <%= h1 @campaign.active ? "Edit programme" : "Check and confirm" %> + + <%= render AppCardComponent.new do |card| %> + <% card.with_heading { @campaign.active ? "Programme details" : "New programme details" } %> + + <%= govuk_summary_list do |summary_list| %> + <%= summary_list.with_row do |row| %> + <%= row.with_key { "Name" } %> + <%= row.with_value { @campaign.name } %> + <%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :details), visually_hidden_text: "name") %> + <% end %> + + <%= summary_list.with_row do |row| %> + <%= row.with_key { "Programme type" } %> + <%= row.with_value { @campaign.human_enum_name(:type) } %> + <%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :details), visually_hidden_text: "programme type") %> + <% end %> + + <%= summary_list.with_row do |row| %> + <%= row.with_key { "Academic year" } %> + <%= row.with_value { campaign_academic_year(@campaign) } %> + <%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :details), visually_hidden_text: "academic year") %> + <% end %> + + <%= summary_list.with_row do |row| %> + <%= row.with_key { "Start date" } %> + <%= row.with_value { @campaign.start_date.to_fs(:long) } %> + <%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :dates), visually_hidden_text: "start date") %> + <% end %> + + <%= summary_list.with_row do |row| %> + <%= row.with_key { "End date" } %> + <%= row.with_value { @campaign.end_date.to_fs(:long) } %> + <%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :dates), visually_hidden_text: "end date") %> + <% end %> + + <% if @campaign.active %> + <%= summary_list.with_row do |row| %> + <%= row.with_key { "Vaccines" } %> + <%= row.with_value { @campaign.vaccines.map(&:brand).join("
").html_safe } %> + <%= row.with_action(text: "Change", href: campaign_edit_path(@campaign, :vaccines), visually_hidden_text: "vaccines") %> + <% end %> + <% end %> + <% end %> + <% end %> + + <%= f.govuk_submit "Save changes" %> +<% end %> diff --git a/app/views/campaigns/new/dates.html.erb b/app/views/campaigns/edit/dates.html.erb similarity index 68% rename from app/views/campaigns/new/dates.html.erb rename to app/views/campaigns/edit/dates.html.erb index 4e06dad2af..e823d97d43 100644 --- a/app/views/campaigns/new/dates.html.erb +++ b/app/views/campaigns/edit/dates.html.erb @@ -1,7 +1,7 @@ <% content_for :before_main do %> <%= render AppBacklinkComponent.new( - href: previous_wizard_path, - name: "#{@previous_step} page of programme creation", + href: @campaign.active ? campaign_edit_path(@campaign, :confirm) : previous_wizard_path, + name: @campaign.active ? "edit programme" : "#{@previous_step} page of programme creation", ) %> <% end %> diff --git a/app/views/campaigns/new/details.html.erb b/app/views/campaigns/edit/details.html.erb similarity index 80% rename from app/views/campaigns/new/details.html.erb rename to app/views/campaigns/edit/details.html.erb index cbbe5651ee..0f01a796b8 100644 --- a/app/views/campaigns/new/details.html.erb +++ b/app/views/campaigns/edit/details.html.erb @@ -1,5 +1,8 @@ <% content_for :before_main do %> - <%= render AppBacklinkComponent.new(href: campaigns_path, name: "programme") %> + <%= render AppBacklinkComponent.new( + href: @campaign.active ? campaign_edit_path(@campaign, :confirm) : campaigns_path, + name: @campaign.active ? "edit programme" : "vaccination programmes", + ) %> <% end %> <%= form_with model: @campaign, url: wizard_path, method: :put do |f| %> diff --git a/app/views/campaigns/edit/vaccines.html.erb b/app/views/campaigns/edit/vaccines.html.erb new file mode 100644 index 0000000000..74e20535a9 --- /dev/null +++ b/app/views/campaigns/edit/vaccines.html.erb @@ -0,0 +1,18 @@ +<% content_for :before_main do %> + <%= render AppBacklinkComponent.new( + href: @campaign.active ? campaign_edit_path(@campaign, :confirm) : previous_wizard_path, + name: @campaign.active ? "edit programme" : "#{@previous_step} page of programme creation", + ) %> +<% end %> + +<% title = "Which vaccine(s) does this programme administer?" %> + +<% content_for :page_title, title %> + +<%= form_with model: @campaign, url: wizard_path, method: :put do |f| %> + <%= f.govuk_error_summary %> + + <%= f.govuk_collection_check_boxes :vaccine_ids, Vaccine.where(type: @campaign.type), :id, :brand, legend: { text: title, tag: "h1", size: "l" } %> + + <%= f.govuk_submit %> +<% end %> diff --git a/app/views/campaigns/index.html.erb b/app/views/campaigns/index.html.erb index af47aa4a4b..4a7dd62786 100644 --- a/app/views/campaigns/index.html.erb +++ b/app/views/campaigns/index.html.erb @@ -28,9 +28,7 @@ <% end %> <% row.with_cell do %> Vaccines - <%= campaign.vaccines - .map { |vaccine| vaccine.brand } - .join("
").html_safe %> + <%= campaign.vaccines.map(&:brand).join("
").html_safe %> <% end %> <% end %> <% end %> diff --git a/app/views/campaigns/new/confirm.html.erb b/app/views/campaigns/new/confirm.html.erb deleted file mode 100644 index 0e992abce2..0000000000 --- a/app/views/campaigns/new/confirm.html.erb +++ /dev/null @@ -1,45 +0,0 @@ -<% content_for :before_main do %> - <%= render AppBacklinkComponent.new( - href: previous_wizard_path, - name: "#{@previous_step} page of programme creation", - ) %> -<% end %> - -<%= form_with model: @campaign, url: wizard_path, method: :put do |f| %> - <%= f.govuk_error_summary %> - - <%= h1 "Check and confirm" %> - - <%= render AppCardComponent.new do |card| %> - <% card.with_heading { "New programme details" } %> - - <%= govuk_summary_list do |summary_list| %> - <%= summary_list.with_row do |row| %> - <%= row.with_key { "Name" } %> - <%= row.with_value { @campaign.name } %> - <% end %> - - <%= summary_list.with_row do |row| %> - <%= row.with_key { "Type" } %> - <%= row.with_value { @campaign.human_enum_name(:type) } %> - <% end %> - - <%= summary_list.with_row do |row| %> - <%= row.with_key { "Academic year" } %> - <%= row.with_value { campaign_academic_year(@campaign) } %> - <% end %> - - <%= summary_list.with_row do |row| %> - <%= row.with_key { "Start date" } %> - <%= row.with_value { @campaign.start_date.to_fs(:long) } %> - <% end %> - - <%= summary_list.with_row do |row| %> - <%= row.with_key { "End date" } %> - <%= row.with_value { @campaign.end_date.to_fs(:long) } %> - <% end %> - <% end %> - <% end %> - - <%= f.govuk_submit "Save changes" %> -<% end %> diff --git a/app/views/campaigns/show.html.erb b/app/views/campaigns/show.html.erb index a7e645085a..f6275f3392 100644 --- a/app/views/campaigns/show.html.erb +++ b/app/views/campaigns/show.html.erb @@ -27,3 +27,9 @@ href: campaign_immunisation_imports_path(@campaign), ) end %> + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 18f8a46c8d..45c8bbf40c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -203,6 +203,9 @@ en: type: blank: Choose a programme type inclusion: Choose a programme type + vaccines: + blank: Choose the vaccines this programme administers + match_type: Vaccines must be suitable for the programme type consent: attributes: new_or_existing_parent: diff --git a/config/routes.rb b/config/routes.rb index c0dea6ea0b..e5109702b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,10 +66,10 @@ resources :campaigns, only: %i[index create show] do get "sessions", on: :member - resource :new, - controller: "campaigns/new", + resource :edit, + controller: "campaigns/edit", only: %i[show update], - path: "new/:id" + path: "edit/:id" resources :immunisation_imports, path: "immunisation-imports", diff --git a/spec/features/create_and_edit_campaigns_spec.rb b/spec/features/create_and_edit_campaigns_spec.rb new file mode 100644 index 0000000000..a6e3730217 --- /dev/null +++ b/spec/features/create_and_edit_campaigns_spec.rb @@ -0,0 +1,280 @@ +# frozen_string_literal: true + +describe "Create and edit campaigns" do + before { given_i_am_signed_in } + + scenario "User creates a Flu campaign" do + given_active_flu_vaccines_exist + and_discontinued_flu_vaccines_exist + + when_i_go_to_the_campaigns_page + and_i_click_on_the_new_campaign_button + then_i_should_see_the_details_page + + when_i_fill_in_flu_details + and_i_click_continue + then_i_should_see_the_dates_page + + when_i_fill_in_the_dates + and_i_click_continue + then_i_should_see_the_new_confirm_page + + when_i_confirm_the_campaign + then_i_should_see_the_campaign_page + and_i_should_see_the_flu_campaign + + when_i_go_to_the_campaigns_page + then_i_should_see_the_flu_campaign_and_vaccines + end + + scenario "User edits a Flu campaign" do + given_a_flu_campaign_exists + and_discontinued_flu_vaccines_exist + + when_i_go_to_the_campaigns_page + and_i_click_on_the_flu_campaign + and_i_click_edit_campaign + then_i_should_see_the_edit_confirm_page + + when_i_click_on_change_name + and_i_fill_in_flu_details + and_i_click_continue + then_i_should_see_the_edit_confirm_page + + when_i_click_on_change_start_date + and_i_fill_in_the_dates + and_i_click_continue + then_i_should_see_the_edit_confirm_page + + when_i_click_on_change_vaccines + and_i_select_the_flu_vaccines + and_i_click_continue + then_i_should_see_the_edit_confirm_page + + when_i_confirm_the_campaign + then_i_should_see_the_campaign_page + and_i_should_see_the_flu_campaign + end + + scenario "User creates an HPV campaign" do + given_active_hpv_vaccines_exist + and_discontinued_hpv_vaccines_exist + + when_i_go_to_the_campaigns_page + and_i_click_on_the_new_campaign_button + then_i_should_see_the_details_page + + when_i_fill_in_hpv_details + and_i_click_continue + then_i_should_see_the_dates_page + + when_i_fill_in_the_dates + and_i_click_continue + then_i_should_see_the_new_confirm_page + + when_i_confirm_the_campaign + then_i_should_see_the_campaign_page + and_i_should_see_the_hpv_campaign + + when_i_go_to_the_campaigns_page + then_i_should_see_the_hpv_campaign_and_vaccines + end + + scenario "User edits an HPV campaign" do + given_an_hpv_campaign_exists + and_discontinued_hpv_vaccines_exist + + when_i_go_to_the_campaigns_page + and_i_click_on_the_hpv_campaign + and_i_click_edit_campaign + then_i_should_see_the_edit_confirm_page + + when_i_click_on_change_name + and_i_fill_in_hpv_details + and_i_click_continue + then_i_should_see_the_edit_confirm_page + + when_i_click_on_change_start_date + and_i_fill_in_the_dates + and_i_click_continue + then_i_should_see_the_edit_confirm_page + + when_i_click_on_change_vaccines + and_i_select_the_hpv_vaccines + and_i_click_continue + then_i_should_see_the_edit_confirm_page + + when_i_confirm_the_campaign + then_i_should_see_the_campaign_page + and_i_should_see_the_hpv_campaign + end + + def given_i_am_signed_in + @team = create(:team, :with_one_nurse, ods_code: "R1L") + sign_in @team.users.first + end + + def given_active_flu_vaccines_exist + create(:vaccine, :adjuvanted_quadrivalent) + end + + def and_discontinued_flu_vaccines_exist + create(:vaccine, :fluad_tetra) + create(:vaccine, :flucelvax_tetra) + end + + def given_active_hpv_vaccines_exist + create(:vaccine, :gardasil_9) + end + + def and_discontinued_hpv_vaccines_exist + create(:vaccine, :cervarix) + create(:vaccine, :gardasil) + end + + def given_a_flu_campaign_exists + create( + :campaign, + :flu, + name: "Flu - to be renamed", + academic_year: 2024, + team: @team + ) + end + + def given_an_hpv_campaign_exists + create( + :campaign, + :hpv, + name: "HPV - to be renamed", + academic_year: 2024, + team: @team + ) + end + + def when_i_go_to_the_campaigns_page + visit "/dashboard" + click_on "Vaccination programmes", match: :first + end + + def and_i_click_on_the_new_campaign_button + click_on "Create a new vaccination programme" + end + + def then_i_should_see_the_details_page + expect(page).to have_content("Programme details") + end + + def when_i_fill_in_flu_details + fill_in "Name", with: "Flu" + choose "Flu" + choose "2025/26" + end + + alias_method :and_i_fill_in_flu_details, :when_i_fill_in_flu_details + + def when_i_fill_in_hpv_details + fill_in "Name", with: "HPV" + choose "HPV" + choose "2025/26" + end + + alias_method :and_i_fill_in_hpv_details, :when_i_fill_in_hpv_details + + def and_i_click_continue + click_on "Continue" + end + + def then_i_should_see_the_dates_page + expect(page).to have_content("When does this programme run?") + end + + def when_i_fill_in_the_dates + within all(".nhsuk-fieldset")[0] do + fill_in "Day", with: "1" + fill_in "Month", with: "09" + fill_in "Year", with: "2025" + end + + within all(".nhsuk-fieldset")[1] do + fill_in "Day", with: "31" + fill_in "Month", with: "05" + fill_in "Year", with: "2026" + end + end + + alias_method :and_i_fill_in_the_dates, :when_i_fill_in_the_dates + + def then_i_should_see_the_new_confirm_page + expect(page).to have_content("Check and confirm") + expect(page).to have_content("New programme details") + end + + def when_i_confirm_the_campaign + click_on "Save changes" + end + + def then_i_should_see_the_campaign_page + expect(page).to have_content("Vaccination programmes") + end + + def and_i_should_see_the_flu_campaign + expect(page).to have_content("Flu\n2025/26") + end + + def and_i_should_see_the_hpv_campaign + expect(page).to have_content("HPV\n2025/26") + end + + def then_i_should_see_the_flu_campaign_and_vaccines + expect(page).to have_content( + "Name Flu Academic year 2025/26 Vaccines Adjuvanted Quadrivalent - aQIV" + ) + end + + def then_i_should_see_the_hpv_campaign_and_vaccines + expect(page).to have_content( + "Name HPV Academic year 2025/26 Vaccines Gardasil 9" + ) + end + + def and_i_click_on_the_flu_campaign + click_on "Flu" + end + + def and_i_click_on_the_hpv_campaign + click_on "HPV" + end + + def and_i_click_edit_campaign + click_on "Edit programme" + end + + def then_i_should_see_the_edit_confirm_page + expect(page).to have_content("Edit programme") + expect(page).to have_content("Programme details") + expect(page).to have_content("Vaccines") + end + + def when_i_click_on_change_name + within(".nhsuk-summary-list__row", text: "Name") { click_on "Change" } + end + + def when_i_click_on_change_start_date + within(".nhsuk-summary-list__row", text: "Start date") { click_on "Change" } + end + + def when_i_click_on_change_vaccines + within(".nhsuk-summary-list__row", text: "Vaccines") { click_on "Change" } + end + + def and_i_select_the_flu_vaccines + check "Fluad Tetra - aQIV" + check "Flucelvax Tetra - QIVc" + end + + def and_i_select_the_hpv_vaccines + check "Cervarix" + check "Gardasil" + end +end diff --git a/spec/features/create_campaign_spec.rb b/spec/features/create_campaign_spec.rb deleted file mode 100644 index 44aef1e9d1..0000000000 --- a/spec/features/create_campaign_spec.rb +++ /dev/null @@ -1,142 +0,0 @@ -# frozen_string_literal: true - -describe "Create campaign" do - before do - given_i_am_signed_in - and_active_and_discontinued_vaccines_exist - end - - scenario "User creates a Flu campaign" do - when_i_go_to_the_campaigns_page - and_i_click_on_the_new_campaign_button - then_i_should_see_the_details_page - - when_i_fill_in_flu_details - and_i_click_continue - then_i_should_see_the_dates_page - - when_i_fill_in_the_dates - and_i_click_continue - then_i_should_see_the_confirm_page - - when_i_confirm_the_campaign - then_i_should_see_the_campaign_page - and_i_should_see_the_flu_campaign - - when_i_go_to_the_campaigns_page - then_i_should_see_the_flu_campaign_and_vaccines - end - - scenario "User creates an HPV campaign" do - when_i_go_to_the_campaigns_page - and_i_click_on_the_new_campaign_button - then_i_should_see_the_details_page - - when_i_fill_in_hpv_details - and_i_click_continue - then_i_should_see_the_dates_page - - when_i_fill_in_the_dates - and_i_click_continue - then_i_should_see_the_confirm_page - - when_i_confirm_the_campaign - then_i_should_see_the_campaign_page - and_i_should_see_the_hpv_campaign - - when_i_go_to_the_campaigns_page - then_i_should_see_the_hpv_campaign_and_vaccines - end - - def given_i_am_signed_in - @team = create(:team, :with_one_nurse, ods_code: "R1L") - sign_in @team.users.first - end - - def and_active_and_discontinued_vaccines_exist - create(:vaccine, :gardasil_9) - create(:vaccine, :gardasil) - - create(:vaccine, :fluenz_tetra) - create(:vaccine, :fluad_tetra) - end - - def when_i_go_to_the_campaigns_page - visit "/dashboard" - click_on "Vaccination programmes", match: :first - end - - def and_i_click_on_the_new_campaign_button - click_on "Create a new vaccination programme" - end - - def then_i_should_see_the_details_page - expect(page).to have_content("Programme details") - end - - def when_i_fill_in_flu_details - fill_in "Name", with: "Flu" - choose "Flu" - choose "2025/26" - end - - def when_i_fill_in_hpv_details - fill_in "Name", with: "HPV" - choose "HPV" - choose "2025/26" - end - - def and_i_click_continue - click_on "Continue" - end - - def then_i_should_see_the_dates_page - expect(page).to have_content("When does this programme run?") - end - - def when_i_fill_in_the_dates - within all(".nhsuk-fieldset")[0] do - fill_in "Day", with: "1" - fill_in "Month", with: "09" - fill_in "Year", with: "2025" - end - - within all(".nhsuk-fieldset")[1] do - fill_in "Day", with: "31" - fill_in "Month", with: "05" - fill_in "Year", with: "2026" - end - end - - def then_i_should_see_the_confirm_page - expect(page).to have_content("Check and confirm") - end - - def when_i_confirm_the_campaign - click_on "Save changes" - end - - def then_i_should_see_the_campaign_page - expect(page).to have_content("Vaccination programmes") - end - - def and_i_should_see_the_flu_campaign - expect(page).to have_content("Flu\n2025/26") - end - - def and_i_should_see_the_hpv_campaign - expect(page).to have_content("HPV\n2025/26") - end - - def then_i_should_see_the_flu_campaign_and_vaccines - expect(page).to have_content( - "Name Flu Academic year 2025/26 Vaccines Fluenz Tetra - LAIV" - ) - end - - def then_i_should_see_the_hpv_campaign_and_vaccines - expect(page).to have_content( - "Name HPV Academic year 2025/26 Vaccines Gardasil 9" - ) - end -end diff --git a/spec/models/campaign_spec.rb b/spec/models/campaign_spec.rb index e4b9be24c1..f29e49f208 100644 --- a/spec/models/campaign_spec.rb +++ b/spec/models/campaign_spec.rb @@ -26,7 +26,12 @@ describe Campaign, type: :model do subject(:campaign) do - build(:campaign, academic_year: 2024, start_date: Date.new(2024, 6, 1)) + build( + :campaign, + academic_year: 2024, + start_date: Date.new(2024, 9, 1), + end_date: Date.new(2025, 7, 31) + ) end it { should normalize(:name).from(" abc ").to("abc") } @@ -40,29 +45,28 @@ it { should validate_presence_of(:academic_year).on(:update) } it do - expect(campaign).to validate_comparison_of( - :academic_year - ).is_greater_than_or_equal_to(2000).is_less_than_or_equal_to( - Time.zone.today.year + 5 - ) + expect(campaign).to validate_comparison_of(:academic_year) + .on(:update) + .is_greater_than_or_equal_to(2000) + .is_less_than_or_equal_to(Time.zone.today.year + 5) end it { should validate_presence_of(:start_date).on(:update) } it do - expect(campaign).to validate_comparison_of( - :start_date - ).is_greater_than_or_equal_to(Date.new(2024, 1, 1)) + expect(campaign).to validate_comparison_of(:start_date) + .on(:update) + .is_greater_than_or_equal_to(Date.new(2024, 1, 1)) + .is_less_than(Date.new(2025, 7, 31)) end it { should validate_presence_of(:end_date).on(:update) } it do - expect(campaign).to validate_comparison_of( - :end_date - ).is_greater_than_or_equal_to( - Date.new(2024, 6, 1) - ).is_less_than_or_equal_to(Date.new(2025, 12, 31)) + expect(campaign).to validate_comparison_of(:end_date) + .on(:update) + .is_greater_than(Date.new(2024, 9, 1)) + .is_less_than_or_equal_to(Date.new(2025, 12, 31)) end context "when vaccines don't match type" do @@ -73,7 +77,7 @@ it "is invalid" do expect(campaign).to be_invalid expect(campaign.errors[:vaccines]).to include( - "must match programme type" + /must be suitable for the programme type/ ) end end