diff --git a/Gemfile b/Gemfile index baaddab2e..e9af29d55 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,8 @@ gem "possessive" # Strip whitespace from active record attributes gem "auto_strip_attributes" # Use sidekiq for background processing +gem "factory_bot_rails" +gem "faker" gem "method_source", "~> 1.1" gem "rails_admin", "~> 3.1" gem "ruby-openai" @@ -75,8 +77,6 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem "byebug", platforms: %i[mri mingw x64_mingw] gem "dotenv-rails" - gem "factory_bot_rails" - gem "faker" gem "pry-byebug" gem "parallel_tests" diff --git a/app/components/create_log_actions_component.html.erb b/app/components/create_log_actions_component.html.erb index 53e2bb57b..a600f3290 100644 --- a/app/components/create_log_actions_component.html.erb +++ b/app/components/create_log_actions_component.html.erb @@ -7,5 +7,10 @@ <% if user.support? %> <%= govuk_button_link_to view_uploads_button_copy, view_uploads_button_href, secondary: true %> <% end %> + + <% if FeatureToggle.create_test_logs_enabled? %> + <%= govuk_button_link_to "Create test log", create_test_log_href, secondary: true %> + <%= govuk_button_link_to "Create test log (setup only)", create_setup_test_log_href, secondary: true %> + <% end %> <% end %> diff --git a/app/components/create_log_actions_component.rb b/app/components/create_log_actions_component.rb index 4395c48a9..896bfe97e 100644 --- a/app/components/create_log_actions_component.rb +++ b/app/components/create_log_actions_component.rb @@ -34,6 +34,14 @@ class CreateLogActionsComponent < ViewComponent::Base send("bulk_upload_#{log_type}_log_path", id: "start") end + def create_test_log_href + send("create_test_#{log_type}_log_path") + end + + def create_setup_test_log_href + send("create_setup_test_#{log_type}_log_path") + end + def view_uploads_button_copy "View #{log_type} bulk uploads" end diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index cc3c731d5..af3a6c32f 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -149,6 +149,20 @@ class LettingsLogsController < LogsController end end + def create_test_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA") + redirect_to lettings_log_path(log) + end + + def create_setup_test_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user) + redirect_to lettings_log_path(log) + end + private def session_filters diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index af9879896..8799fe528 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -119,6 +119,20 @@ class SalesLogsController < LogsController end end + def create_test_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user) + redirect_to sales_log_path(log) + end + + def create_setup_test_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user) + redirect_to sales_log_path(log) + end + private def session_filters diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index 1b67b8b37..065c3b54e 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -46,4 +46,8 @@ class FeatureToggle def self.managing_resources_enabled? !Rails.env.production? end + + def self.create_test_logs_enabled? + Rails.env.development? || Rails.env.review? + end end diff --git a/config/routes.rb b/config/routes.rb index 1c7af8c59..55d58b41b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -389,6 +389,11 @@ Rails.application.routes.draw do end end + get "create-test-lettings-log", to: "lettings_logs#create_test_log" + get "create-test-sales-log", to: "sales_logs#create_test_log" + get "create-setup-test-lettings-log", to: "lettings_logs#create_setup_test_log" + get "create-setup-test-sales-log", to: "sales_logs#create_setup_test_log" + scope via: :all do match "/404", to: "errors#not_found" match "/429", to: "errors#too_many_requests", status: 429