Skip to content

Commit

Permalink
Merge branch 'EN-7393-event-confirmation-email' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-entourage committed Jan 10, 2025
2 parents e7b5828 + d4fa16f commit 6a7d0d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions app/mailers/group_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def event_created_confirmation event
)
end

def event_joined_confirmation event
user = event.user
def event_joined_confirmation event_id, user_id
event = Outing.find(event_id)
user = User.find(user_id)

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

Expand Down
7 changes: 4 additions & 3 deletions app/observers/join_request_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def action(verb, record)
end

def mailer(record)
if record.joinable.respond_to?(:outing?) && record.joinable.outing?
GroupMailer.event_joined_confirmation(record.joinable).deliver_later
end
return unless record.user
return unless record.joinable.respond_to?(:outing?) && record.joinable.outing?

GroupMailer.event_joined_confirmation(record.joinable_id, record.user_id).deliver_later
end
end
10 changes: 5 additions & 5 deletions spec/mailers/group_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'rails_helper'

describe GroupMailer, type: :mailer do
let(:user) { create :public_user }
let(:outing) { create :outing, user: user }
let(:participant) { create :public_user, first_name: 'Alice' }
let(:organizer) { create :public_user, first_name: 'Bob' }
let(:outing) { create :outing, user: organizer }

describe ".event_joined_confirmation" do
let(:user) { create :public_user }
let(:mail) { GroupMailer.event_joined_confirmation(outing) }
let(:mail) { GroupMailer.event_joined_confirmation(outing.id, participant.id) }
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['first_name']).to eq(participant.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") }
Expand Down

0 comments on commit 6a7d0d1

Please sign in to comment.