Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPQ capping update the npq csv serialiser to surface funded place #4843

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/serializers/api/v1/npq_application_csv_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def csv_headers
teacher_catchment_iso_country_code
itt_provider
lead_mentor
]
].tap do |headers|
headers.insert(12, "funded_place") if FeatureFlag.active?(:npq_capping)
end
end

def to_row(record)
Expand Down Expand Up @@ -86,7 +88,9 @@ def to_row(record)
record.teacher_catchment_iso_country_code,
record.itt_provider,
record.lead_mentor,
]
].tap do |row|
row.insert(12, record.funded_place.to_s) if FeatureFlag.active?(:npq_capping)
end
end

def teacher_catchment(record)
Expand Down
8 changes: 6 additions & 2 deletions app/serializers/api/v2/npq_application_csv_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def csv_headers
targeted_delivery_funding_eligibility
itt_provider
lead_mentor
]
].tap do |headers|
headers.insert(12, "funded_place") if FeatureFlag.active?(:npq_capping)
end
end

def to_row(record)
Expand Down Expand Up @@ -80,7 +82,9 @@ def to_row(record)
record.targeted_delivery_funding_eligibility,
record.itt_provider,
record.lead_mentor,
]
].tap do |row|
row.insert(12, record.funded_place) if FeatureFlag.active?(:npq_capping)
end
end

def updated_at(record)
Expand Down
8 changes: 6 additions & 2 deletions app/serializers/api/v2/npq_enrolments_csv_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def call
object.npq_application.eligible_for_funding,
object.training_status,
object.school_urn,
]
].tap do |r|
r.insert(6, object.npq_application.funded_place) if FeatureFlag.active?(:npq_capping)
end

csv << row
end
Expand All @@ -42,7 +44,9 @@ def headers
eligible_for_funding
training_status
school_urn
]
].tap do |headers|
headers.insert(6, "funded_place") if FeatureFlag.active?(:npq_capping)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/services/npq/npq_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

trait :accepted do
after :create do |npq_application|
NPQ::Application::Accept.new(npq_application:).call
NPQ::Application::Accept.new(npq_application:, funded_place: npq_application.funded_place).call
npq_application.reload
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/serializers/api/v1/npq_application_csv_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ module V1
expect(rows[0]["itt_provider"]).to eql(npq_application.itt_provider)
expect(rows[0]["lead_mentor"]).to eql(npq_application.lead_mentor.to_s)
end

describe "funded_place" do
context "when Feature Flag `npq_capping` is active" do
before { FeatureFlag.activate(:npq_capping) }

it "returns funded place" do
npq_application.update!(funded_place: true)

expect(rows[0]["funded_place"]).to eql("true")
end
end

context "when Feature Flag `npq_capping` is inactive" do
before { FeatureFlag.deactivate(:npq_capping) }

it "does not return funded place attribute" do
expect(rows[0]).to_not include("funded_place")
end
end
end
end

describe "#updated_at" do
Expand Down
20 changes: 20 additions & 0 deletions spec/serializers/api/v2/npq_application_csv_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ module V2
expect(rows[0]["itt_provider"]).to eql(npq_application.itt_provider)
expect(rows[0]["lead_mentor"]).to eql(npq_application.lead_mentor.to_s)
end

describe "funded_place" do
context "when Feature Flag `npq_capping` is active" do
before { FeatureFlag.activate(:npq_capping) }

it "returns funded place" do
npq_application.update!(funded_place: true)

expect(rows[0]["funded_place"]).to eql("true")
end
end

context "when Feature Flag `npq_capping` is inactive" do
before { FeatureFlag.deactivate(:npq_capping) }

it "does not return funded place attribute" do
expect(rows[0]).to_not include("funded_place")
end
end
end
end

describe "#updated_at" do
Expand Down
61 changes: 61 additions & 0 deletions spec/serializers/api/v2/npq_enrolments_csv_serializer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Api::V2::NPQEnrolmentsCsvSerializer do
let(:npq_application) do
create(:npq_application,
:accepted,
eligible_for_funding: true,
npq_course:,
npq_lead_provider:)
end
let(:npq_lead_provider) { create(:npq_lead_provider) }
let(:npq_course) { create(:npq_leadership_course, identifier: "npq-senior-leadership") }
let(:funding_cap) { 10 }
let!(:statement) do
create(
:npq_statement,
:next_output_fee,
cpd_lead_provider: npq_lead_provider.cpd_lead_provider,
cohort: npq_application.cohort,
)
end
let!(:npq_contract) do
create(
:npq_contract,
npq_lead_provider:,
cohort: statement.cohort,
course_identifier: npq_course.identifier,
version: statement.contract_version,
funding_cap:,
)
end

let(:participant_profile) { npq_application.profile }
subject { described_class.new(scope: [participant_profile]).call }

describe "serialization" do
let(:rows) { CSV.parse(subject, headers: true) }

describe "funded_place" do
context "when Feature Flag `npq_capping` is active" do
before { FeatureFlag.activate(:npq_capping) }

it "returns funded place" do
npq_application.update!(funded_place: true)

expect(rows[0]["funded_place"]).to eql("true")
end
end

context "when Feature Flag `npq_capping` is inactive" do
before { FeatureFlag.deactivate(:npq_capping) }

it "does not return funded place attribute" do
expect(rows[0]).to_not include("funded_place")
end
end
end
end
end
Loading