diff --git a/.env.example b/.env.example index 2163f2802..b6a2bf14f 100644 --- a/.env.example +++ b/.env.example @@ -3,3 +3,5 @@ DB_PASSWORD=postgres-password GOVUK_NOTIFY_API_KEY= OTP_SECRET_ENCRYPTION_KEY="" + +APP_HOST="http://localhost:3000" diff --git a/lib/tasks/onboarding_emails.rake b/lib/tasks/onboarding_emails.rake index d65dd9d9c..6610358db 100644 --- a/lib/tasks/onboarding_emails.rake +++ b/lib/tasks/onboarding_emails.rake @@ -1,10 +1,10 @@ namespace :onboarding_emails do desc "Send onboarding emails to private beta users" - task :send, %i[organisation_id host] => :environment do |_task, args| + task :send, %i[organisation_id] => :environment do |_task, args| organisation_id = args[:organisation_id] - host = args[:host] + host = ENV["APP_HOST"] raise "Organisation id must be provided" unless organisation_id - raise "host must be provided" unless host + raise "Host is not set" unless host organisation = Organisation.find(organisation_id) raise "Organisation #{organisation_id} does not exist" unless organisation diff --git a/spec/lib/tasks/onboarding_emails_spec.rb b/spec/lib/tasks/onboarding_emails_spec.rb index e0fafe706..a1f2809b1 100644 --- a/spec/lib/tasks/onboarding_emails_spec.rb +++ b/spec/lib/tasks/onboarding_emails_spec.rb @@ -9,14 +9,18 @@ describe "rake onboarding_emails:send", type: task do let(:notify_client) { instance_double(Notifications::Client) } let(:devise_notify_mailer) { DeviseNotifyMailer.new } let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" } + let(:host) { "http://localhost:3000" } before do Rake.application.rake_require("tasks/onboarding_emails") + Rake::Task.define_task(:environment) task.reenable allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) allow(notify_client).to receive(:send_email).and_return(true) allow(Devise.token_generator).to receive(:generate).and_return(reset_password_token) + allow(ENV).to receive(:[]) + allow(ENV).to receive(:[]).with("APP_HOST").and_return(host) end it "can send the onboarding emails" do @@ -26,12 +30,12 @@ describe "rake onboarding_emails:send", type: task do template_id: "b48bc2cd-5887-4611-8296-d0ab3ed0e7fd", personalisation: { name: user.name, - link: "http://localhost:3000/account/password/edit?reset_password_token=#{reset_password_token}", + link: "#{host}/account/password/edit?reset_password_token=#{reset_password_token}", }, }, ) - task.invoke(user.organisation.id, "http://localhost:3000") + task.invoke(user.organisation.id) end end end