4 changed files with 64 additions and 31 deletions
@ -0,0 +1,14 @@ |
|||||||
|
include Rails.application.routes.url_helpers |
||||||
|
|
||||||
|
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] |
||||||
|
raise "Organisation id must be provided" unless organisation_id |
||||||
|
|
||||||
|
organisation = Organisation.find(organisation_id) |
||||||
|
raise "Organisation #{organisation_id} does not exist" unless organisation |
||||||
|
|
||||||
|
organisation.users.each(&:send_beta_onboarding_email) |
||||||
|
end |
||||||
|
end |
@ -1,31 +0,0 @@ |
|||||||
<% content_for :title, "Reset your password" %> |
|
||||||
|
|
||||||
<% content_for :before_content do %> |
|
||||||
<%= govuk_back_link( |
|
||||||
text: "Back", |
|
||||||
href: :back, |
|
||||||
) %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= form_for(@user, as: :user, url: password_path(User), html: { method: :put }) do |f| %> |
|
||||||
<%= f.hidden_field :reset_password_token %> |
|
||||||
<div class="govuk-grid-row"> |
|
||||||
<div class="govuk-grid-column-two-thirds"> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
|
|
||||||
<h1 class="govuk-heading-l"> |
|
||||||
<%= content_for(:title) %> |
|
||||||
</h1> |
|
||||||
|
|
||||||
<%= f.govuk_password_field :password, |
|
||||||
label: { text: "New password" }, |
|
||||||
hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil, |
|
||||||
autocomplete: "new-password" %> |
|
||||||
|
|
||||||
<%= f.govuk_password_field :password_confirmation, |
|
||||||
label: { text: "Confirm new password" } %> |
|
||||||
|
|
||||||
<%= f.govuk_submit "Update" %> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
<% end %> |
|
@ -0,0 +1,39 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
describe "rake onboarding_emails:send", type: task do |
||||||
|
subject(:task) { Rake::Task["onboarding_emails:send"] } |
||||||
|
|
||||||
|
let!(:user) { FactoryBot.create(:user) } |
||||||
|
let(:notify_client) { instance_double(Notifications::Client) } |
||||||
|
let(:devise_notify_mailer) { DeviseNotifyMailer.new } |
||||||
|
let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" } |
||||||
|
|
||||||
|
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(:[]).with("APP_HOST").and_return("http://localhost:3000") |
||||||
|
end |
||||||
|
|
||||||
|
context "when onboarding a new organisation to private beta" do |
||||||
|
it "can send the onboarding emails" do |
||||||
|
expect(notify_client).to receive(:send_email).with( |
||||||
|
{ |
||||||
|
email_address: user.email, |
||||||
|
template_id: User::BETA_ONBOARDING_TEMPLATE_ID, |
||||||
|
personalisation: { |
||||||
|
name: user.name, |
||||||
|
link: "http://localhost:3000/account/password/edit?reset_password_token=#{reset_password_token}", |
||||||
|
}, |
||||||
|
}, |
||||||
|
) |
||||||
|
|
||||||
|
task.invoke(user.organisation.id) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue