VRFS-1665 added mail delivery test
This commit is contained in:
parent
f4533ebbf1
commit
f90f55fb11
|
|
@ -391,6 +391,23 @@
|
|||
end
|
||||
end
|
||||
|
||||
def scheduled_session_daily(receiver, sessions)
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => "scheduled_session_daily"
|
||||
|
||||
sendgrid_recipients([receiver.email])
|
||||
sendgrid_substitute('@USERID', [receiver.id])
|
||||
|
||||
@user = receiver
|
||||
|
||||
mail(:to => receiver.email,
|
||||
:subject => EmailBatchScheduledSessions.subject,
|
||||
:title => 'New Scheduled Sessions Matched to You') do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def band_session_join(email, msg, session_id)
|
||||
subject = "A band that you follow has joined a session"
|
||||
unique_args = {:type => "band_session_join"}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
<% provide(:title, 'Scheduled Session RSVP') %>
|
||||
|
||||
<p><%= @body %></p>
|
||||
|
||||
<p>
|
||||
<%= @session_name %><br/>
|
||||
<%= @session_date %>
|
||||
</p>
|
||||
|
||||
<p><a style="color: #588C98;" href="<%= @session_url %>">View Session Details</a></p>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<% provide(:title, @title) %>
|
||||
|
||||
<p>Hello <%= @user.first_name %> --
|
||||
</p>
|
||||
|
||||
<p>The following new sessions that that have been posted during the last 24 hours:
|
||||
</p>
|
||||
<ol>
|
||||
<li>Need someone who plays an instrument that you play</li>
|
||||
<li>Were posted by someone to whom you have either a good or medium latency connection</li>
|
||||
</ol>
|
||||
|
||||
<p>Take a look through these new sessions below, and just click the RSVP button on the far right side of the row for any session in which you'd like to play. This will let the session organizer know you're interested, and you'll be notified if the session organizer accepts your request to play in that session!
|
||||
</p>
|
||||
|
||||
HERE WE PRESENT THE SESSIONS IN A TABLE JUST LIKE THE FIND SESSION PAGE
|
||||
|
||||
<p>To see ALL the scheduled sessions that you might be interested in joining, view our Find Session page at: <a href="http://www.jamkazam.com/client#/findSession">http://www.jamkazam.com/client#/findSession</a>.
|
||||
</p>
|
||||
|
||||
<p>Best Regards,</p>
|
||||
|
||||
Team JamKazam
|
||||
|
|
@ -80,25 +80,29 @@ WHERE
|
|||
SQL
|
||||
results = ActiveRecord::Base.connection.execute(sql)
|
||||
results.each do |result|
|
||||
sql = "SELECT session_id, creator_id FROM #{TMP_USER} WHERE user_id = '#{result['user_id']}'"
|
||||
sql =<<SQL
|
||||
SELECT session_id, creator_id, user_id
|
||||
FROM #{TMP_USER}
|
||||
WHERE
|
||||
user_id = '#{result['user_id']}'
|
||||
SQL
|
||||
sessions = ActiveRecord::Base.connection.execute(sql).collect { |rr| rr['session_id'] }
|
||||
vals = result.clone
|
||||
vals['sessions'] = MusicSession.where(["id IN ('#{sessions.join("','")}')"])
|
||||
block_given? ? yield(vals) : objs << vals
|
||||
sched_sessions = MusicSession.where(["id IN ('#{sessions.join("','")}')"])
|
||||
receiver = User.find_by_id(result['user_id'])
|
||||
block_given? ? yield(receiver, sched_sessions) : objs << vals
|
||||
end
|
||||
objs
|
||||
ensure
|
||||
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{TMP_SNAP}")
|
||||
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS #{TMP_USER}")
|
||||
end
|
||||
|
||||
def deliver_batch_sets!
|
||||
self.opt_in_count = 0
|
||||
sent = 0
|
||||
self.fetch_recipients do |sess_creator, users|
|
||||
self.opt_in_count += users.size
|
||||
bset = EmailBatchSet.scheduled_session_set(self, sess_creator, users.map(&:id))
|
||||
UserMailer.scheduled_sessions(users).deliver
|
||||
self.fetch_recipients do |receiver, sessions|
|
||||
self.opt_in_count += 1
|
||||
sent += 1
|
||||
bset = EmailBatchSet.scheduled_session_set(self, receiver, sessions)
|
||||
UserMailer.scheduled_session_daily(receiver, sessions).deliver
|
||||
end
|
||||
self.sent_count = sent
|
||||
self.save
|
||||
|
|
@ -106,6 +110,9 @@ SQL
|
|||
end
|
||||
|
||||
def self.send_daily_session_batch
|
||||
oo = self.create
|
||||
oo..deliver_batch
|
||||
oo
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,6 +27,17 @@ module JamRuby
|
|||
bset
|
||||
end
|
||||
|
||||
def self.scheduled_session_set(batch, receiver, sessions)
|
||||
bset = self.new
|
||||
bset.email_batch = batch
|
||||
bset.user = receiver
|
||||
bset.user_ids = sessions.map(&:id).join(',')
|
||||
bset.started_at = Time.now
|
||||
bset.batch_count = 1
|
||||
bset.save!
|
||||
bset
|
||||
end
|
||||
|
||||
def subject
|
||||
unless sub_type.blank?
|
||||
return EmailBatchProgression.subject(self.sub_type.to_sym)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ describe EmailBatch do
|
|||
Timecop.return
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
UserMailer.deliveries.clear
|
||||
end
|
||||
|
||||
describe 'daily scheduled' do
|
||||
# before { pending }
|
||||
|
||||
|
|
@ -47,7 +51,11 @@ describe EmailBatch do
|
|||
:approval_required => false)
|
||||
end
|
||||
|
||||
before(:all) do
|
||||
before(:each) do
|
||||
MusicianInstrument.delete_all
|
||||
RsvpSlot.delete_all
|
||||
JamRuby::Score.delete_all
|
||||
|
||||
drummer.musician_instruments << FactoryGirl.build(:musician_instrument, user: drummer, instrument: drums, proficiency_level: 2)
|
||||
drummer.musician_instruments << FactoryGirl.build(:musician_instrument, user: drummer, instrument: guitar, proficiency_level: 2)
|
||||
|
||||
|
|
@ -74,16 +82,11 @@ describe EmailBatch do
|
|||
# oo = FactoryGirl.create(:rsvp_request, :user => vocalist, :rsvp_slot => oo)
|
||||
# oo.rsvp_request_slot.update_attributes(chosen: true)
|
||||
|
||||
JamRuby::Score.delete_all
|
||||
JamRuby::Score.createx(1, 'a', 1, 1, 'a', 1, 10)
|
||||
JamRuby::Score.createx(1, 'a', 1, 2, 'a', 2, Score::MAX_YELLOW_LATENCY + 1)
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
# @u1 = FactoryGirl.create(:user, :email => 'jonathan@jamkazam.com', :subscribe_email => true)
|
||||
# @u2 = FactoryGirl.create(:user, :subscribe_email => true)
|
||||
# @u3 = FactoryGirl.create(:user, :subscribe_email => false)
|
||||
# @u4 = FactoryGirl.create(:user, :subscribe_email => true)
|
||||
end
|
||||
|
||||
it 'sets up data properly' do
|
||||
|
|
@ -93,5 +96,11 @@ describe EmailBatch do
|
|||
expect(obj.count).to eq(3)
|
||||
end
|
||||
|
||||
it 'sends email' do
|
||||
ebatch = scheduled_batch
|
||||
ebatch.deliver_batch
|
||||
expect(UserMailer.deliveries.length).to eq(3)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue