diff --git a/app/models/form.rb b/app/models/form.rb index 3ab473a3b..caaaab7df 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -2,7 +2,7 @@ class Form < ApplicationRecord include FormStateMachine extend Mobility - self.ignored_columns += [:language] + self.ignored_columns += %i[language submission_type submission_format send_daily_submission_batch send_weekly_submission_batch] SUPPORTED_LANGUAGES = %w[en cy].freeze @@ -32,26 +32,14 @@ class Form < ApplicationRecord :what_happens_next_markdown, :payment_url - enum :submission_type, { - email: "email", - s3: "s3", - } - enum :send_copy_of_answers, { disabled: "disabled", enabled: "enabled", }, prefix: :send_copy_of_answers - # ActiveRecord doesn't support enums with arrays - # enum :submission_format, { - # csv: "csv", - # json: "json", - # } - validates :name, presence: true validates :payment_url, url: true, allow_blank: true validate :marking_complete_with_errors - validates :submission_type, presence: true validates :send_copy_of_answers, presence: true validates :available_languages, presence: true, inclusion: { in: SUPPORTED_LANGUAGES } validates :submission_email, email_address: { message: :invalid_email }, allow_blank: true diff --git a/app/models/form_document/content.rb b/app/models/form_document/content.rb index e1b5d009f..904291b69 100644 --- a/app/models/form_document/content.rb +++ b/app/models/form_document/content.rb @@ -21,8 +21,6 @@ class FormDocument::Content attribute :support_email, :string attribute :support_phone, :string attribute :s3_bucket_name, :string - attribute :submission_type, :string - attribute :submission_format, array: true attribute :declaration_text, :string attribute :declaration_markdown, :string attribute :s3_bucket_region, :string @@ -31,8 +29,6 @@ class FormDocument::Content attribute :privacy_policy_url, :string attribute :s3_bucket_aws_account_id, :string attribute :what_happens_next_markdown, :string - attribute :send_daily_submission_batch, :boolean - attribute :send_weekly_submission_batch, :boolean attribute :send_copy_of_answers, :string attribute :delivery_configurations, array: true diff --git a/db/seeds.rb b/db/seeds.rb index 632692ab8..71f4256ae 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -300,8 +300,6 @@ support_phone: "08000800", what_happens_next_markdown: "Test", share_preview_completed: true, - submission_type: "s3", - submission_format: %w[csv], s3_bucket_region: "eu-west-2", s3_bucket_name: "govuk-forms-submissions-to-s3-test", s3_bucket_aws_account_id: "711966560482", diff --git a/lib/tasks/data_migrations.rake b/lib/tasks/data_migrations.rake deleted file mode 100644 index 956d3389b..000000000 --- a/lib/tasks/data_migrations.rake +++ /dev/null @@ -1,60 +0,0 @@ -namespace :data_migrations do - desc "create delivery configurations for existing forms" - task create_delivery_configurations: :environment do - updated_count = 0 - - Form.all.find_each do |form| - form.delivery_configurations.find_or_create_by!( - delivery_method: form.submission_type, - formats: form.submission_format, - delivery_schedule: "immediate", - ) - - if form.send_daily_submission_batch - form.delivery_configurations.find_or_create_by!( - delivery_method: "email", - formats: %w[csv], - delivery_schedule: "daily", - ) - end - - if form.send_weekly_submission_batch - form.delivery_configurations.find_or_create_by!( - delivery_method: "email", - formats: %w[csv], - delivery_schedule: "weekly", - ) - end - - form.form_documents.each do |form_document| - add_delivery_configurations_to_form_document(form, form_document) - end - - updated_count += 1 - end - - Rails.logger.info("Updated #{updated_count} forms") - end -end - -def add_delivery_configurations_to_form_document(form, form_document) - content = form_document.content - - delivery_configurations = [] - - delivery_method = content["submission_type"] - formats = content["submission_format"] - delivery_configurations << DeliveryConfiguration.new(form:, delivery_method:, formats:, delivery_schedule: "immediate") - - if content["send_daily_submission_batch"] - delivery_configurations << DeliveryConfiguration.new(form:, delivery_method: "email", formats: %w[csv], delivery_schedule: "daily") - end - - if content["send_weekly_submission_batch"] - delivery_configurations << DeliveryConfiguration.new(form:, delivery_method: "email", formats: %w[csv], delivery_schedule: "weekly") - end - - content["delivery_configurations"] = delivery_configurations - - form_document.save! -end diff --git a/spec/factories/models/forms.rb b/spec/factories/models/forms.rb index 40ad9457b..aae255bbb 100644 --- a/spec/factories/models/forms.rb +++ b/spec/factories/models/forms.rb @@ -2,8 +2,6 @@ factory :form, class: "Form" do sequence(:name) { |n| "Form #{n}" } submission_email { Faker::Internet.email(domain: "example.gov.uk") } - submission_type { "email" } - submission_format { [] } privacy_policy_url { Faker::Internet.url(host: "gov.uk") } support_email { nil } support_phone { nil } @@ -18,8 +16,6 @@ state { :draft } payment_url { nil } external_id { nil } - send_daily_submission_batch { false } - send_weekly_submission_batch { false } send_copy_of_answers { "disabled" } brand_id { nil } s3_bucket_aws_account_id { nil } diff --git a/spec/lib/tasks/data_migrations.rake_spec.rb b/spec/lib/tasks/data_migrations.rake_spec.rb deleted file mode 100644 index 3c491f4d9..000000000 --- a/spec/lib/tasks/data_migrations.rake_spec.rb +++ /dev/null @@ -1,128 +0,0 @@ -require "rails_helper" - -RSpec.describe "data_migrations.rake", type: :task do - describe "data_migrations:create_delivery_configurations" do - subject(:task) do - Rake::Task["data_migrations:create_delivery_configurations"] - end - - let(:form) do - create(:form, :live_with_draft, submission_type: "email", submission_format: %w[csv json]) - end - - let!(:draft_form_document) do - form.draft_form_document - end - - it "has no delivery configurations before the task is run" do - expect(form.delivery_configurations).to be_empty - end - - it "creates a delivery configuration for the form" do - task.invoke - - expect(form.reload.delivery_configurations.pluck(:delivery_method, :delivery_schedule, :formats)).to contain_exactly( - ["email", "immediate", %w[csv json]], - ) - end - - it "updates the draft form document" do - task.invoke - - expect(draft_form_document.reload.content["delivery_configurations"]).to contain_exactly( - { - "delivery_method" => "email", - "delivery_schedule" => "immediate", - "formats" => %w[csv json], - }, - ) - end - - context "when the live form document has different settings from the form" do - let(:form) do - create(:form, submission_type: "email", submission_format: []) - end - - let!(:live_form_document) do - create( - :form_document, - form:, - tag: "live", - language: "en", - content: form.as_form_document.merge( - "submission_type" => "s3", - "submission_format" => %w[json], - ), - ) - end - - it "updates the live form document with the delivery configuration for the live form settings" do - task.invoke - - expect(form.reload.delivery_configurations.pluck(:delivery_method, :delivery_schedule, :formats)).to contain_exactly( - ["email", "immediate", []], - ) - - expect(live_form_document.reload.content["delivery_configurations"]).to contain_exactly( - { - "delivery_method" => "s3", - "delivery_schedule" => "immediate", - "formats" => %w[json], - }, - ) - end - end - - context "when the form sends daily and weekly submission batches" do - let(:form) do - create(:form, :live_with_draft, send_daily_submission_batch: true, send_weekly_submission_batch: true) - end - - let!(:draft_form_document) do - form.draft_form_document - end - - it "creates immediate, daily, and weekly delivery configurations for the form" do - task.invoke - - expect(form.reload.delivery_configurations.pluck(:delivery_method, :delivery_schedule, :formats)).to contain_exactly( - ["email", "immediate", []], - ["email", "daily", %w[csv]], - ["email", "weekly", %w[csv]], - ) - end - - it "updates the draft form document with all delivery configurations" do - task.invoke - - expect(draft_form_document.reload.content["delivery_configurations"]).to contain_exactly( - { - "delivery_method" => "email", - "delivery_schedule" => "immediate", - "formats" => [], - }, - { - "delivery_method" => "email", - "delivery_schedule" => "daily", - "formats" => %w[csv], - }, - { - "delivery_method" => "email", - "delivery_schedule" => "weekly", - "formats" => %w[csv], - }, - ) - end - end - - it "does not duplicate delivery configurations when rerun" do - task.invoke - task.reenable - task.invoke - - expect(form.reload.delivery_configurations.pluck(:delivery_method, :delivery_schedule, :formats)).to contain_exactly( - ["email", "immediate", %w[csv json]], - ) - end - end -end diff --git a/spec/models/form_document/content_spec.rb b/spec/models/form_document/content_spec.rb index 4d8d397df..0841ee869 100644 --- a/spec/models/form_document/content_spec.rb +++ b/spec/models/form_document/content_spec.rb @@ -35,7 +35,20 @@ end it "has all form attributes the original form has" do - expected_attributes = form.attributes.except(*%w[id state external_id pages question_section_completed declaration_section_completed share_preview_completed welsh_completed copied_from_id]) + excluded_attributes = %w[id + state + external_id + pages + question_section_completed + declaration_section_completed + share_preview_completed + welsh_completed + copied_from_id + submission_type + submission_format + send_daily_submission_batch + send_weekly_submission_batch] + expected_attributes = form.attributes.except(*excluded_attributes) expect(form_document_content).to have_attributes(expected_attributes) end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 2c7e81b2c..ac27573de 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -234,13 +234,6 @@ expect(form).to be_valid end end - - context "when there is no submission type" do - it "returns invalid" do - form.submission_type = nil - expect(form).to be_invalid - end - end end end @@ -900,15 +893,6 @@ end end - describe "submission type" do - describe "enum" do - it "returns a list of submission types" do - expect(described_class.submission_types.keys).to eq(%w[email s3]) - expect(described_class.submission_types.values).to eq(%w[email s3]) - end - end - end - describe "answer email copy" do describe "enum" do it "returns a list of email copy answers values" do @@ -924,30 +908,6 @@ end end - describe "submission format" do - let(:form) { create :form } - - it "can be empty" do - form.update!(submission_format: []) - expect(form.submission_format).to be_empty - end - - it "stores an array of strings" do - form.update!(submission_format: %w[csv json]) - expect(form.submission_format).to include "csv" - expect(form.submission_format).to include "json" - end - - # ActiveRecord doesn't support enums with arrays - # describe "enum" do - # it "returns a list of submission formats" do - # formats = %w[csv json] - # expect(described_class.submission_formats.keys).to eq formats - # expect(described_class.submission_formats.values).to eq formats - # end - # end - end - describe "#destroy" do let(:form) { create :form }