Skip to content

Commit

Permalink
Rework after having redesigned the template
Browse files Browse the repository at this point in the history
  • Loading branch information
edujackedu committed Feb 23, 2024
1 parent a4bd665 commit 9b8fade
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 139 deletions.
14 changes: 6 additions & 8 deletions app/mailers/mentor_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class MentorMailer < ApplicationMailer
MATERIALS_TEMPLATE = "d5409fd3-bad6-4e98-97d7-69363d2921c8"

def training_materials
mentor_email = params[:mentor_email]
mentor_name = params[:mentor_name]
school_name = params[:school_name]
mentor_profile = params[:mentor_profile]
mentor_email = mentor_profile.user.email
mentor_name = mentor_profile.user.full_name
ect_name = params[:ect_name]
lead_provider_name = params[:lead_provider_name]
cip_materials_name = params[:cip_materials_name]
sit_name = params[:sit_name]

template_mail(
Expand All @@ -18,13 +18,11 @@ def training_materials
rails_mail_template: action_name,
personalisation: {
subject: "Access training materials for your new early career teacher",
mentor_email:,
mentor_name:,
school_name:,
ect_name:,
lead_provider_name:,
cip_materials_name:,
sit_name:,
},
)
).tag(:send_cip_materials_to_mentor).associate_with(mentor_profile, as: :mentor_profile)
end
end
27 changes: 8 additions & 19 deletions app/services/induction/change_mentor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,26 @@ def initialize(induction_record:, mentor_profile: nil)

def send_training_materials
MentorMailer.with(
mentor_email: mentor_profile.user.email,
mentor_name: mentor_profile.user.full_name,
school_name: induction_record.school.name,
mentor_profile:,
ect_name: induction_record.participant_profile.user.full_name,
lead_provider_name: induction_record.lead_provider.name,
sit_name: induction_record.school.induction_tutor.full_name,
).training_materials.deliver_later
cip_materials_name: cip_materials.name,
sit_name:,
).training_materials
.deliver_later
end

def materials(profile)
profile.school_cohort.default_induction_programme&.core_induction_programme&.name
def cip_materials
induction_record.induction_programme.core_induction_programme
end

def sit_name
induction_record.school.induction_tutor&.full_name
end

def send_training_materials_if_needed
return unless mentor_profile&.school_cohort
return unless sit_name

# CIP and CIP but different materials
if mentor_profile.school_cohort.cip? &&
induction_record.participant_profile.school_cohort.cip? &&
materials(mentor_profile).present? &&
(materials(mentor_profile) != materials(induction_record.participant_profile))
send_training_materials
end

# Mentor at FIP school but mentor is CIP ECT
if mentor_profile.school_cohort.fip? && induction_record.participant_profile.school_cohort.cip?
if induction_record.enrolled_in_cip? && cip_materials.present?
send_training_materials
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/mailers/mentor_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

let(:training_materials_email) do
MentorMailer.with(
mentor_email: mentor_profile.user.email,
mentor_name: mentor_profile.user.full_name,
mentor_profile:,
school_name: induction_record.school.name,
ect_name: induction_record.participant_profile.user.full_name,
lead_provider_name: induction_record.lead_provider.name,
cip_materials_name: "Core Induction Programme",
sit_name: induction_record.school.induction_tutor.full_name,
).training_materials.deliver_now
end
Expand Down
124 changes: 15 additions & 109 deletions spec/services/induction/change_mentor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,112 +37,10 @@
expect(MentorMailer).not_to have_received(:with)
end

describe "sending training materials" do
let(:cip_school_cohort) { create :school_cohort, :cip }
let(:fip_school_cohort) { create :school_cohort, :fip }
let(:materials_1) { "1" }
let(:materials_2) { "2" }

context "with CIP induction programme" do
let!(:sit) { create(:induction_coordinator_profile, schools: [induction_record.school]).user }

context "the mentor is at a CIP school and the ECT is at a CIP school" do
context "with same training materials" do
let(:school_cohort_1) do
create(
:school_cohort,
:cip,
default_induction_programme: create(
:induction_programme,
:cip,
core_induction_programme: create(
:core_induction_programme,
name: materials_1,
),
),
)
end

let(:school_cohort_2) do
create(
:school_cohort,
:cip,
default_induction_programme: create(
:induction_programme,
:cip,
core_induction_programme: create(
:core_induction_programme,
name: materials_1,
),
),
)
end

let!(:ect_profile) { create(:ect_participant_profile, school_cohort: school_cohort_1) }
let!(:mentor_profile_2) { create(:mentor_participant_profile, school_cohort: school_cohort_2) }

it "does not send the email" do
allow(MentorMailer).to receive(:with).and_call_original

service.call(induction_record:, mentor_profile: mentor_profile_2)

expect(MentorMailer).not_to have_received(:with)
end
end

context "with different training materials" do
let(:school_cohort_1) do
create(
:school_cohort,
:cip,
default_induction_programme: create(
:induction_programme,
:cip,
core_induction_programme: create(
:core_induction_programme,
name: materials_1,
),
),
)
end

let(:school_cohort_2) do
create(
:school_cohort,
:cip,
default_induction_programme: create(
:induction_programme,
:cip,
core_induction_programme: create(
:core_induction_programme,
name: materials_2,
),
),
)
end

let!(:ect_profile) { create(:ect_participant_profile, school_cohort: school_cohort_1) }
let!(:mentor_profile_2) { create(:mentor_participant_profile, school_cohort: school_cohort_2) }

it "sends the email" do
allow(MentorMailer).to receive(:with).and_call_original

service.call(induction_record:, mentor_profile: mentor_profile_2)

expect(MentorMailer).to have_received(:with).with({
ect_name: ect_profile.user.full_name,
sit_name: sit.full_name,
lead_provider_name: induction_record.lead_provider.name,
mentor_email: mentor_profile_2.user.email,
mentor_name: mentor_profile_2.user.full_name,
school_name: induction_record.school.name,
})
end
end
end

context "the mentor is at a FIP school and the ECT is at a CIP school" do
let(:ect_profile) { create(:ect_participant_profile, school_cohort: cip_school_cohort) }
let(:mentor_profile_2) { create(:mentor_participant_profile, school_cohort: fip_school_cohort) }
context "with SIT" do
let(:induction_programme) { create(:induction_programme, :cip, school_cohort:) }

it "sends the email" do
allow(MentorMailer).to receive(:with).and_call_original
Expand All @@ -152,13 +50,21 @@
expect(MentorMailer).to have_received(:with).with({
ect_name: ect_profile.user.full_name,
sit_name: sit.full_name,
lead_provider_name: induction_record.lead_provider.name,
mentor_email: mentor_profile_2.user.email,
mentor_name: mentor_profile_2.user.full_name,
school_name: induction_record.school.name,
mentor_profile: mentor_profile_2,
cip_materials_name: induction_record.induction_programme.core_induction_programme.name,
})
end
end

context "without SIT" do
it "does not send material email" do
allow(MentorMailer).to receive(:with).and_call_original

service.call(induction_record:, mentor_profile: mentor_profile_2)

expect(MentorMailer).not_to have_received(:with)
end
end
end
end
end

0 comments on commit 9b8fade

Please sign in to comment.