Compare commits

..

2 Commits

2 changed files with 14 additions and 2 deletions

4
app.rb
View File

@ -69,9 +69,11 @@ class App < Roda
rescue OpenURI::HTTPError
response.status = 400
return {message: "url not found"}.to_json
rescue SocketError => e
response.status = 400
return {message: "url does not resolve"}.to_json
end
if links.filter(:url => url).first.nil?
code = SecureRandom.urlsafe_base64 4
links.insert(url: url, code: code)

View File

@ -66,7 +66,7 @@ describe "Submit API request to create new link" do
expect(response_json['message']).to eq('invalid url parameter')
end
it "should return with a 400 status and 'url not found' message when an invalid url is submitted" do
it "should return with a 400 status and 'url not found' message when a 404 url is submitted" do
data = {
url: 'http://google.com/example'
}
@ -75,4 +75,14 @@ describe "Submit API request to create new link" do
response_json = JSON.parse(last_response.body)
expect(response_json['message']).to eq('url not found')
end
it "should return with a 400 status and 'url not found' message when a URL with no DNS is submitted" do
data = {
url: 'http://bad.tld'
}
post('/links', data.to_json, "CONTENT_TYPE" => "application/json")
expect(last_response.status).to eq(400)
response_json = JSON.parse(last_response.body)
expect(response_json['message']).to eq('url does not resolve')
end
end