Skip to content

Commit 978ff04

Browse files
committed
update copy and add test for resp content type
1 parent 35c8cf9 commit 978ff04

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/open_api_spex/test/test_assertions.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ defmodule OpenApiSpex.TestAssertions do
167167

168168
if is_nil(resolved_schema) do
169169
flunk(
170-
"Failed to resolve schema! Unable to find a response for operation_id: #{operation_id} for response status code: #{conn.status} and content type #{content_type}"
170+
"Failed to resolve schema! Unable to find a response schema for operation_id: #{operation_id} for status code: #{conn.status} and content type: #{content_type}"
171171
)
172172
end
173173

test/test_assertions_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,26 @@ defmodule OpenApiSpex.TestAssertionsTest do
158158
"Value does not conform to schema PetResponse: Failed to cast value to one of: no schemas validate at"
159159
end
160160
end
161+
162+
test "returns an error when the response content-type does not match the schema" do
163+
conn =
164+
:get
165+
|> Plug.Test.conn("/api/pets")
166+
|> Plug.Conn.put_req_header("content-type", "application/json")
167+
|> Plug.Conn.put_resp_header("content-type", "unexpected-content-type")
168+
169+
conn = OpenApiSpexTest.Router.call(conn, [])
170+
171+
assert conn.status == 200
172+
173+
try do
174+
TestAssertions.assert_operation_response(conn, "showPetById")
175+
raise RuntimeError, "Should flunk"
176+
rescue
177+
e in ExUnit.AssertionError ->
178+
assert e.message =~
179+
"Failed to resolve schema! Unable to find a response schema for operation_id: showPetById for status code: 200 and content type: unexpected-content-type"
180+
end
181+
end
161182
end
162183
end

0 commit comments

Comments
 (0)