Skip to content

Commit

Permalink
Add tests to expose bug in appointment mail sending.
Browse files Browse the repository at this point in the history
When a member schedules a new appointment with the same time as
an existing one, we merge the appointments together. However, we were still
sending an email with an appointment argument that was the appointment that
no longer existed after the merge. This led to deserialization errors when the
mail job was later processed.
  • Loading branch information
jim committed Oct 12, 2023
1 parent b2913ef commit 13edb41
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/controllers/account/appointments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest
@appointment.save
end

private def assert_enqueued_email(mailer, method, params: {})
assert_enqueued_with(job: ActionMailer::MailDeliveryJob, args: ->(job_arguments) {
job_mailer, job_method, _delivery, rest = *job_arguments
assert_equal mailer.to_s, job_mailer
assert_equal method.to_s, job_method
assert_equal(params, rest[:params])
})
end

test "creates a new appointment to pickup items on hold" do
@hold = FactoryBot.create(:started_hold, member: @member)
@event = FactoryBot.create(:appointment_slot_event)
Expand All @@ -30,6 +39,26 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest
time_range_string: "#{@event.start}..#{@event.finish}"
}}

@appointment = @member.appointments.last
assert_enqueued_email(MemberMailer, :appointment_confirmation, params: {member: @member, appointment: @appointment})

assert_redirected_to account_appointments_path
assert_equal 1, @member.appointments.count
end

test "adds additional items to an existing appointment via creation form" do
create_appointment
@hold = FactoryBot.create(:started_hold, member: @member)

post account_appointments_path, params: {appointment: {
hold_ids: [@hold.id],
comment: "Excited to start on my project!",
time_range_string: "#{@appointment.starts_at}..#{@appointment.ends_at}"
}}

@appointment = @member.appointments.last
assert_enqueued_email(MemberMailer, :appointment_confirmation, params: {member: @member, appointment: @appointment})

assert_redirected_to account_appointments_path
assert_equal 1, @member.appointments.count
end
Expand Down

0 comments on commit 13edb41

Please sign in to comment.