Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
3.0 KiB

require "rails_helper"
RSpec.describe ResendInvitationMailer do
describe "#resend_invitation_email" do
let(:notify_client) { instance_double(Notifications::Client) }
let(:organisation) { create(:organisation, name: "test organisation") }
let!(:active_user) { create(:user, name: "active user", email: "active_user@example.com", organisation:, confirmation_token: "ghi", initial_confirmation_sent: true, old_user_id: "234", sign_in_count: 0) }
let!(:new_active_user) { create(:user, name: "new active user", email: "new_active_user@example.com", organisation:, confirmation_token: "abc", initial_confirmation_sent: false, old_user_id: nil, sign_in_count: 0) }
let(:new_active_migrated_user) { create(:user, name: "new active migrated user", email: "new_active_migrated_user@example.com", organisation:, confirmation_token: "def", initial_confirmation_sent: false, old_user_id: "123", sign_in_count: 0) }
before do
LegacyUser.destroy_all
allow(Notifications::Client).to receive(:new).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
end
context "with a new active user" do
let(:personalisation) do
{
name: "new active user",
email: "new_active_user@example.com",
organisation: "test organisation",
link: include("/account/confirmation?confirmation_token=abc"),
}
end
it "sends invitation email to user" do
expect(notify_client).to receive(:send_email).with(email_address: "new_active_user@example.com", template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
described_class.new.resend_invitation_email(new_active_user)
end
end
context "with active migrated user before the initial invitation has been sent" do
let(:personalisation) do
{
name: "new active migrated user",
email: "new_active_migrated_user@example.com",
organisation: "test organisation",
link: include("/account/confirmation?confirmation_token=def"),
}
end
it "sends an initial invitation" do
expect(notify_client).to receive(:send_email).with(email_address: "new_active_migrated_user@example.com", template_id: User::BETA_ONBOARDING_TEMPLATE_ID, personalisation:).once
described_class.new.resend_invitation_email(new_active_migrated_user)
end
end
context "with active user after the initial invitation has been sent" do
let(:personalisation) do
{
name: "active user",
email: "active_user@example.com",
organisation: "test organisation",
link: include("/account/confirmation?confirmation_token=ghi"),
}
end
it "sends a reinvitation" do
expect(notify_client).to receive(:send_email).with(email_address: "active_user@example.com", template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once
described_class.new.resend_invitation_email(active_user)
end
end
end
end