Merge pull request #150 from koic/set_default_content_to_an_empty_array_instead_of_nil
Set default `content` to an empty array instead of `nil`
This commit is contained in:
commit
c5f2f98077
2 changed files with 14 additions and 3 deletions
|
|
@ -13,7 +13,7 @@ module MCP
|
|||
error = deprecated_error
|
||||
end
|
||||
|
||||
@content = content
|
||||
@content = content || []
|
||||
@error = error
|
||||
@structured_content = structured_content
|
||||
end
|
||||
|
|
|
|||
|
|
@ -101,13 +101,24 @@ module MCP
|
|||
refute actual[:isError]
|
||||
end
|
||||
|
||||
test "#to_h for a standard response with nil content and structured content" do
|
||||
structured_content = { code: 401, message: "Unauthorized" }
|
||||
response = Response.new(nil, structured_content: structured_content)
|
||||
actual = response.to_h
|
||||
|
||||
assert_equal [:content, :isError, :structuredContent], actual.keys
|
||||
assert_empty actual[:content]
|
||||
assert_equal structured_content, actual[:structuredContent]
|
||||
refute actual[:isError]
|
||||
end
|
||||
|
||||
test "#to_h for a standard response with structured content only" do
|
||||
structured_content = { code: 401, message: "Unauthorized" }
|
||||
response = Response.new(structured_content: structured_content)
|
||||
actual = response.to_h
|
||||
|
||||
assert_equal [:isError, :structuredContent], actual.keys
|
||||
assert_nil actual[:content]
|
||||
assert_equal [:content, :isError, :structuredContent], actual.keys
|
||||
assert_empty actual[:content]
|
||||
assert_equal structured_content, actual[:structuredContent]
|
||||
refute actual[:isError]
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue