Compare commits
2 Commits
ac3e9f14cd
...
cabb4daded
| Author | SHA1 | Date |
|---|---|---|
|
|
cabb4daded | |
|
|
1e61a76ded |
9
app.rb
9
app.rb
|
|
@ -50,9 +50,14 @@ class App < Roda
|
||||||
end
|
end
|
||||||
|
|
||||||
url = r.params['url']
|
url = r.params['url']
|
||||||
if url.nil? or url.empty?
|
if url.nil?
|
||||||
response.status = 400
|
response.status = 400
|
||||||
return {message: "Please enter a valid URL"}
|
return {message: "missing url parameter"}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
if url.empty?
|
||||||
|
response.status = 400
|
||||||
|
return {message: "invalid url parameter"}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
if links.filter(:url => url).first.nil?
|
if links.filter(:url => url).first.nil?
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ describe "Submit API request to create new link" do
|
||||||
after :each do
|
after :each do
|
||||||
@links.delete
|
@links.delete
|
||||||
end
|
end
|
||||||
it "should return link data in json format when a valid url is entered" do
|
it "should return link data in json format when a valid url is submitted" do
|
||||||
data = {
|
data = {
|
||||||
url: 'http://google.com'
|
url: 'http://google.com'
|
||||||
}
|
}
|
||||||
|
|
@ -36,5 +36,25 @@ describe "Submit API request to create new link" do
|
||||||
expect(response_json['code']).not_to eq(nil)
|
expect(response_json['code']).not_to eq(nil)
|
||||||
expect(response_json['link']).to include(response_json['code'])
|
expect(response_json['link']).to include(response_json['code'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return with a 400 status and 'invalid url parameter' message when an empty url is submitted" do
|
||||||
|
data = {
|
||||||
|
url: ''
|
||||||
|
}
|
||||||
|
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('invalid url parameter')
|
||||||
|
|
||||||
|
end
|
||||||
|
it "should return with a 400 status and 'missing url parameter' message when an empty url is submitted" do
|
||||||
|
data = {
|
||||||
|
}
|
||||||
|
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('missing url parameter')
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue