Commit 649a9ebf authored by Robert Speicher's avatar Robert Speicher

Merge branch '21153-external-wiki-integration-test-always-fails-when-saving' into 'master'

Resolve "External Wiki integration: Test always fails when saving"

Closes #21153

See merge request gitlab-org/gitlab!19568
parents a476939c d1c5f97a
......@@ -19,16 +19,21 @@ class ExternalWikiService < Service
def fields
[
{ type: 'text', name: 'external_wiki_url', placeholder: s_('ExternalWikiService|The URL of the external Wiki'), required: true }
{
type: 'text',
name: 'external_wiki_url',
placeholder: s_('ExternalWikiService|The URL of the external Wiki'),
required: true
}
]
end
def execute(_data)
@response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true) rescue nil
if @response != 200
response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true)
response.body if response.code == 200
rescue
nil
end
end
def self.supported_events
%w()
......
......@@ -26,4 +26,34 @@ describe ExternalWikiService do
it { is_expected.not_to validate_presence_of(:external_wiki_url) }
end
end
describe 'test' do
before do
subject.properties['external_wiki_url'] = url
end
let(:url) { 'http://foo' }
let(:data) { nil }
let(:result) { subject.test(data) }
context 'the URL is not reachable' do
before do
WebMock.stub_request(:get, url).to_return(status: 404, body: 'not a page')
end
it 'is not successful' do
expect(result[:success]).to be_falsey
end
end
context 'the URL is reachable' do
before do
WebMock.stub_request(:get, url).to_return(status: 200, body: 'foo')
end
it 'is successful' do
expect(result[:success]).to be_truthy
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment