From 533a3551e90debef09fc29686dab26ce71c93cd5 Mon Sep 17 00:00:00 2001 From: Felix Clack Date: Fri, 27 Sep 2024 15:26:41 +0100 Subject: [PATCH] Only highlight known restrictions There are cases where a record will have restrictions that we don't want to highlight. We only display the restrictons tag if the code is listed in the `Sanction::SANCTIONS` constant. --- app/lib/qualifications_api/teacher.rb | 2 +- spec/lib/qualifications_api/teacher_spec.rb | 30 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/lib/qualifications_api/teacher.rb b/app/lib/qualifications_api/teacher.rb index 90b9f09f..1b7df163 100644 --- a/app/lib/qualifications_api/teacher.rb +++ b/app/lib/qualifications_api/teacher.rb @@ -46,7 +46,7 @@ def restriction_status end def no_restrictions? - return true if sanctions.blank? || sanctions.all?(&:guilty_but_not_prohibited?) + return true if sanctions.blank? || sanctions.all?(&:guilty_but_not_prohibited?) || sanctions.map(&:title).join.blank? false end diff --git a/spec/lib/qualifications_api/teacher_spec.rb b/spec/lib/qualifications_api/teacher_spec.rb index 623f8b9d..01f24b65 100644 --- a/spec/lib/qualifications_api/teacher_spec.rb +++ b/spec/lib/qualifications_api/teacher_spec.rb @@ -425,7 +425,7 @@ let(:api_data) do { "sanctions" => [ - { "guiltyButNotProhibited" => true }, + { "code" => "T6", "start_date" => "2024-01-01" }, { "possibleMatchOnChildrensBarredList" => true } ] } @@ -434,11 +434,35 @@ it { is_expected.to be_falsey } end - context "when there are sanctions" do + context "when there are sanctions that are not prohibited" do let(:api_data) do { "sanctions" => [ - { "guiltyButNotProhibited" => true }, + { "code" => "T6", "start_date" => "2024-01-01" }, + ] + } + end + + it { is_expected.to be_truthy } + end + + context "when there are sanctions not listed in the Sanction model" do + let(:api_data) do + { + "sanctions" => [ + { "code" => "T7", "start_date" => "2024-01-01" }, + ] + } + end + + it { is_expected.to be_truthy } + end + + context "when there are sanctions that are prohibited" do + let(:api_data) do + { + "sanctions" => [ + { "code" => "A13", "start_date" => "2024-01-01" }, ] } end