Skip to content

Commit

Permalink
added tests for redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRuiz committed Jan 22, 2019
1 parent ff35796 commit 88e3a92
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
12 changes: 12 additions & 0 deletions spec/nice_http/nice_http_delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@
expect(resp.data.json).to eq ({ example: "mock" })
end

it 'doesn\'t redirect when auto_redirect is false and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = false
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.delete(req)
expect(resp.code).to eq 303
end

end
6 changes: 6 additions & 0 deletions spec/nice_http/nice_http_get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
expect(resp.message).to eq 'Found'
end

it 'handles correctly when http or https is on path' do
resp = @http.get 'https://www.reqres.in/api/users?page=2'
expect(resp.code).to eq 200
expect(resp.message).to eq 'OK'
end

it 'set the cookies when required' do
server = "https://samples.auth0.com/"
path = "/authorize?client_id=kbyuFDidLLm280LIwVFiazOqjO3ty8KH&response_type=code"
Expand Down
24 changes: 24 additions & 0 deletions spec/nice_http/nice_http_head_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,29 @@
expect(http.cookies['/'].key?("auth0")).to eq true
end

it 'redirects when auto_redirect is true and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = true
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.head(req)
expect(resp.code).to eq 200
expect(resp.message).to eq 'OK'
end

it 'doesn\'t redirect when auto_redirect is false and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = false
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.head(req)
expect(resp.code).to eq 303
end

end
27 changes: 26 additions & 1 deletion spec/nice_http/nice_http_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@
expect(resp.data.json(:name)).to eq 'peter'
end

#todo: add tests for redirection, headers, encoding and cookies
it 'redirects when auto_redirect is true and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = true
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.patch(req)
expect(resp.code).to eq 200
expect(resp.message).to eq 'OK'
end

it 'doesn\'t redirect when auto_redirect is false and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = false
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.patch(req)
expect(resp.code).to eq 303
end

#todo: add tests for headers, encoding and cookies

end
27 changes: 26 additions & 1 deletion spec/nice_http/nice_http_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@
expect(resp.data.json(:name)).to eq 'peter'
end

#todo: add tests for redirection, headers, encoding and cookies
it 'redirects when auto_redirect is true and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = true
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.post(req)
expect(resp.code).to eq 200
expect(resp.message).to eq 'OK'
end

it 'doesn\'t redirect when auto_redirect is false and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = false
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.post(req)
expect(resp.code).to eq 303
end

#todo: add tests headers, encoding and cookies

end
14 changes: 13 additions & 1 deletion spec/nice_http/nice_http_put_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
expect(resp.data.json(:name)).to eq 'peter'
end

#todo: add tests for redirection, headers, encoding and cookies
it 'doesn\'t redirect when auto_redirect is false and http code is 30x' do
server = "http://examplesinatra--tcblues.repl.co/"
http = NiceHttp.new(server)
http.auto_redirect = false
req = {
path: '/exampleRedirect',
data: {example: 'example'},
}
resp = http.put(req)
expect(resp.code).to eq 303
end

#todo: add tests for headers, encoding and cookies

end

0 comments on commit 88e3a92

Please sign in to comment.