mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 16:41:18 +08:00
283b08d45f
* Move onebox gem in core library * Update template file path * Remove warning for onebox gem caching * Remove onebox version file * Remove onebox gem * Add sanitize gem * Require onebox library in lazy-yt plugin * Remove onebox web specific code This code was used in standalone onebox Sinatra application * Merge Discourse specific AllowlistedGenericOnebox engine in core * Fix onebox engine filenames to match class name casing * Move onebox specs from gem into core * DEV: Rename `response` helper to `onebox_response` Fixes a naming collision. * Require rails_helper * Don't use `before/after(:all)` * Whitespace * Remove fakeweb * Remove poor unit tests * DEV: Re-add fakeweb, plugins are using it * Move onebox helpers * Stub Instagram API * FIX: Follow additional redirect status codes (#476) Don’t throw errors if we encounter 303, 307 or 308 HTTP status codes in responses * Remove an empty file * DEV: Update the license file Using the copy from https://choosealicense.com/licenses/gpl-2.0/# Hopefully this will enable GitHub to show the license UI? * DEV: Update embedded copyrights * DEV: Add Onebox copyright notice * DEV: Add MIT license, convert COPYRIGHT.txt to md * DEV: Remove an incorrect copyright claim Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: jbrw <jamie@goatforce5.org>
71 lines
3.0 KiB
Ruby
71 lines
3.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe Onebox::StatusCheck do
|
|
before do
|
|
stub_request(:get, "http://www.amazon.com/200-url").to_return(status: 200)
|
|
stub_request(:get, "http://www.amazon.com/201-url").to_return(status: 201)
|
|
stub_request(:get, "http://www.amazon.com/401-url").to_return(status: 401)
|
|
stub_request(:get, "http://www.amazon.com/403-url").to_return(status: 403)
|
|
stub_request(:get, "http://www.amazon.com/404-url").to_return(status: 404)
|
|
stub_request(:get, "http://www.amazon.com/500-url").to_return(status: 500)
|
|
stub_request(:get, "http://www.amazon.com/503-url").to_return(status: 503)
|
|
stub_request(:get, "http://www.amazon.com/timeout-url").to_raise(Timeout::Error)
|
|
stub_request(:get, "http://www.amazon.com/http-error").to_raise(Net::HTTPError.new("error", nil))
|
|
stub_request(:get, "http://www.amazon.com/error-connecting").to_raise(Errno::ECONNREFUSED)
|
|
end
|
|
|
|
describe '#human_status' do
|
|
it 'returns :success on HTTP status code 200' do
|
|
expect(described_class.new("http://www.amazon.com/200-url").human_status).to eq(:success)
|
|
end
|
|
|
|
it 'returns :success on HTTP status code 201' do
|
|
expect(described_class.new("http://www.amazon.com/201-url").human_status).to eq(:success)
|
|
end
|
|
|
|
it 'returns :client_error on HTTP status code 401' do
|
|
expect(described_class.new("http://www.amazon.com/401-url").human_status).to eq(:client_error)
|
|
end
|
|
|
|
it 'returns :client_error on HTTP status code 403' do
|
|
expect(described_class.new("http://www.amazon.com/403-url").human_status).to eq(:client_error)
|
|
end
|
|
|
|
it 'returns :client_error on HTTP status code 404' do
|
|
expect(described_class.new("http://www.amazon.com/404-url").human_status).to eq(:client_error)
|
|
end
|
|
|
|
it 'returns :server_error on HTTP status code 500' do
|
|
expect(described_class.new("http://www.amazon.com/500-url").human_status).to eq(:server_error)
|
|
end
|
|
|
|
it 'returns :server_error on HTTP status code 503' do
|
|
expect(described_class.new("http://www.amazon.com/503-url").human_status).to eq(:server_error)
|
|
end
|
|
|
|
it 'returns :connection_error if there is a connection refused error' do
|
|
expect(described_class.new("http://www.amazon.com/error-connecting").human_status).to eq(:connection_error)
|
|
end
|
|
|
|
it 'returns :connection_error if there is a timeout error' do
|
|
expect(described_class.new("http://www.amazon.com/timeout-url").human_status).to eq(:connection_error)
|
|
end
|
|
|
|
it 'returns :connection_error if there is a general HTTP error' do
|
|
expect(described_class.new("http://www.amazon.com/http-error").human_status).to eq(:connection_error)
|
|
end
|
|
end
|
|
|
|
describe '#ok?' do
|
|
it 'returns true for HTTP status codes 200-299' do
|
|
expect(described_class.new("http://www.amazon.com/200-url").ok?).to be true
|
|
end
|
|
|
|
it 'returns false for any status codes other than 200-299' do
|
|
expect(described_class.new("http://www.amazon.com/404-url").ok?).to be false
|
|
end
|
|
end
|
|
end
|