From 1e61a76ded54d266dac19a3de45e19b1f5b75e1d Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Thu, 12 Oct 2023 14:27:02 -0700 Subject: [PATCH] added 2 more tests for empty and missing url data posting to links --- spec/create_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/create_spec.rb b/spec/create_spec.rb index a088c88..c814803 100644 --- a/spec/create_spec.rb +++ b/spec/create_spec.rb @@ -25,7 +25,7 @@ describe "Submit API request to create new link" do after :each do @links.delete 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 = { 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['link']).to include(response_json['code']) 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