Compare commits
2 Commits
dfb6b23e70
...
ae2360a480
| Author | SHA1 | Date |
|---|---|---|
|
|
ae2360a480 | |
|
|
213265a5d0 |
3
app.rb
3
app.rb
|
|
@ -47,7 +47,8 @@ class App < Roda
|
||||||
r.on "links" do
|
r.on "links" do
|
||||||
r.post do
|
r.post do
|
||||||
if 'application/json' != r.headers['CONTENT_TYPE']
|
if 'application/json' != r.headers['CONTENT_TYPE']
|
||||||
return {message: "Not a valid JSON request"}.to_json
|
response.status = 400
|
||||||
|
return {message: "not a valid json request"}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
url = r.params['url']
|
url = r.params['url']
|
||||||
|
|
|
||||||
|
|
@ -88,4 +88,14 @@ describe "Submit API request to create new link" do
|
||||||
response_json = JSON.parse(last_response.body)
|
response_json = JSON.parse(last_response.body)
|
||||||
expect(response_json['message']).to eq('url does not resolve')
|
expect(response_json['message']).to eq('url does not resolve')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return with a 400 status and 'not a valid json request' message when a request is made with the wrong content type header" do
|
||||||
|
data = {
|
||||||
|
url: 'http://google.com'
|
||||||
|
}
|
||||||
|
post('/links', data.to_json)
|
||||||
|
expect(last_response.status).to eq(400)
|
||||||
|
response_json = JSON.parse(last_response.body)
|
||||||
|
expect(response_json['message']).to eq('not a valid json request')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue