Compare commits
2 Commits
7eaa8eacf8
...
c81a7a6160
| Author | SHA1 | Date |
|---|---|---|
|
|
c81a7a6160 | |
|
|
bbb710a5e1 |
4
app.rb
4
app.rb
|
|
@ -69,9 +69,11 @@ class App < Roda
|
||||||
rescue OpenURI::HTTPError
|
rescue OpenURI::HTTPError
|
||||||
response.status = 400
|
response.status = 400
|
||||||
return {message: "url not found"}.to_json
|
return {message: "url not found"}.to_json
|
||||||
|
rescue SocketError => e
|
||||||
|
response.status = 400
|
||||||
|
return {message: "url does not resolve"}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if links.filter(:url => url).first.nil?
|
if links.filter(:url => url).first.nil?
|
||||||
code = SecureRandom.urlsafe_base64 4
|
code = SecureRandom.urlsafe_base64 4
|
||||||
links.insert(url: url, code: code)
|
links.insert(url: url, code: code)
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ describe "Submit API request to create new link" do
|
||||||
expect(response_json['message']).to eq('invalid url parameter')
|
expect(response_json['message']).to eq('invalid url parameter')
|
||||||
end
|
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 = {
|
data = {
|
||||||
url: 'http://google.com/example'
|
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)
|
response_json = JSON.parse(last_response.body)
|
||||||
expect(response_json['message']).to eq('url not found')
|
expect(response_json['message']).to eq('url not found')
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue