user_mailer_spec.rb 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe UserMailer do
  4. let(:receiver) { Fabricate(:user) }
  5. describe '#confirmation_instructions' do
  6. let(:mail) { described_class.confirmation_instructions(receiver, 'spec') }
  7. it 'renders confirmation instructions' do
  8. receiver.update!(locale: nil)
  9. expect(mail)
  10. .to be_present
  11. .and(have_body_text(I18n.t('devise.mailer.confirmation_instructions.title')))
  12. .and(have_body_text('spec'))
  13. .and(have_body_text(Rails.configuration.x.local_domain))
  14. end
  15. include_examples 'localized subject',
  16. 'devise.mailer.confirmation_instructions.subject',
  17. instance: Rails.configuration.x.local_domain
  18. end
  19. describe '#reconfirmation_instructions' do
  20. let(:mail) { described_class.confirmation_instructions(receiver, 'spec') }
  21. it 'renders reconfirmation instructions' do
  22. receiver.update!(email: 'new-email@example.com', locale: nil)
  23. expect(mail)
  24. .to be_present
  25. .and(have_body_text(I18n.t('devise.mailer.reconfirmation_instructions.title')))
  26. .and(have_body_text('spec'))
  27. .and(have_body_text(Rails.configuration.x.local_domain))
  28. end
  29. include_examples 'localized subject',
  30. 'devise.mailer.confirmation_instructions.subject',
  31. instance: Rails.configuration.x.local_domain
  32. end
  33. describe '#reset_password_instructions' do
  34. let(:mail) { described_class.reset_password_instructions(receiver, 'spec') }
  35. it 'renders reset password instructions' do
  36. receiver.update!(locale: nil)
  37. expect(mail)
  38. .to be_present
  39. .and(have_body_text(I18n.t('devise.mailer.reset_password_instructions.title')))
  40. .and(have_body_text('spec'))
  41. end
  42. include_examples 'localized subject',
  43. 'devise.mailer.reset_password_instructions.subject'
  44. end
  45. describe '#password_change' do
  46. let(:mail) { described_class.password_change(receiver) }
  47. it 'renders password change notification' do
  48. receiver.update!(locale: nil)
  49. expect(mail)
  50. .to be_present
  51. .and(have_body_text(I18n.t('devise.mailer.password_change.title')))
  52. end
  53. include_examples 'localized subject',
  54. 'devise.mailer.password_change.subject'
  55. end
  56. describe '#email_changed' do
  57. let(:mail) { described_class.email_changed(receiver) }
  58. it 'renders email change notification' do
  59. receiver.update!(locale: nil)
  60. expect(mail)
  61. .to be_present
  62. .and(have_body_text(I18n.t('devise.mailer.email_changed.title')))
  63. end
  64. include_examples 'localized subject',
  65. 'devise.mailer.email_changed.subject'
  66. end
  67. describe '#warning' do
  68. let(:strike) { Fabricate(:account_warning, target_account: receiver.account, text: 'dont worry its just the testsuite', action: 'suspend') }
  69. let(:mail) { described_class.warning(receiver, strike) }
  70. it 'renders warning notification' do
  71. receiver.update!(locale: nil)
  72. expect(mail)
  73. .to be_present
  74. .and(have_body_text(I18n.t('user_mailer.warning.title.suspend', acct: receiver.account.acct)))
  75. .and(have_body_text(strike.text))
  76. end
  77. end
  78. describe '#webauthn_credential_deleted' do
  79. let(:credential) { Fabricate(:webauthn_credential, user_id: receiver.id) }
  80. let(:mail) { described_class.webauthn_credential_deleted(receiver, credential) }
  81. it 'renders webauthn credential deleted notification' do
  82. receiver.update!(locale: nil)
  83. expect(mail)
  84. .to be_present
  85. .and(have_body_text(I18n.t('devise.mailer.webauthn_credential.deleted.title')))
  86. end
  87. include_examples 'localized subject',
  88. 'devise.mailer.webauthn_credential.deleted.subject'
  89. end
  90. describe '#suspicious_sign_in' do
  91. let(:ip) { '192.168.0.1' }
  92. let(:agent) { 'NCSA_Mosaic/2.0 (Windows 3.1)' }
  93. let(:timestamp) { Time.now.utc }
  94. let(:mail) { described_class.suspicious_sign_in(receiver, ip, agent, timestamp) }
  95. it 'renders suspicious sign in notification' do
  96. receiver.update!(locale: nil)
  97. expect(mail)
  98. .to be_present
  99. .and(have_body_text(I18n.t('user_mailer.suspicious_sign_in.explanation')))
  100. end
  101. include_examples 'localized subject',
  102. 'user_mailer.suspicious_sign_in.subject'
  103. end
  104. describe '#appeal_approved' do
  105. let(:appeal) { Fabricate(:appeal, account: receiver.account, approved_at: Time.now.utc) }
  106. let(:mail) { described_class.appeal_approved(receiver, appeal) }
  107. it 'renders appeal_approved notification' do
  108. expect(mail)
  109. .to be_present
  110. .and(have_subject(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at))))
  111. .and(have_body_text(I18n.t('user_mailer.appeal_approved.title')))
  112. end
  113. end
  114. describe '#appeal_rejected' do
  115. let(:appeal) { Fabricate(:appeal, account: receiver.account, rejected_at: Time.now.utc) }
  116. let(:mail) { described_class.appeal_rejected(receiver, appeal) }
  117. it 'renders appeal_rejected notification' do
  118. expect(mail)
  119. .to be_present
  120. .and(have_subject(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at))))
  121. .and(have_body_text(I18n.t('user_mailer.appeal_rejected.title')))
  122. end
  123. end
  124. describe '#two_factor_enabled' do
  125. let(:mail) { described_class.two_factor_enabled(receiver) }
  126. it 'renders two_factor_enabled mail' do
  127. expect(mail)
  128. .to be_present
  129. .and(have_subject(I18n.t('devise.mailer.two_factor_enabled.subject')))
  130. .and(have_body_text(I18n.t('devise.mailer.two_factor_enabled.explanation')))
  131. end
  132. end
  133. describe '#two_factor_disabled' do
  134. let(:mail) { described_class.two_factor_disabled(receiver) }
  135. it 'renders two_factor_disabled mail' do
  136. expect(mail)
  137. .to be_present
  138. .and(have_subject(I18n.t('devise.mailer.two_factor_disabled.subject')))
  139. .and(have_body_text(I18n.t('devise.mailer.two_factor_disabled.explanation')))
  140. end
  141. end
  142. describe '#webauthn_enabled' do
  143. let(:mail) { described_class.webauthn_enabled(receiver) }
  144. it 'renders webauthn_enabled mail' do
  145. expect(mail)
  146. .to be_present
  147. .and(have_subject(I18n.t('devise.mailer.webauthn_enabled.subject')))
  148. .and(have_body_text(I18n.t('devise.mailer.webauthn_enabled.explanation')))
  149. end
  150. end
  151. describe '#webauthn_disabled' do
  152. let(:mail) { described_class.webauthn_disabled(receiver) }
  153. it 'renders webauthn_disabled mail' do
  154. expect(mail)
  155. .to be_present
  156. .and(have_subject(I18n.t('devise.mailer.webauthn_disabled.subject')))
  157. .and(have_body_text(I18n.t('devise.mailer.webauthn_disabled.explanation')))
  158. end
  159. end
  160. describe '#two_factor_recovery_codes_changed' do
  161. let(:mail) { described_class.two_factor_recovery_codes_changed(receiver) }
  162. it 'renders two_factor_recovery_codes_changed mail' do
  163. expect(mail)
  164. .to be_present
  165. .and(have_subject(I18n.t('devise.mailer.two_factor_recovery_codes_changed.subject')))
  166. .and(have_body_text(I18n.t('devise.mailer.two_factor_recovery_codes_changed.explanation')))
  167. end
  168. end
  169. describe '#webauthn_credential_added' do
  170. let(:credential) { Fabricate.build(:webauthn_credential) }
  171. let(:mail) { described_class.webauthn_credential_added(receiver, credential) }
  172. it 'renders webauthn_credential_added mail' do
  173. expect(mail)
  174. .to be_present
  175. .and(have_subject(I18n.t('devise.mailer.webauthn_credential.added.subject')))
  176. .and(have_body_text(I18n.t('devise.mailer.webauthn_credential.added.explanation')))
  177. end
  178. end
  179. describe '#welcome' do
  180. let(:mail) { described_class.welcome(receiver) }
  181. it 'renders welcome mail' do
  182. expect(mail)
  183. .to be_present
  184. .and(have_subject(I18n.t('user_mailer.welcome.subject')))
  185. .and(have_body_text(I18n.t('user_mailer.welcome.explanation')))
  186. end
  187. end
  188. describe '#backup_ready' do
  189. let(:backup) { Fabricate(:backup) }
  190. let(:mail) { described_class.backup_ready(receiver, backup) }
  191. it 'renders backup_ready mail' do
  192. expect(mail)
  193. .to be_present
  194. .and(have_subject(I18n.t('user_mailer.backup_ready.subject')))
  195. .and(have_body_text(I18n.t('user_mailer.backup_ready.explanation')))
  196. end
  197. end
  198. end