Skip to content

Commit

Permalink
Add protection type image details to specialist document model
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leenagupte committed Jan 20, 2025
1 parent c74eabc commit df0e093
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/specialist_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions spec/models/specialist_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit df0e093

Please sign in to comment.