Repository: DFE-Digital/early-careers-framework
Pull request #5692: [CPDLP-4182] Update school serializer to return the new programme type based on feature
Author: login: mooktakim
Created: 2025-04-04T11:07:02Z | Merged: 2025-04-11T14:59:00Z

### Context

- Ticket: https://dfedigital.atlassian.net/browse/CPDLP-4182

### Changes proposed in this pull request

* `Api::V3::ECF::SchoolSerializer` updated to return new programme mapping when `programme_type_changes_2025` feature is enabled.

### Guidance to review




Diff:
diff --git a/app/serializers/api/v3/ecf/school_serializer.rb b/app/serializers/api/v3/ecf/school_serializer.rb
index c142c92ddd..43397669cf 100644
--- a/app/serializers/api/v3/ecf/school_serializer.rb
+++ b/app/serializers/api/v3/ecf/school_serializer.rb
@@ -41,7 +41,8 @@ def school_cohort_for(school:, cohort:)
 
         attribute :induction_programme_choice do |school, params|
           school_cohort = school_cohort_for(school:, cohort: params[:cohort])
-          school_cohort&.induction_programme_choice.presence || "not_yet_known"
+          choice = school_cohort&.induction_programme_choice.presence || "not_yet_known"
+          ProgrammeTypeMappings.training_programme(training_programme: choice)
         end
 
         attribute :created_at do |school|
diff --git a/spec/serializers/api/v3/ecf/school_serializer_spec.rb b/spec/serializers/api/v3/ecf/school_serializer_spec.rb
index 3864cb156c..fed47d969a 100644
--- a/spec/serializers/api/v3/ecf/school_serializer_spec.rb
+++ b/spec/serializers/api/v3/ecf/school_serializer_spec.rb
@@ -51,16 +51,79 @@ module ECF
             end
           end
 
-          context "when the school is already in the cohort" do
-            let!(:school_cohort) { create(:school_cohort, school:, cohort:) }
-            it "returns the school cohort induction_programme_choice" do
-              expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq(school_cohort.induction_programme_choice)
+          context "when 'programme_type_changes_2025' feature is disabled" do
+            before { FeatureFlag.deactivate(:programme_type_changes_2025) }
+
+            %w[
+              full_induction_programme
+              core_induction_programme
+              design_our_own
+              school_funded_fip
+              no_early_career_teachers
+              not_yet_known
+            ].each do |induction_programme_choice|
+              context "when the school is already in the cohort with '#{induction_programme_choice}'" do
+                let!(:school_cohort) { create(:school_cohort, school:, cohort:, induction_programme_choice:) }
+
+                it "returns the school cohort induction_programme_choice" do
+                  expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq(induction_programme_choice)
+                end
+              end
+            end
+
+            context "when school is not yet in the cohort" do
+              it "returns the an unknown induction programme choice" do
+                expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("not_yet_known")
+              end
             end
           end
 
-          context "when school is not yet in the cohort" do
-            it "returns the an unknown induction programme choice" do
-              expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("not_yet_known")
+          context "when 'programme_type_changes_2025' feature is enabled" do
+            before { FeatureFlag.activate(:programme_type_changes_2025) }
+
+            %w[
+              full_induction_programme
+              school_funded_fip
+            ].each do |induction_programme_choice|
+              context "when the school is already in the cohort with '#{induction_programme_choice}'" do
+                let!(:school_cohort) { create(:school_cohort, school:, cohort:, induction_programme_choice:) }
+
+                it "returns the updated induction_programme_choice" do
+                  expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("provider_led")
+                end
+              end
+            end
+
+            %w[
+              core_induction_programme
+              design_our_own
+            ].each do |induction_programme_choice|
+              context "when the school is already in the cohort with '#{induction_programme_choice}'" do
+                let!(:school_cohort) { create(:school_cohort, school:, cohort:, induction_programme_choice:) }
+
+                it "returns the updated induction_programme_choice" do
+                  expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("school_led")
+                end
+              end
+            end
+
+            %w[
+              no_early_career_teachers
+              not_yet_known
+            ].each do |induction_programme_choice|
+              context "when the school is already in the cohort with '#{induction_programme_choice}'" do
+                let!(:school_cohort) { create(:school_cohort, school:, cohort:, induction_programme_choice:) }
+
+                it "returns the school cohort induction_programme_choice" do
+                  expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq(induction_programme_choice)
+                end
+              end
+            end
+
+            context "when school is not yet in the cohort" do
+              it "returns the an unknown induction programme choice" do
+                expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("not_yet_known")
+              end
             end
           end
 
diff --git a/spec/services/programme_type_mappings_spec.rb b/spec/services/programme_type_mappings_spec.rb
index f7dbdf7b73..24070b96fe 100644
--- a/spec/services/programme_type_mappings_spec.rb
+++ b/spec/services/programme_type_mappings_spec.rb
@@ -56,45 +56,48 @@
       context "when mappings are enabled" do
         let(:mappings_enabled) { true }
 
-        %i[full_induction_programme school_funded_fip].each do |induction_programme_type|
-          context "when training_programme is '#{induction_programme_type}'" do
-            let(:training_programme) { build(:induction_programme, induction_programme_type).training_programme }
+        %w[full_induction_programme school_funded_fip].each do |param|
+          context "when training_programme is '#{param}'" do
+            let(:training_programme) { param }
 
             it { is_expected.to eq("provider_led") }
           end
         end
 
-        %i[core_induction_programme design_our_own].each do |induction_programme_type|
-          context "when training_programme is '#{induction_programme_type}'" do
-            let(:training_programme) { build(:induction_programme, induction_programme_type).training_programme }
+        %w[core_induction_programme design_our_own].each do |param|
+          context "when training_programme is '#{param}'" do
+            let(:training_programme) { param }
 
             it { is_expected.to eq("school_led") }
           end
         end
 
-        context "when training_programme is anything else" do
-          let(:training_programme) { :anything_else }
+        %w[no_early_career_teachers not_yet_known].each do |param|
+          context "when training_programme is '#{param}'" do
+            let(:training_programme) { param }
 
-          it { is_expected.to eq(training_programme) }
+            it { is_expected.to eq(training_programme) }
+          end
         end
       end
 
       context "when mappings are disabled" do
         let(:mappings_enabled) { false }
 
-        %i[fip school_funded_fip cip design_our_own].each do |induction_programme_type|
-          context "when training_programme is '#{induction_programme_type}'" do
-            let(:training_programme) { build(:induction_programme, induction_programme_type).training_programme }
+        %w[
+          full_induction_programme
+          school_funded_fip
+          core_induction_programme
+          design_our_own
+          no_early_career_teachers
+          not_yet_known
+        ].each do |param|
+          context "when training_programme is '#{param}'" do
+            let(:training_programme) { param }
 
             it { is_expected.to eq(training_programme) }
           end
         end
-
-        context "when training_programme is anything else" do
-          let(:training_programme) { :anything_else }
-
-          it { is_expected.to eq(training_programme) }
-        end
       end
     end
   end


Reviews:
user: login: cwrw
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T06:20:02Z
user: login: cwrw
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T06:21:00Z
user: login: leandroalemao
body: Think base branch would be Ross' branch instead? All good tks
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T14:30:42Z
user: login: ethax-ross
body: Looks good, I've just merged the service down so should be good to rebase shortly
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-07T15:01:47Z
user: login: cwrw
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-08T06:31:48Z

Review comments:
diff_hunk: @@ -51,16 +51,49 @@ module ECF
             end
           end
 
-          context "when the school is already in the cohort" do
-            let!(:school_cohort) { create(:school_cohort, school:, cohort:) }
-            it "returns the school cohort induction_programme_choice" do
-              expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq(school_cohort.induction_programme_choice)
+          context "when 'programme_type_changes_2025' feature is disabled" do
+            before { FeatureFlag.deactivate(:programme_type_changes_2025) }
+
+            %w[core_induction_programme full_induction_programme].each do |induction_programme_choice|
path: spec/serializers/api/v3/ecf/school_serializer_spec.rb
user: login: cwrw
body: could we add the other examples in the test please:
```
design_our_own
school_funded_fip
no_early_career_teachers
```
created_at: 2025-04-07T06:20:02Z
author_association: CONTRIBUTOR
diff_hunk: @@ -51,16 +51,49 @@ module ECF
             end
           end
 
-          context "when the school is already in the cohort" do
-            let!(:school_cohort) { create(:school_cohort, school:, cohort:) }
-            it "returns the school cohort induction_programme_choice" do
-              expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq(school_cohort.induction_programme_choice)
+          context "when 'programme_type_changes_2025' feature is disabled" do
+            before { FeatureFlag.deactivate(:programme_type_changes_2025) }
+
+            %w[core_induction_programme full_induction_programme].each do |induction_programme_choice|
+              context "when the school is already in the cohort with '#{induction_programme_choice}'" do
+                let!(:school_cohort) { create(:school_cohort, school:, cohort:, induction_programme_choice:) }
+
+                it "returns the school cohort induction_programme_choice" do
+                  expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq(induction_programme_choice)
+                end
+              end
+            end
+
+            context "when school is not yet in the cohort" do
+              it "returns the an unknown induction programme choice" do
+                expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("not_yet_known")
+              end
             end
           end
 
-          context "when school is not yet in the cohort" do
-            it "returns the an unknown induction programme choice" do
-              expect(subject.serializable_hash[:data][:attributes][:induction_programme_choice]).to eq("not_yet_known")
+          context "when 'programme_type_changes_2025' feature is enabled" do
+            before { FeatureFlag.activate(:programme_type_changes_2025) }
+
+            context "when the school is already in the cohort with 'core_induction_programme'" do
path: spec/serializers/api/v3/ecf/school_serializer_spec.rb
user: login: cwrw
body: same here around the mappings please:
```
design_our_own
school_funded_fip
no_early_career_teachers
```
where `no_early_career_teachers` should also be returned the same
created_at: 2025-04-07T06:21:00Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-04-07T06:05:54Z
body: Review app deployed to https://cpd-ecf-review-5692-web.test.teacherservices.cloud
<!-- Sticky Pull Request Comment -->
author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-04-11T08:51:51Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=DFE-Digital_early-careers-framework&pullRequest=5692) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=DFE-Digital_early-careers-framework&pullRequest=5692&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=DFE-Digital_early-careers-framework&pullRequest=5692&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=DFE-Digital_early-careers-framework&pullRequest=5692&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=DFE-Digital_early-careers-framework&pullRequest=5692&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=DFE-Digital_early-careers-framework&pullRequest=5692&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=DFE-Digital_early-careers-framework&pullRequest=5692)


author_association: NONE