Skip to content

Commit

Permalink
Remove references to accredited provider in about_your_organisation_form
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Dec 18, 2024
1 parent 1f8f048 commit 57cb781
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 66 deletions.
47 changes: 1 addition & 46 deletions app/forms/publish/about_your_organisation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class AboutYourOrganisationForm < BaseProviderForm
validates :train_with_us, words_count: { maximum: 250, message: 'Reduce the word count for training with you' }
validates :train_with_disability, words_count: { maximum: 250, message: 'Reduce the word count for training with disabilities and other needs' }

validate :add_enrichment_errors

def initialize(model, params: {}, redirect_params: {}, course_code: nil)
super(model, params:)
@redirect_params = redirect_params
Expand All @@ -21,18 +19,11 @@ def initialize(model, params: {}, redirect_params: {}, course_code: nil)
FIELDS = %i[
train_with_us
train_with_disability
accrediting_provider_enrichments
].freeze

attr_accessor(*FIELDS)
attr_reader :redirect_params, :course_code

def accredited_bodies
@accredited_bodies ||= provider.accredited_bodies.map do |ab|
accredited_provider(**ab)
end
end

def update_success_path
case redirection_key
when 'goto_preview'
Expand Down Expand Up @@ -76,48 +67,12 @@ def changed?(attribute)
public_send(attribute) != provider.public_send(attribute)
end

def accredited_provider(provider_name:, provider_code:, description:)
AccreditedProvider.new(
provider_name:,
provider_code:,
description: params_description(provider_code) || description
)
end

def params_description(provider_code)
params[:accredited_bodies].to_h { |i| [i[:provider_code], i[:description]] }[provider_code] if params&.dig(:accredited_bodies).present?
end

def accrediting_provider_enrichments
accredited_bodies.map do |accredited_provider|
{
UcasProviderCode: accredited_provider.provider_code,
Description: accredited_provider.description
}
end
end

def compute_fields
provider.attributes.symbolize_keys.slice(*FIELDS).merge(new_attributes)
end

def new_attributes
params.except(:accredited_bodies).merge(accrediting_provider_enrichments:)
end

def add_enrichment_errors
accredited_bodies&.each_with_index do |accredited_provider, _index|
errors.add :accredited_bodies, accredited_provider.errors[:description].first if accredited_provider.invalid?
end
end

class AccreditedProvider
include ActiveModel::Model
validates :description, words_count: { maximum: 100, message: lambda do |object, _data|
"Reduce the word count for #{object.provider_name}"
end }

attr_accessor :provider_name, :provider_code, :description
params
end

def redirection_key
Expand Down
21 changes: 1 addition & 20 deletions spec/forms/publish/about_your_organisation_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ module Publish
end
let(:train_with_us) { 'train_with_us' }
let(:train_with_disability) { 'train_with_disability' }
let(:provider) do
create(
:provider,
accrediting_provider_enrichments: [
{ UcasProviderCode: accredited_provider.provider_code }
]
)
end
let(:accredited_provider) { create(:provider, :accredited_provider) }
let(:provider) { create(:provider) }
let(:redirect_params) { { 'goto_preview' => 'true' } }
let(:course_code) { create(:course) }

Expand Down Expand Up @@ -50,17 +42,6 @@ module Publish
end
end

describe '#accredited_bodies' do
it 'returns an array of accredited_providers' do
expect(subject.accredited_bodies).to include(
have_attributes(
provider_name: accredited_provider.provider_name,
provider_code: accredited_provider.provider_code
)
)
end
end

describe '#update_success_path' do
context 'when goto_preview is true' do
it 'returns the goto_preview path' do
Expand Down

0 comments on commit 57cb781

Please sign in to comment.