Skip to content

Commit

Permalink
EN-7393 event confirmation email
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-entourage committed Jan 10, 2025
1 parent 9e85c98 commit 1198705
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
29 changes: 26 additions & 3 deletions app/mailers/group_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class GroupMailer < MailjetMailer
def event_created_confirmation event
event_creator = event.user
user = event.user

IcalService.attach_ical(group: event, for_user: event_creator, to: self)
IcalService.attach_ical(group: event, for_user: user, to: self)

mailjet_email(
to: event_creator,
to: user,
campaign_name: :event_created_confirmation,
template_id: 491291,
variables: [
Expand All @@ -18,4 +18,27 @@ def event_created_confirmation event
]
)
end

def event_joined_confirmation event
user = event.user

IcalService.attach_ical(group: event, for_user: user, to: self)

mailjet_email(
to: user,
campaign_name: :event_joined_confirmation,
template_id: 6174412,
variables: {
outing: {
name: event.title,
address: event.event_url,
date: I18n.l(event.metadata[:starts_at].to_date, format: :short, locale: user.lang),
hour: event.metadata[:starts_at].strftime("%Hh%M"),
image_url: event.image_url_with_size(:landscape_url, :medium),
calendar_url: event.calendar_url,
url: event.share_url
}
}
)
end
end
7 changes: 7 additions & 0 deletions app/models/entourage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ def share_url_model
:solicitations
end

def calendar_url
return unless outing?
return unless uuid_v2

"#{share_url}/agenda"
end

class << self
def share_url model
"#{ENV['MOBILE_HOST']}/app/#{model}"
Expand Down
8 changes: 8 additions & 0 deletions app/observers/join_request_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class JoinRequestObserver < ActiveRecord::Observer

def after_create(record)
action(:create, record)

mailer(record)
end

def after_update(record)
Expand All @@ -28,4 +30,10 @@ def action(verb, record)
rescue
# we want this hook to never fail the main process
end

def mailer(record)
if record.joinable.respond_to?(:outing?) && record.joinable.outing?
GroupMailer.event_joined_confirmation(record.joinable).deliver_later
end
end
end
17 changes: 17 additions & 0 deletions spec/mailers/group_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

describe GroupMailer, type: :mailer do
let(:user) { create :public_user }
let(:outing) { create :outing, user: user }

describe ".event_joined_confirmation" do
let(:user) { create :public_user }
let(:mail) { GroupMailer.event_joined_confirmation(outing) }
let(:json_variables) { JSON.parse(mail['X-MJ-Vars'].value) }

it { expect(json_variables['first_name']).to eq(user.first_name) }
it { expect(json_variables).to have_key("outing") }
it { expect(json_variables['outing']['name']).to eq(outing.title) }
it { expect(json_variables['outing']['calendar_url']).to match("agenda") }
end
end
23 changes: 23 additions & 0 deletions spec/observers/join_request_observer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rails_helper'

describe JoinRequestObserver do
describe "mailer" do
let(:join_request) { create :join_request, joinable: joinable }

context "outing membership does trigger mailer" do
let(:joinable) { create(:outing) }

before { expect_any_instance_of(GroupMailer).to receive(:event_joined_confirmation) }

it { join_request }
end

context "neighborhood membership does not trigger mailer" do
let(:joinable) { create(:neighborhood) }

before { expect_any_instance_of(GroupMailer).not_to receive(:event_joined_confirmation) }

it { join_request }
end
end
end

0 comments on commit 1198705

Please sign in to comment.