|
21 | 21 | assert_equal 'multipart/form-data', media_type |
22 | 22 | end |
23 | 23 |
|
| 24 | + it "detects application/json as a JSON media type" do |
| 25 | + assert_equal true, Committee::SchemaValidator.json_media_type?("application/json") |
| 26 | + end |
| 27 | + |
| 28 | + it "detects application/problem+json with parameters as a JSON media type" do |
| 29 | + assert_equal true, Committee::SchemaValidator.json_media_type?("application/problem+json; charset=utf-8") |
| 30 | + end |
| 31 | + |
| 32 | + it "detects application/vnd.api+json as a JSON media type" do |
| 33 | + assert_equal true, Committee::SchemaValidator.json_media_type?("application/vnd.api+json") |
| 34 | + end |
| 35 | + |
| 36 | + it "does not detect application/x-ndjson as a JSON media type" do |
| 37 | + assert_equal false, Committee::SchemaValidator.json_media_type?("application/x-ndjson") |
| 38 | + end |
| 39 | + |
| 40 | + it "does not detect non-JSON content types as JSON media types" do |
| 41 | + assert_equal false, Committee::SchemaValidator.json_media_type?("test/csv") |
| 42 | + assert_equal false, Committee::SchemaValidator.json_media_type?(nil) |
| 43 | + end |
| 44 | + |
| 45 | + it "parses +json responses in the HyperSchema validator" do |
| 46 | + schema = Committee::Drivers::OpenAPI2::Driver.new.parse(open_api_2_data) |
| 47 | + validator_option = Committee::SchemaValidator::Option.new({ parse_response_by_content_type: true }, schema, :hyper_schema) |
| 48 | + router = Committee::SchemaValidator::HyperSchema::Router.new(schema, validator_option) |
| 49 | + request = Rack::Request.new({ "REQUEST_METHOD" => "GET", "PATH_INFO" => "/api/pets", "rack.input" => StringIO.new("") }) |
| 50 | + validator = Committee::SchemaValidator::HyperSchema.new(router, request, validator_option) |
| 51 | + |
| 52 | + validator.link.media_type = "application/vnd.api+json" |
| 53 | + |
| 54 | + validator.response_validate(200, { "Content-Type" => "application/vnd.api+json" }, [JSON.generate([ValidPet])]) |
| 55 | + end |
| 56 | + |
24 | 57 | it "builds prefix regexp with a path segment boundary" do |
25 | 58 | regexp = Committee::SchemaValidator.build_prefix_regexp("/v1") |
26 | 59 |
|
|
0 commit comments