diff --git a/app/mailers/mentor_mailer.rb b/app/mailers/mentor_mailer.rb index 04c85049e9..961038cb4c 100644 --- a/app/mailers/mentor_mailer.rb +++ b/app/mailers/mentor_mailer.rb @@ -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( @@ -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 diff --git a/app/services/induction/change_mentor.rb b/app/services/induction/change_mentor.rb index 82cffb90a3..d8969debd4 100644 --- a/app/services/induction/change_mentor.rb +++ b/app/services/induction/change_mentor.rb @@ -26,17 +26,16 @@ 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 @@ -44,19 +43,9 @@ def sit_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 diff --git a/spec/mailers/mentor_mailer_spec.rb b/spec/mailers/mentor_mailer_spec.rb index 72a3bcea7c..d143820704 100644 --- a/spec/mailers/mentor_mailer_spec.rb +++ b/spec/mailers/mentor_mailer_spec.rb @@ -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 diff --git a/spec/services/induction/change_mentor_spec.rb b/spec/services/induction/change_mentor_spec.rb index f5899f2469..d369669ea8 100644 --- a/spec/services/induction/change_mentor_spec.rb +++ b/spec/services/induction/change_mentor_spec.rb @@ -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 @@ -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