diff --git a/app/assets/images/email/letter-success.png b/app/assets/images/email/letter-success.png new file mode 100644 index 00000000000..de287b7c8c5 Binary files /dev/null and b/app/assets/images/email/letter-success.png differ diff --git a/app/helpers/locale_helper.rb b/app/helpers/locale_helper.rb index 67706bc1cea..c930297c0e8 100644 --- a/app/helpers/locale_helper.rb +++ b/app/helpers/locale_helper.rb @@ -10,7 +10,17 @@ def with_user_locale(user, &block) locale = user.email_language if I18n.locale_available?(locale) - I18n.with_locale(locale, &block) + if defined?(url_options) + I18n.with_locale(locale) do + url_options_locale = url_options[:locale] + url_options[:locale] = locale + block.call + ensure + url_options[:locale] = url_options_locale + end + else + I18n.with_locale(locale, &block) + end else Rails.logger.warn("user_id=#{user.uuid} has bad email_language=#{locale}") if locale.present? diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index c69079ba73a..afb50fab1ae 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -206,7 +206,15 @@ def please_reset_password def verify_by_mail_letter_requested with_user_locale(user) do - mail(to: email_address.email, subject: t('user_mailer.letter_reminder.subject')) + @hide_title = true + @presenter = Idv::ByMail::LetterRequestedEmailPresenter.new( + current_user: user, + url_options:, + ) + mail( + to: email_address.email, + subject: t('user_mailer.verify_by_mail_letter_requested.subject'), + ) end end @@ -246,7 +254,7 @@ def account_verified(profile:) attachments.inline['verified.png'] = Rails.root.join('app/assets/images/email/user-signup-ial2.png').read with_user_locale(user) do - @presenter = Idv::AccountVerifiedEmailPresenter.new(profile:) + @presenter = Idv::AccountVerifiedEmailPresenter.new(profile:, url_options:) @hide_title = true @date = I18n.l(profile.verified_at, format: :event_date) mail( diff --git a/app/presenters/idv/account_verified_email_presenter.rb b/app/presenters/idv/account_verified_email_presenter.rb index ceb89b83901..1512812c2de 100644 --- a/app/presenters/idv/account_verified_email_presenter.rb +++ b/app/presenters/idv/account_verified_email_presenter.rb @@ -4,10 +4,11 @@ module Idv class AccountVerifiedEmailPresenter include Rails.application.routes.url_helpers - attr_reader :profile + attr_reader :profile, :url_options - def initialize(profile:) + def initialize(profile:, url_options:) @profile = profile + @url_options = url_options end def service_provider @@ -30,10 +31,6 @@ def sp_name service_provider&.friendly_name || APP_NAME end - def url_options - {} - end - private def sp_return_url_resolver diff --git a/app/presenters/idv/by_mail/letter_requested_email_presenter.rb b/app/presenters/idv/by_mail/letter_requested_email_presenter.rb new file mode 100644 index 00000000000..c16de87bd39 --- /dev/null +++ b/app/presenters/idv/by_mail/letter_requested_email_presenter.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Idv + module ByMail + class LetterRequestedEmailPresenter + include ActionView::Helpers::TranslationHelper + include Rails.application.routes.url_helpers + + attr_reader :current_user, :service_provider, :url_options + def initialize(current_user:, url_options:) + @current_user = current_user + @url_options = url_options + @service_provider = current_user.pending_profile&.initiating_service_provider + end + + def sp_name + service_provider&.friendly_name + end + + def show_sp_contact_instructions? + sp_name.present? + end + + def show_cta? + sign_in_url.present? + end + + def sign_in_url + if service_provider.present? + service_provider_homepage_url + else + root_url + end + end + + private + + def service_provider_homepage_url + sp_return_url_resolver.homepage_url if service_provider + end + + def sp_return_url_resolver + SpReturnUrlResolver.new(service_provider:) + end + end + end +end diff --git a/app/views/user_mailer/verify_by_mail_letter_requested.html.erb b/app/views/user_mailer/verify_by_mail_letter_requested.html.erb index 4d1a82d6863..53e721e7b1c 100644 --- a/app/views/user_mailer/verify_by_mail_letter_requested.html.erb +++ b/app/views/user_mailer/verify_by_mail_letter_requested.html.erb @@ -1,21 +1,58 @@ -
- <%= t('user_mailer.letter_reminder.info_html', link_html: link_to(APP_NAME, root_url)) %> +<%= image_tag( + 'email/letter-success.png', + width: 140, + height: 177, + alt: '', + class: 'float-center padding-bottom-4', + ) %> +
+ <%= t('user_mailer.verify_by_mail_letter_requested.intro_html', app_name: APP_NAME) %>
+ +<% if @presenter.show_sp_contact_instructions? %> +<%= t('user_mailer.verify_by_mail_letter_requested.instructions.sign_in') %>
+<% end %> -| - - | -
| - - | -
|---|
+
|
+ + |
+ <%= link_to @presenter.sign_in_url, @presenter.sign_in_url, target: '_blank', rel: 'noopener' %> +
+<% end %> + diff --git a/config/locales/en.yml b/config/locales/en.yml index c4e56d5d3c2..fa619cb021d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1890,8 +1890,6 @@ user_mailer.letter_reminder_14_days.did_not_get_a_letter_html: If you didn’t g user_mailer.letter_reminder_14_days.finish: Finish verifying your identity user_mailer.letter_reminder_14_days.sign_in_and_request_another_letter: sign in to request another letter user_mailer.letter_reminder_14_days.subject: Finish verifying your identity -user_mailer.letter_reminder.info_html: The letter you are about to receive will contain a verification code that helps us verify your address. You can complete the identity verification process by signing into %{link_html} and entering the verification code. -user_mailer.letter_reminder.subject: We mailed a letter to the address you have on file user_mailer.new_device_sign_in_after_2fa.authentication_methods: authentication methods user_mailer.new_device_sign_in_after_2fa.info_p1: Your %{app_name} email and password were used to sign-in and authenticate on a new device. user_mailer.new_device_sign_in_after_2fa.info_p2: If you recognize this activity, you don’t need to do anything. @@ -1947,6 +1945,11 @@ user_mailer.suspended_reset_password.subject: We couldn’t reset your password user_mailer.suspension_confirmed.contact_agency: Please contact the agency whose service you are trying to access. user_mailer.suspension_confirmed.remain_locked: We have completed our review of your %{app_name} account and your account will remain locked. user_mailer.suspension_confirmed.subject: Your account is locked +user_mailer.verify_by_mail_letter_requested.cta.sign_in: Sign in +user_mailer.verify_by_mail_letter_requested.instructions.contact_sp: Contact %{friendly_name} if you need to access their services before your letter arrives. +user_mailer.verify_by_mail_letter_requested.instructions.sign_in: Sign back in and enter the verification code when your letter arrives. +user_mailer.verify_by_mail_letter_requested.intro_html: You’ll get a letter in the mail from %{app_name} in 5 to 10 days at the address we verified and associated with you. +user_mailer.verify_by_mail_letter_requested.subject: Your letter is on the way users.delete.actions.cancel: Back to profile users.delete.actions.delete: Delete account users.delete.bullet_1: You won’t have a %{app_name} account diff --git a/config/locales/es.yml b/config/locales/es.yml index 5ab154e9ebd..f17dae675f8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1902,8 +1902,6 @@ user_mailer.letter_reminder_14_days.did_not_get_a_letter_html: Si no recibió es user_mailer.letter_reminder_14_days.finish: Termine de verificar su identidad user_mailer.letter_reminder_14_days.sign_in_and_request_another_letter: inicie sesión para solicitar otra carta user_mailer.letter_reminder_14_days.subject: Termine de verificar su identidad -user_mailer.letter_reminder.info_html: La carta que recibirá próximamente contiene un código de verificación que nos ayudará a verificar su dirección. Para completar el proceso de verificación de identidad, inicie sesión en %{link_html} e ingrese el código de verificación. -user_mailer.letter_reminder.subject: Enviamos una carta a la dirección de su expediente user_mailer.new_device_sign_in_after_2fa.authentication_methods: métodos de autenticación user_mailer.new_device_sign_in_after_2fa.info_p1: Su correo electrónico y contraseña de %{app_name} se usaron para iniciar sesión y hacer la autenticación en un dispositivo nuevo. user_mailer.new_device_sign_in_after_2fa.info_p2: Si reconoce esta actividad, no tiene que hacer nada. @@ -1959,6 +1957,11 @@ user_mailer.suspended_reset_password.subject: No pudimos restablecer su contrase user_mailer.suspension_confirmed.contact_agency: Contacte con la agencia a cuyo servicio está intentando acceder. user_mailer.suspension_confirmed.remain_locked: Terminamos la revisión de su cuenta de %{app_name} y la cuenta permanecerá bloqueada. user_mailer.suspension_confirmed.subject: Su cuenta está bloqueada +user_mailer.verify_by_mail_letter_requested.cta.sign_in: Iniciar sesión +user_mailer.verify_by_mail_letter_requested.instructions.contact_sp: Contacte con %{friendly_name} si necesita acceder a los servicios de esa agencia antes de que llegue su carta. +user_mailer.verify_by_mail_letter_requested.instructions.sign_in: Cuando reciba su carta, vuelva a iniciar sesión e ingrese el código de verificación. +user_mailer.verify_by_mail_letter_requested.intro_html: 'En un plazo de 5 a 10 días, recibirá por correo una carta de %{app_name} en la dirección que verificamos y asociamos con usted:' +user_mailer.verify_by_mail_letter_requested.subject: Su carta está en camino users.delete.actions.cancel: Volver al perfil users.delete.actions.delete: Eliminar cuenta users.delete.bullet_1: No tendrá una cuenta de %{app_name}. diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1c7fd9cb6e1..61d7ea3c890 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1890,8 +1890,6 @@ user_mailer.letter_reminder_14_days.did_not_get_a_letter_html: Si vous n’avez user_mailer.letter_reminder_14_days.finish: Terminer la vérification de votre identité user_mailer.letter_reminder_14_days.sign_in_and_request_another_letter: connectez-vous pour en demander une autre user_mailer.letter_reminder_14_days.subject: Terminer la vérification de votre identité -user_mailer.letter_reminder.info_html: La lettre que vous êtes sur le point de recevoir contiendra un code de vérification nous permettant de vérifier votre adresse. Vous pouvez terminer le processus de vérification d’identité en vous connectant à %{link_html} et en saisissant le code de vérification. -user_mailer.letter_reminder.subject: Nous avons posté une lettre à l’adresse que vous avez enregistrée user_mailer.new_device_sign_in_after_2fa.authentication_methods: méthodes d’authentification user_mailer.new_device_sign_in_after_2fa.info_p1: Votre e-mail et mot de passe %{app_name} ont été utilisés pour se connecter et s’authentifier sur un nouvel appareil. user_mailer.new_device_sign_in_after_2fa.info_p2: Si vous reconnaissez cette activité, vous n’avez rien à faire. @@ -1947,6 +1945,11 @@ user_mailer.suspended_reset_password.subject: Nous n’avons pas pu réinitialis user_mailer.suspension_confirmed.contact_agency: Veuillez contacter l’organisme dont vous essayez d’accéder au service. user_mailer.suspension_confirmed.remain_locked: Nous avons terminé l’examen de votre compte %{app_name} et votre compte restera verrouillé. user_mailer.suspension_confirmed.subject: Votre compte est verrouillé +user_mailer.verify_by_mail_letter_requested.cta.sign_in: Connexion +user_mailer.verify_by_mail_letter_requested.instructions.contact_sp: Contactez %{friendly_name} si vous avez besoin d’accéder à ses services avant l’arrivée de votre lettre. +user_mailer.verify_by_mail_letter_requested.instructions.sign_in: Une fois ce courrier reçu, reconnectez-vous pour saisir le code de vérification qui y figure. +user_mailer.verify_by_mail_letter_requested.intro_html: 'Vous recevrez un courrier de %{app_name} d’ici 5 à 10 jours à l’adresse que nous avons confirmée qui est associée à votre nom :' +user_mailer.verify_by_mail_letter_requested.subject: Votre lettre est en route users.delete.actions.cancel: Retour au profil users.delete.actions.delete: Supprimer le compte users.delete.bullet_1: Vous n’aurez pas de compte %{app_name}. diff --git a/config/locales/zh.yml b/config/locales/zh.yml index d7e911f2dc5..e68b7fb5452 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1903,8 +1903,6 @@ user_mailer.letter_reminder_14_days.did_not_get_a_letter_html: 如果你没有 user_mailer.letter_reminder_14_days.finish: 完成验证你的身份 user_mailer.letter_reminder_14_days.sign_in_and_request_another_letter: 登录要求再发一封信 user_mailer.letter_reminder_14_days.subject: 完成验证你的身份 -user_mailer.letter_reminder.info_html: 你将收到的信件会含有帮助我们验证你地址的一次性代码。你可以登入 %{link_html} 并输入该一次性代码来完成身份验证流i程。 -user_mailer.letter_reminder.subject: 我们已向你存档地址发送了一封信。 user_mailer.new_device_sign_in_after_2fa.authentication_methods: 身份证实方法 user_mailer.new_device_sign_in_after_2fa.info_p1: 你的 %{app_name} 电邮和密码在一个新设备上被用来登录和进行身份验证。 user_mailer.new_device_sign_in_after_2fa.info_p2: 如果你知道该活动,则无需做任何事情。 @@ -1960,6 +1958,11 @@ user_mailer.suspended_reset_password.subject: 我们无法重设你的密码。 user_mailer.suspension_confirmed.contact_agency: 请联系你试图访问其服务的那个机构。 user_mailer.suspension_confirmed.remain_locked: 我们已完成了对你%{app_name}账户的审查,你的账户将继续被锁。 user_mailer.suspension_confirmed.subject: 你的账户被锁 +user_mailer.verify_by_mail_letter_requested.cta.sign_in: 登录 +user_mailer.verify_by_mail_letter_requested.instructions.contact_sp: 如果收到信件之前你需要访问我们合作伙伴机构的服务,请联系%{friendly_name}。 +user_mailer.verify_by_mail_letter_requested.instructions.sign_in: 收到信件后请再登录并输入其中的验证码。 +user_mailer.verify_by_mail_letter_requested.intro_html: '你会在5到10天内在我们验证过的与你相关的地址收到来自%{app_name}寄给你的一封信:' +user_mailer.verify_by_mail_letter_requested.subject: 你的信件已寄出。 users.delete.actions.cancel: 返回用户资料 users.delete.actions.delete: 删除账户 users.delete.bullet_1: 你不会有 %{app_name} 账户 diff --git a/spec/controllers/idv/verify_info_controller_spec.rb b/spec/controllers/idv/verify_info_controller_spec.rb index 9f453c60677..50351d84b11 100644 --- a/spec/controllers/idv/verify_info_controller_spec.rb +++ b/spec/controllers/idv/verify_info_controller_spec.rb @@ -200,6 +200,7 @@ before do controller.idv_session.ssn = nil end + it 'does not log an idv_verify_info_missing_threatmetrix_session_id event' do get :show expect(@analytics).not_to have_logged_event( diff --git a/spec/features/idv/steps/enter_password_step_spec.rb b/spec/features/idv/steps/enter_password_step_spec.rb index b53a3e3c126..d7fa1e5a9dd 100644 --- a/spec/features/idv/steps/enter_password_step_spec.rb +++ b/spec/features/idv/steps/enter_password_step_spec.rb @@ -73,7 +73,7 @@ def sends_letter_creates_unverified_profile_sends_email to change { GpoConfirmation.count }.by(1) expect_delivered_email_count(email_count_before_continue + 1) - expect(last_email.subject).to eq(t('user_mailer.letter_reminder.subject')) + expect(last_email.subject).to eq(t('user_mailer.verify_by_mail_letter_requested.subject')) expect(user.events.account_verified.size).to be(0) expect(user.profiles.count).to eq 1 diff --git a/spec/helpers/locale_helper_spec.rb b/spec/helpers/locale_helper_spec.rb index dbffafd9230..356aa61e928 100644 --- a/spec/helpers/locale_helper_spec.rb +++ b/spec/helpers/locale_helper_spec.rb @@ -52,6 +52,7 @@ context 'when the user has an email_language' do let(:email_language) { 'es' } + let(:url_options) { {} } it 'sets the language inside the block and yields' do subject diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index ebcabaded71..e745a01ab1e 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -281,7 +281,7 @@ def allowed_untranslated_key?(locale, key) ) end - it 'has matching HTML tags' do + it 'has matching HTML tags across all locales' do i18n.data[i18n.base_locale].select_keys do |key, _node| if key.start_with?('i18n.transliterate.rule.') || i18n.t(key).is_a?(Array) || i18n.t(key).nil? next diff --git a/spec/mailers/previews/user_mailer_preview.rb b/spec/mailers/previews/user_mailer_preview.rb index e5c2f96a542..ac6dc41e16e 100644 --- a/spec/mailers/previews/user_mailer_preview.rb +++ b/spec/mailers/previews/user_mailer_preview.rb @@ -124,6 +124,14 @@ def please_reset_password end def verify_by_mail_letter_requested + service_provider = unsaveable( + ServiceProvider.new( + friendly_name: 'Sample App SP', + return_to_sp_url: 'https://example.com', + ), + ) + profile = Profile.new(initiating_service_provider: service_provider) + user.instance_variable_set(:@pending_profile, profile) UserMailer.with(user: user, email_address: email_address_record).verify_by_mail_letter_requested end @@ -286,6 +294,7 @@ def user ), ), ], + email_language: params[:locale], ), ) end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 59f25d32c69..7f4b80dd228 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -166,6 +166,7 @@ describe '#new_device_sign_in_before_2fa' do let(:event) { create(:event, event_type: :sign_in_before_2fa, user:, device: create(:device)) } + subject(:mail) do UserMailer.with(user:, email_address:).new_device_sign_in_before_2fa( events: user.events.where(event_type: 'sign_in_before_2fa').includes(:device).to_a, @@ -179,6 +180,7 @@ describe '#new_device_sign_in_after_2fa' do let(:event) { create(:event, event_type: :sign_in_after_2fa, user:, device: create(:device)) } + subject(:mail) do UserMailer.with(user:, email_address:).new_device_sign_in_after_2fa( events: user.events.where(event_type: 'sign_in_after_2fa').includes(:device).to_a, @@ -501,6 +503,24 @@ def expect_email_body_to_have_help_and_contact_links end describe '#verify_by_mail_letter_requested' do + let(:service_provider) do + create( + :service_provider, + return_to_sp_url: 'https://www.example.com', + friendly_name: 'My Awesome SP', + ) + end + + let(:profile) do + create( + :profile, + :verify_by_mail_pending, + initiating_service_provider: service_provider, + ) + end + + let(:user) { profile.user } + let(:mail) do UserMailer.with(user: user, email_address: email_address).verify_by_mail_letter_requested end @@ -513,12 +533,76 @@ def expect_email_body_to_have_help_and_contact_links end it 'renders the subject' do - expect(mail.subject).to eq t('user_mailer.letter_reminder.subject') + expect(mail.subject).to eq t('user_mailer.verify_by_mail_letter_requested.subject') end - it 'renders the body' do - expect(mail.html_part.body). - to have_content(strip_tags(t('user_mailer.letter_reminder.info_html', link_html: APP_NAME))) + context 'ServiceProvider has a homepage URL' do + it 'renders the contact SP instructions' do + expect(mail.html_part.body).to have_content( + t( + 'user_mailer.verify_by_mail_letter_requested.instructions.contact_sp', + friendly_name: 'My Awesome SP', + ), + ) + end + + it 'renders the sign in CTA' do + expect(mail.html_part.body).to have_link( + t( + 'user_mailer.verify_by_mail_letter_requested.cta.sign_in', + ), + href: 'https://www.example.com', + ) + end + end + + context 'ServiceProvider does not have a homepage URL' do + let(:service_provider) do + create( + :service_provider, + friendly_name: 'My Awesome SP', + return_to_sp_url: nil, + ) + end + + it 'renders the contact SP instructions' do + expect(mail.html_part.body).to have_content( + t( + 'user_mailer.verify_by_mail_letter_requested.instructions.contact_sp', + friendly_name: 'My Awesome SP', + ), + ) + end + + it 'does not render the sign in CTA' do + expect(mail.html_part.body).to_not have_link( + t( + 'user_mailer.verify_by_mail_letter_requested.cta.sign_in', + ), + ) + end + end + + context 'No Service Provider present' do + let(:service_provider) { nil } + + it 'it does not render the contact SP instructions' do + expect(mail.html_part.body).to_not have_content( + t( + 'user_mailer.verify_by_mail_letter_requested.instructions.contact_sp', + friendly_name: APP_NAME, + ), + ) + end + + it 'renders the sign in CTA with root URL' do + expect(mail.html_part.body).to have_link( + t( + 'user_mailer.verify_by_mail_letter_requested.cta.sign_in', + ), + href: root_url, + ) + end end end @@ -847,6 +931,7 @@ def expect_email_body_to_have_help_and_contact_links enrollment: enrollment, ) end + context 'For Informed Delivery IPP (ID-IPP)' do it_behaves_like 'a system email' it_behaves_like 'an email that respects user email locale preference' @@ -867,6 +952,7 @@ def expect_email_body_to_have_help_and_contact_links context 'For Enhanced In-Person Proofing (Enhanced IPP)' do let(:enrollment) { enhanced_ipp_enrollment } + it 'renders content that is applicable to Enhanced In-Person Proofing (Enhanced IPP)' do aggregate_failures do [ @@ -1064,6 +1150,7 @@ def expect_email_body_to_have_help_and_contact_links user.email_language = 'fr' user.save! end + it 'renders the pre opt-in in person completion survey url' do expect(mail.html_part.body). to have_selector( diff --git a/spec/policies/pending_profile_policy_spec.rb b/spec/policies/pending_profile_policy_spec.rb index d5676a57e9c..ec59c3eaee8 100644 --- a/spec/policies/pending_profile_policy_spec.rb +++ b/spec/policies/pending_profile_policy_spec.rb @@ -23,6 +23,7 @@ describe '#user_has_pending_profile?' do context 'has an active non-facial match profile and facial match comparison is requested' do let(:idv_level) { :unsupervised_with_selfie } + before do create(:profile, :active, :verified, idv_level: :legacy_unsupervised, user: user) create(:profile, :verify_by_mail_pending, idv_level: idv_level, user: user) @@ -62,6 +63,7 @@ context 'no facial match comparison is requested' do let(:idv_level) { :legacy_unsupervised } let(:vtr) { ['C2'] } + context 'user has pending profile' do before do create(:profile, :verify_by_mail_pending, idv_level: idv_level, user: user) diff --git a/spec/presenters/account_show_presenter_spec.rb b/spec/presenters/account_show_presenter_spec.rb index 546ae1f92af..3688bde40c1 100644 --- a/spec/presenters/account_show_presenter_spec.rb +++ b/spec/presenters/account_show_presenter_spec.rb @@ -16,6 +16,7 @@ let(:sp_name) { nil } let(:user) { build(:user) } let(:locked_for_session) { false } + subject(:presenter) do AccountShowPresenter.new( decrypted_pii:, @@ -480,6 +481,7 @@ describe '#connected_apps' do let(:user) { create(:user, identities: [create(:service_provider_identity)]) } + subject(:connected_apps) { presenter.connected_apps } it 'delegates to user, eager-loading view-specific relations' do diff --git a/spec/presenters/idv/account_verified_email_presenter_spec.rb b/spec/presenters/idv/account_verified_email_presenter_spec.rb index 760b22b2fd0..64b620fae57 100644 --- a/spec/presenters/idv/account_verified_email_presenter_spec.rb +++ b/spec/presenters/idv/account_verified_email_presenter_spec.rb @@ -12,7 +12,7 @@ ) end - subject(:presenter) { described_class.new(profile:) } + subject(:presenter) { described_class.new(profile:, url_options: {}) } context 'when there is no associated service provider' do let(:service_provider) { nil } diff --git a/spec/presenters/idv/by_mail/letter_requested_email_presenter_spec.rb b/spec/presenters/idv/by_mail/letter_requested_email_presenter_spec.rb new file mode 100644 index 00000000000..16adf3a2d07 --- /dev/null +++ b/spec/presenters/idv/by_mail/letter_requested_email_presenter_spec.rb @@ -0,0 +1,93 @@ +require 'rails_helper' + +RSpec.describe Idv::ByMail::LetterRequestedEmailPresenter do + include Rails.application.routes.url_helpers + + let(:service_provider) { create(:service_provider) } + + let(:profile) do + create( + :profile, + :verify_by_mail_pending, + initiating_service_provider: service_provider, + ) + end + + let(:user) { profile.user } + + subject(:presenter) { described_class.new(current_user: user, url_options: {}) } + + context 'when there is no associated service provider' do + let(:service_provider) { nil } + + describe '#sp_name' do + it { expect(presenter.sp_name).to be_nil } + end + + describe '#show_sp_contact_instructions?' do + it { expect(presenter.show_sp_contact_instructions?).to eq(false) } + end + + describe '#show_cta?' do + it { expect(presenter.show_cta?).to eq(true) } + end + + describe '#sign_in_url' do + it { expect(presenter.sign_in_url).to eq(root_url) } + end + end + + context 'where there is a service provider' do + context 'when the service provider has no return URL' do + let(:service_provider) do + create( + :service_provider, + return_to_sp_url: nil, + friendly_name: 'My Awesome SP', + ) + end + + describe '#sp_name' do + it { expect(presenter.sp_name).to eq('My Awesome SP') } + end + + describe '#show_sp_contact_instructions?' do + it { expect(presenter.show_sp_contact_instructions?).to eq(true) } + end + + describe '#show_cta?' do + it { expect(presenter.show_cta?).to eq(false) } + end + + describe '#sign_in_url' do + it { expect(presenter.sign_in_url).to eq(nil) } + end + end + + context 'when the service provider does have a return URL' do + let(:service_provider) do + create( + :service_provider, + return_to_sp_url: 'https://www.example.com', + friendly_name: 'My Awesome SP', + ) + end + + describe '#sp_name' do + it { expect(presenter.sp_name).to eq('My Awesome SP') } + end + + describe '#show_sp_contact_instructions?' do + it { expect(presenter.show_sp_contact_instructions?).to eq(true) } + end + + describe '#show_cta?' do + it { expect(presenter.show_cta?).to eq(true) } + end + + describe '#sign_in_url' do + it { expect(presenter.sign_in_url).to eq('https://www.example.com') } + end + end + end +end