changed send_thank_you_note and got_new_comment_for_subscription methods to use tokens properly, as well as new test scenarios for both cases
This commit is contained in:

committed by
Sebastian Serth

parent
cc3fc72cf9
commit
146eee673f
@ -60,4 +60,122 @@ describe UserMailer 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
|
||||
|
Reference in New Issue
Block a user