Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/api_sim/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ def configure_fixture_directory(dir)
Dir[File.join(dir, "**/*.json.erb")].each do |path|
endpoint_match = path.match(%r{#{dir}([/\w+\_\-]+)/(GET|POST|PATCH|OPTIONS|HEAD|PUT|DELETE).json})
config = JSON.parse(File.read(path))
request_schema = config['request_schema'].to_json unless config['request_schema'].nil?
configure_endpoint endpoint_match[2],
endpoint_match[1],
config['body'].to_json,
config['status'],
config['headers'],
config['schema'].to_json
config['schema'].to_json,
request_schema: request_schema
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/path/to/response/POST.json.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"status": 201,
"headers": {
"content-type": "application/json"
},
"body": {
"id": 1,
"name": "Sammy"
},
"request_schema": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
}
}
}
}
11 changes: 11 additions & 0 deletions spec/http_sim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ def app
expect(response_body['id']).to eq 1
end

it 'validates json from fixture configuration' do
response = make_request_to 'POST', '/path/to/response', {'name': 'mom'}.to_json, 'application/json'

expect(response).to be_created

response = make_request_to 'POST', '/path/to/response', {'not_name': 'mom'}.to_json, 'application/json'

expect(response.status).to eq(498)

end

it 'records the incoming Content-Type' do
make_request_to 'POST', '/endpoint', {'hi': 'mom'}.to_json, 'application/foo'

Expand Down