From df0e093056603fa53d4f026d4df4e411e8184588 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Mon, 20 Jan 2025 17:58:36 +0000 Subject: [PATCH] Add protection type image details to specialist document model This is to get the images when the document type is "protected_food_drink_name". It might be worth separating this into a separate model and presenter. --- app/models/specialist_document.rb | 10 ++++++ .../protected_food_drink_name/images.yaml | 9 ++++++ spec/models/specialist_document_spec.rb | 32 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/data/specialist_documents/protected_food_drink_name/images.yaml diff --git a/app/models/specialist_document.rb b/app/models/specialist_document.rb index 81d2327e7a..eb5beda68a 100644 --- a/app/models/specialist_document.rb +++ b/app/models/specialist_document.rb @@ -12,6 +12,12 @@ def initialize(content_store_response) @headers = headers_list(content_store_hash.dig("details", "headers")) end + def protection_type_image + return if protection_type.blank? + + all_protection_type_images[protection_type] + end + private def headers_list(headers) @@ -31,4 +37,8 @@ def headers_list(headers) h end end + + def all_protection_type_images + @all_protection_type_images ||= YAML.load_file(Rails.root.join("lib/data/specialist_documents/protected_food_drink_name/images.yaml")) + end end diff --git a/lib/data/specialist_documents/protected_food_drink_name/images.yaml b/lib/data/specialist_documents/protected_food_drink_name/images.yaml new file mode 100644 index 0000000000..c1be856c51 --- /dev/null +++ b/lib/data/specialist_documents/protected_food_drink_name/images.yaml @@ -0,0 +1,9 @@ +protected-designation-of-origin-pdo: + file_name: protected-designation-of-origin-pdo.png + alt_text_tag: pdo_alt_text +protected-geographical-indication-pgi: + file_name: protected-geographical-indication-pgi.png + alt_text_tag: pgi_alt_text +traditional-speciality-guaranteed-tsg: + file_name: traditional-speciality-guaranteed-tsg.png + alt_text_tag: tsg_alt_text \ No newline at end of file diff --git a/spec/models/specialist_document_spec.rb b/spec/models/specialist_document_spec.rb index 3a73ded8a8..298a5bd8ff 100644 --- a/spec/models/specialist_document_spec.rb +++ b/spec/models/specialist_document_spec.rb @@ -66,4 +66,36 @@ end end end + + describe "protection type images" do + let(:content_store_response) { GovukSchemas::Example.find("specialist_document", example_name: "protected-food-drink-names") } + + context "when a protection type exists and is known" do + it "gets the image details" do + content_store_response["details"]["metadata"]["protection_type"] = "protected-designation-of-origin-pdo" + expected = { + "file_name" => "protected-designation-of-origin-pdo.png", + "alt_text_tag" => "pdo_alt_text", + } + + expect(described_class.new(content_store_response).protection_type_image).to eq(expected) + end + end + + context "when a protection type exists but is not recognised" do + it "returns nil" do + content_store_response["details"]["metadata"]["protection_type"] = "fake-type" + + expect(described_class.new(content_store_response).protection_type_image).to be_nil + end + end + + context "when a protection type does not exist" do + it "returns nil" do + content_store_response["details"]["metadata"]["protection_type"] = nil + + expect(described_class.new(content_store_response).protection_type_image).to be_nil + end + end + end end