osem-fcy/spec/models/email_settings_spec.rb

120 lines
4.7 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2016-03-26 22:04:44 +05:30
require 'spec_helper'
describe EmailSettings do
let(:conference) { create(:conference, short_title: 'goto', start_date: Date.new(2014, 05, 01), end_date: Date.new(2014, 05, 06)) }
let(:user) { create(:user, username: 'johnd', email: 'john@doe.com', name: 'John Doe') }
let(:event) { create(:event, program: conference.program, title: 'Talk about talks', submitter: user) }
2016-03-26 22:04:44 +05:30
let(:expected_hash) do
{
2018-11-13 18:01:49 -08:00
'email' => 'john@doe.com',
'name' => 'John Doe',
'conference' => conference.title,
'conference_start_date' => Date.new(2014, 05, 01),
'conference_end_date' => Date.new(2014, 05, 06),
'registrationlink' => 'http://localhost:3000/conferences/goto/register',
'conference_splash_link' => 'http://localhost:3000/conferences/goto',
2018-11-13 18:01:49 -08:00
'schedule_link' => 'http://localhost:3000/conferences/goto/schedule',
'cfp_end_date' => 'Unknown',
'cfp_start_date' => 'Unknown',
'venue' => 'Unknown',
'venue_address' => 'Unknown'
2016-03-26 22:04:44 +05:30
}
end
describe '#get_values' do
context 'user has name' do
it 'returns correct key-value pairs' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'user does not have name' do
before do
user.update(name: nil)
username_hash = { 'name' => 'johnd' }
expected_hash.merge!(username_hash)
end
it 'returns correct key-value pairs with username as name' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
2016-03-26 22:04:44 +05:30
end
context 'conference has cfp' do
before do
create(:cfp,
start_date: Date.new(2014, 04, 29),
2018-11-13 18:01:49 -08:00
end_date: Date.new(2014, 05, 06),
program: conference.program)
cfp_dates_hash = { 'cfp_start_date' => Date.new(2014, 04, 29), 'cfp_end_date' => Date.new(2014, 05, 06) }
expected_hash.merge!(cfp_dates_hash)
2016-03-26 22:04:44 +05:30
end
it 'returns hash with cfp start and end date' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'conference has venue' do
before do
conference.venue = create(:venue)
2016-05-02 15:25:18 +02:00
venue_hash = { 'venue' => conference.venue.name, 'venue_address' => conference.venue.address }
2016-03-26 22:04:44 +05:30
expected_hash.merge!(venue_hash)
end
it 'returns hash with venue and venue_address' do
2016-03-26 22:04:44 +05:30
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'conference has registration period' do
before do
conference.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 03),
end_date: Date.new(2014, 05, 05))
registration_period_hash = { 'registration_start_date' => Date.new(2014, 05, 03), 'registration_end_date' => Date.new(2014, 05, 05) }
expected_hash.merge!(registration_period_hash)
2016-03-26 22:04:44 +05:30
end
it 'returns hash with registration_start_date and registration_end_date' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'conference has event' do
before do
event_hash = { 'eventtitle' => 'Talk about talks', 'proposalslink' => 'http://localhost:3000/conferences/goto/program/proposals' }
2016-03-26 22:04:44 +05:30
expected_hash.merge!(event_hash)
end
it 'returns hash with eventtitle and proposalslink' do
2016-03-26 22:04:44 +05:30
expect(conference.email_settings.get_values(conference, user, event)).to eq expected_hash
end
end
end
describe '#generate_event_mail' do
let(:event_template) do
"Dear {name}\n\nWe are very pleased" \
'to inform you that your submission {eventtitle} has been accepted for the conference {conference}.'
end
it 'replaces fillers in template' do
expected_text = "Dear John Doe\n\nWe are very pleased" \
2016-05-02 15:25:18 +02:00
"to inform you that your submission Talk about talks has been accepted for the conference #{conference.title}."
2016-03-26 22:04:44 +05:30
expect(conference.email_settings.generate_event_mail(event, event_template)).to eq expected_text
end
end
describe '#generate_email_on_conf_updates' do
let(:conf_update_template) { "Dear {name},\n\nThank you for Registering for the conference {conference}." }
it 'replaces fillers in template' do
2016-05-02 15:25:18 +02:00
expected_text = "Dear John Doe,\n\nThank you for Registering for the conference #{conference.title}."
2016-03-26 22:04:44 +05:30
expect(conference.email_settings.generate_email_on_conf_updates(conference, user, conf_update_template)).to eq expected_text
end
end
end