Files
codeocean/spec/mailers/user_mailer_spec.rb

182 lines
6.0 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe UserMailer do
let(:user) { InternalUser.create(attributes_for(:teacher)) }
describe '#activation_needed_email' do
let(:mail) { described_class.activation_needed_email(user) }
before do
user.send(:setup_activation)
user.save(validate: false)
end
it 'sets the correct sender' do
expect(mail.from).to include(CodeOcean::Application.config.action_mailer[:default_options][:from])
end
it 'sets the correct subject' do
expect(mail.subject).to eq(I18n.t('mailers.user_mailer.activation_needed.subject'))
end
it 'sets the correct receiver' do
expect(mail.to).to include(user.email)
end
it 'includes the correct URL' do
expect(mail.body).to include(activate_internal_user_url(user, token: user.activation_token))
end
end
describe '#activation_success_email' do
it 'does not raise an error' do
expect { described_class.activation_success_email(user) }.not_to raise_error
end
end
describe '#reset_password_email' do
let(:mail) { described_class.reset_password_email(user) }
before do
user.send(:setup_activation)
user.save(validate: false)
end
it 'sets the correct sender' do
expect(mail.from).to include(CodeOcean::Application.config.action_mailer[:default_options][:from])
end
it 'sets the correct subject' do
expect(mail.subject).to eq(I18n.t('mailers.user_mailer.reset_password.subject'))
end
it 'sets the correct receiver' do
expect(mail.to).to include(user.email)
end
it 'includes the correct URL' do
expect(mail.body).to include(reset_password_internal_user_url(user, token: user.reset_password_token))
end
end
describe '#got_new_comment' do
let(:user) { create(:learner) }
let(:token) { AuthenticationToken.find_by(user: user) }
let(:request_for_comment) { create(:rfc_with_comment, user: user) }
let(:commenting_user) { InternalUser.create(attributes_for(:teacher)) }
let(:mail) { described_class.got_new_comment(request_for_comment.comments.first, request_for_comment, commenting_user).deliver_now }
it 'sets the correct sender' do
expect(mail.from).to include(CodeOcean::Application.config.action_mailer[:default_options][:from])
end
it 'sets the correct subject' do
expect(mail.subject).to eq(I18n.t('mailers.user_mailer.got_new_comment.subject', commenting_user_displayname: commenting_user.displayname))
end
it 'sets the correct receiver' do
expect(mail.to).to include(request_for_comment.user.email)
end
it 'includes the correct URL' do
expect(mail.body).to include(request_for_comment_url(request_for_comment))
end
it 'includes the correct authentication token' do
expect(mail.body).to include(token.shared_secret)
end
it 'sets a new authentication token' do
expect { mail }.to change(AuthenticationToken, :count).by(1)
end
it 'sets a non expired authentication token' do
mail
expect(token.expire_at.future?).to be(true)
token.expire_at -= 8.days
expect(token.expire_at.future?).to be(false)
end
end
describe '#got_new_comment_for_subscription' do
let(:user) { create(:learner) }
let(:token) { AuthenticationToken.find_by(user: user) }
let(:request_for_comment) { create(:rfc_with_comment, user: user) }
let(:subscription) { Subscription.create(request_for_comment: request_for_comment, user: user) }
let(:from_user) { InternalUser.create(attributes_for(:teacher)) }
let(:mail) { described_class.got_new_comment_for_subscription(request_for_comment.comments.first, subscription, from_user).deliver_now }
it 'sets the correct sender' do
expect(mail.from).to include(CodeOcean::Application.config.action_mailer[:default_options][:from])
end
it 'sets the correct subject' do
expect(mail.subject).to eq(I18n.t('mailers.user_mailer.got_new_comment_for_subscription.subject', author_displayname: from_user.displayname))
end
it 'sets the correct receiver' do
expect(mail.to).to include(subscription.user.email)
end
it 'includes the correct URL' do
expect(mail.body).to include(request_for_comment_url(subscription.request_for_comment))
end
it 'includes the correct authentication token' do
expect(mail.body).to include(token.shared_secret)
end
it 'sets a new authentication token' do
expect { mail }.to change(AuthenticationToken, :count).by(1)
end
it 'sets a non expired authentication token' do
mail
expect(token.expire_at.future?).to be(true)
token.expire_at -= 8.days
expect(token.expire_at.future?).to be(false)
end
end
describe '#send_thank_you_note' do
let(:user) { create(:learner) }
let(:token) { AuthenticationToken.find_by(user: user) }
let(:request_for_comments) { create(:rfc_with_comment, user: user) }
let(:receiver) { InternalUser.create(attributes_for(:teacher)) }
let(:mail) { described_class.send_thank_you_note(request_for_comments, receiver).deliver_now }
it 'sets the correct sender' do
expect(mail.from).to include(CodeOcean::Application.config.action_mailer[:default_options][:from])
end
it 'sets the correct subject' do
expect(mail.subject).to eq(I18n.t('mailers.user_mailer.send_thank_you_note.subject', author: request_for_comments.user.displayname))
end
it 'sets the correct receiver' do
expect(mail.to).to include(receiver.email)
end
it 'includes the correct URL' do
expect(mail.body).to include(request_for_comment_url(request_for_comments))
end
it 'includes the correct authentication token' do
expect(mail.body).to include(token.shared_secret)
end
it 'sets a new authentication token' do
expect { mail }.to change(AuthenticationToken, :count).by(1)
end
it 'sets a non expired authentication token' do
mail
expect(token.expire_at.future?).to be(true)
token.expire_at -= 8.days
expect(token.expire_at.future?).to be(false)
end
end
end