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,15 +19,20 @@ class ExternalWikiService < Service ...@@ -19,15 +19,20 @@ class ExternalWikiService < Service
def fields 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 end
def execute(_data) def execute(_data)
@response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true) rescue nil response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true)
if @response != 200 response.body if response.code == 200
nil rescue
end nil
end end
def self.supported_events def self.supported_events
......
...@@ -26,4 +26,34 @@ describe ExternalWikiService do ...@@ -26,4 +26,34 @@ describe ExternalWikiService do
it { is_expected.not_to validate_presence_of(:external_wiki_url) } it { is_expected.not_to validate_presence_of(:external_wiki_url) }
end end
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 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