|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | + |
| 5 | +module MCP |
| 6 | + class ResourceTemplateTest < ActiveSupport::TestCase |
| 7 | + test "#to_h does not have `:icons` key when icons is empty" do |
| 8 | + resource_template = ResourceTemplate.new( |
| 9 | + uri_template: "file:///{path}", |
| 10 | + name: "resource_template_without_icons", |
| 11 | + description: "a resource template without icons", |
| 12 | + ) |
| 13 | + |
| 14 | + refute resource_template.to_h.key?(:icons) |
| 15 | + end |
| 16 | + |
| 17 | + test "#to_h does not have `:icons` key when icons is nil" do |
| 18 | + resource_template = ResourceTemplate.new( |
| 19 | + uri_template: "file:///{path}", |
| 20 | + name: "resource_template_without_icons", |
| 21 | + description: "a resource template without icons", |
| 22 | + icons: nil, |
| 23 | + ) |
| 24 | + |
| 25 | + refute resource_template.to_h.key?(:icons) |
| 26 | + end |
| 27 | + |
| 28 | + test "#to_h includes icons when present" do |
| 29 | + resource_template = ResourceTemplate.new( |
| 30 | + uri_template: "file:///{path}", |
| 31 | + name: "resource_template_with_icons", |
| 32 | + description: "a resource template with icons", |
| 33 | + icons: [Icon.new(mime_type: "image/png", sizes: ["48x48"], src: "https://example.com", theme: "light")], |
| 34 | + ) |
| 35 | + expected_icons = [{ mimeType: "image/png", sizes: ["48x48"], src: "https://example.com", theme: "light" }] |
| 36 | + |
| 37 | + assert_equal expected_icons, resource_template.to_h[:icons] |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments