generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4494 from DFE-Digital/CST-2265b_add_services_for_…
…sit_ab_reminder_comms [CST-2265] (part 2) Add services and queries to support bulk mailer for AB comms
- Loading branch information
Showing
6 changed files
with
449 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/queries/ects/with_an_appropriate_body_and_unregistered_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ects | ||
class WithAnAppropriateBodyAndUnregisteredQuery < BaseService | ||
def call | ||
InductionRecord | ||
.active | ||
.training_status_active | ||
.joins(:participant_profile) | ||
.where(participant_profile: { induction_start_date: nil, type: "ParticipantProfile::ECT" }) | ||
.joins(induction_programme: :school_cohort) | ||
.where(induction_programme: { training_programme: training_programme_types }) | ||
.where("induction_records.appropriate_body_id IS NOT NULL OR school_cohorts.appropriate_body_id IS NOT NULL") | ||
end | ||
|
||
private | ||
|
||
attr_reader :include_fip, :include_cip | ||
|
||
def initialize(include_fip: true, include_cip: true) | ||
@include_fip = include_fip | ||
@include_cip = include_cip | ||
end | ||
|
||
def training_programme_types | ||
training_programmes = [] | ||
training_programmes << "full_induction_programme" if include_fip | ||
training_programmes << "core_induction_programme" if include_cip | ||
training_programmes | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
app/queries/ects/without_an_appropriate_body_and_unregistered_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ects | ||
class WithoutAnAppropriateBodyAndUnregisteredQuery < BaseService | ||
def call | ||
InductionRecord | ||
.active | ||
.training_status_active | ||
.joins(:participant_profile) | ||
.where(participant_profile: { induction_start_date: nil, type: "ParticipantProfile::ECT" }) | ||
.joins(induction_programme: :school_cohort) | ||
.where(induction_programme: { training_programme: training_programme_types }) | ||
.where(appropriate_body_id: nil) | ||
.where(school_cohort: { appropriate_body_id: nil }) | ||
end | ||
|
||
private | ||
|
||
attr_reader :include_fip, :include_cip | ||
|
||
def initialize(include_fip: true, include_cip: true) | ||
@include_fip = include_fip | ||
@include_cip = include_cip | ||
end | ||
|
||
def training_programme_types | ||
training_programmes = [] | ||
training_programmes << "full_induction_programme" if include_fip | ||
training_programmes << "core_induction_programme" if include_cip | ||
training_programmes | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
spec/queries/ects/with_an_appropriate_body_and_unregistered_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Ects::WithAnAppropriateBodyAndUnregisteredQuery do | ||
describe "#call" do | ||
let(:fip_ab) { create(:seed_appropriate_body, :valid) } | ||
let(:cip_ab) { create(:seed_appropriate_body, :valid) } | ||
|
||
let(:fip_school_cohort) { create(:seed_school_cohort, :fip, :valid, appropriate_body: fip_ab) } | ||
let(:cip_school_cohort) { create(:seed_school_cohort, :cip, :valid, appropriate_body: cip_ab) } | ||
let(:fip_induction_programme) { create(:seed_induction_programme, :fip, school_cohort: fip_school_cohort) } | ||
let(:cip_induction_programme) { create(:seed_induction_programme, :cip, school_cohort: cip_school_cohort) } | ||
|
||
let(:fip_participant_profile) { create(:seed_ect_participant_profile, :valid, school_cohort: fip_school_cohort) } | ||
let(:cip_participant_profile) { create(:seed_ect_participant_profile, :valid, school_cohort: cip_school_cohort) } | ||
|
||
let(:include_fip) { true } | ||
let(:include_cip) { true } | ||
|
||
let!(:fip_induction_record) do | ||
create(:seed_induction_record, :valid, participant_profile: fip_participant_profile, induction_programme: fip_induction_programme) | ||
end | ||
|
||
let!(:cip_induction_record) do | ||
create(:seed_induction_record, :valid, participant_profile: cip_participant_profile, induction_programme: cip_induction_programme) | ||
end | ||
|
||
subject(:query_result) { described_class.call(include_fip:, include_cip:) } | ||
|
||
context "when there are ECTs without induction start dates" do | ||
context "when the school has an AB selected" do | ||
it "returns the induction records for the participants without induction start dates" do | ||
expect(query_result).to match_array [fip_induction_record, cip_induction_record] | ||
end | ||
|
||
context "when CIP is not included" do | ||
let(:include_cip) { false } | ||
|
||
it "does not return CIP participants" do | ||
expect(query_result).to match_array [fip_induction_record] | ||
end | ||
end | ||
|
||
context "when FIP is not included" do | ||
let(:include_fip) { false } | ||
|
||
it "does not return FIP participants" do | ||
expect(query_result).to match_array [cip_induction_record] | ||
end | ||
end | ||
end | ||
|
||
context "when the participant has an AB selected" do | ||
before do | ||
fip_induction_record.update!(appropriate_body: fip_ab) | ||
cip_induction_record.update!(appropriate_body: cip_ab) | ||
fip_school_cohort.update!(appropriate_body: nil) | ||
cip_school_cohort.update!(appropriate_body: nil) | ||
end | ||
|
||
it "returns the induction records for the participants without induction start dates" do | ||
expect(query_result).to match_array [fip_induction_record, cip_induction_record] | ||
end | ||
|
||
context "when CIP is not included" do | ||
let(:include_cip) { false } | ||
|
||
it "does not return CIP participants" do | ||
expect(query_result).to match_array [fip_induction_record] | ||
end | ||
end | ||
|
||
context "when FIP is not included" do | ||
let(:include_fip) { false } | ||
|
||
it "does not return FIP participants" do | ||
expect(query_result).to match_array [cip_induction_record] | ||
end | ||
end | ||
end | ||
|
||
context "when an AB is not selected" do | ||
let(:fip_ab) { nil } | ||
|
||
it "does not return participants" do | ||
expect(query_result).to match_array [cip_induction_record] | ||
end | ||
end | ||
end | ||
|
||
context "when there are ECTs with induction start dates" do | ||
before do | ||
cip_participant_profile.update!(induction_start_date: 1.week.ago) | ||
end | ||
|
||
it "does not return those participants" do | ||
expect(query_result).to match_array [fip_induction_record] | ||
end | ||
end | ||
end | ||
end |
82 changes: 82 additions & 0 deletions
82
spec/queries/ects/without_an_appropriate_body_and_unregistered_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Ects::WithoutAnAppropriateBodyAndUnregisteredQuery do | ||
describe "#call" do | ||
let(:fip_school_cohort) { create(:seed_school_cohort, :fip, :valid) } | ||
let(:cip_school_cohort) { create(:seed_school_cohort, :cip, :valid) } | ||
let(:fip_induction_programme) { create(:seed_induction_programme, :fip, school_cohort: fip_school_cohort) } | ||
let(:cip_induction_programme) { create(:seed_induction_programme, :cip, school_cohort: cip_school_cohort) } | ||
|
||
let(:fip_participant_profile) { create(:seed_ect_participant_profile, :valid, school_cohort: fip_school_cohort) } | ||
let(:cip_participant_profile) { create(:seed_ect_participant_profile, :valid, school_cohort: cip_school_cohort) } | ||
|
||
let(:include_fip) { true } | ||
let(:include_cip) { true } | ||
|
||
let!(:fip_induction_record) do | ||
create(:seed_induction_record, :valid, participant_profile: fip_participant_profile, induction_programme: fip_induction_programme) | ||
end | ||
|
||
let!(:cip_induction_record) do | ||
create(:seed_induction_record, :valid, participant_profile: cip_participant_profile, induction_programme: cip_induction_programme) | ||
end | ||
|
||
subject(:query_result) { described_class.call(include_fip:, include_cip:) } | ||
|
||
context "when there are ECTs without induction start dates" do | ||
context "when no AB is selected" do | ||
it "returns the induction records for the participants without induction start dates" do | ||
expect(query_result).to match_array [fip_induction_record, cip_induction_record] | ||
end | ||
|
||
context "when CIP is not included" do | ||
let(:include_cip) { false } | ||
|
||
it "does not return CIP participants" do | ||
expect(query_result).to match_array [fip_induction_record] | ||
end | ||
end | ||
|
||
context "when FIP is not included" do | ||
let(:include_fip) { false } | ||
|
||
it "does not return FIP participants" do | ||
expect(query_result).to match_array [cip_induction_record] | ||
end | ||
end | ||
end | ||
|
||
context "when the school has an AB" do | ||
before do | ||
fip_school_cohort.update!(appropriate_body: create(:seed_appropriate_body, :valid)) | ||
end | ||
|
||
it "does not return those participants" do | ||
expect(query_result).to match_array [cip_induction_record] | ||
end | ||
end | ||
|
||
context "when the participant has an AB" do | ||
before do | ||
cip_induction_record.update!(appropriate_body: create(:seed_appropriate_body, :valid)) | ||
end | ||
|
||
it "does not return those participants" do | ||
expect(query_result).to match_array [fip_induction_record] | ||
end | ||
end | ||
end | ||
|
||
context "when there are ECTs with induction start dates" do | ||
before do | ||
cip_participant_profile.update!(induction_start_date: 1.week.ago) | ||
end | ||
|
||
it "does not return those participants" do | ||
expect(query_result).to match_array [fip_induction_record] | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.