diff --git a/lib/tasks/onboarding_emails.rake b/lib/tasks/onboarding_emails.rake deleted file mode 100644 index e0282ada9..000000000 --- a/lib/tasks/onboarding_emails.rake +++ /dev/null @@ -1,18 +0,0 @@ -namespace :onboarding_emails do - desc "Send onboarding emails to private beta users" - task :send, %i[organisation_id] => :environment do |_task, args| - organisation_id = args[:organisation_id] - host = ENV["APP_HOST"] - raise "Organisation id must be provided" unless organisation_id - raise "Host is not set" unless host - - organisation = Organisation.find(organisation_id) - raise "Organisation #{organisation_id} does not exist" unless organisation - - organisation.users.each do |user| - next unless URI::MailTo::EMAIL_REGEXP.match?(user.email) - - user.send_confirmation_instructions - end - end -end diff --git a/spec/lib/tasks/onboarding_emails_spec.rb b/spec/lib/tasks/onboarding_emails_spec.rb deleted file mode 100644 index a1f2809b1..000000000 --- a/spec/lib/tasks/onboarding_emails_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "rails_helper" -require "rake" - -describe "rake onboarding_emails:send", type: task do - subject(:task) { Rake::Task["onboarding_emails:send"] } - - context "when onboarding a new organisation to private beta" do - let!(:user) { FactoryBot.create(:user) } - 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 - expect(notify_client).to receive(:send_email).with( - { - email_address: user.email, - template_id: "b48bc2cd-5887-4611-8296-d0ab3ed0e7fd", - personalisation: { - name: user.name, - link: "#{host}/account/password/edit?reset_password_token=#{reset_password_token}", - }, - }, - ) - - task.invoke(user.organisation.id) - end - end -end