summaryrefslogtreecommitdiff
path: root/spec/models/project_services/teamcity_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/project_services/teamcity_service_spec.rb')
-rw-r--r--spec/models/project_services/teamcity_service_spec.rb151
1 files changed, 72 insertions, 79 deletions
diff --git a/spec/models/project_services/teamcity_service_spec.rb b/spec/models/project_services/teamcity_service_spec.rb
index 7bfb6160f57..fa741fb7ff6 100644
--- a/spec/models/project_services/teamcity_service_spec.rb
+++ b/spec/models/project_services/teamcity_service_spec.rb
@@ -91,126 +91,119 @@ describe TeamcityService, models: true do
end
end
- module TeamcityServiceSpec
- Response = Struct.new(:code, :data) do
- def [](key)
- data[key]
- end
- end
- end
-
- describe '#build_info' do
- let(:teamcity_url) { 'http://gitlab.com' }
- let(:response) { TeamcityServiceSpec::Response.new(200, {}) }
- subject do
- TeamcityService.create(
- project: create(:project),
- properties: {
- teamcity_url: teamcity_url,
- username: 'mic',
- password: 'password',
- build_type: 'foo'
- })
- end
- before { allow(HTTParty).to receive(:get).and_return(response) }
-
- context 'when teamcity_url has no trailing slash' do
- it { expect(subject.build_info('123')).to eq(response) }
- end
+ describe '#build_page' do
+ let(:teamcity_full_url) { 'http://mic:password@gitlab.com/httpAuth/app/rest/builds/branch:unspecified:any,number:123' }
- context 'when teamcity_url has a trailing slash' do
- let(:teamcity_url) { 'http://gitlab.com/' }
+ context 'when response code is not 200' do
+ before do
+ WebMock.stub_request(:get, teamcity_full_url).to_return(status: 500)
+ end
+ subject do
+ TeamcityService.create(
+ project: build_stubbed(:empty_project),
+ properties: {
+ teamcity_url: 'http://gitlab.com/',
+ username: 'mic',
+ password: 'password',
+ build_type: 'foo'
+ }
+ )
+ end
- it { expect(subject.build_info('123')).to eq(response) }
- end
- end
+ it 'returns a specific URL' do
- describe '#build_page' do
- let(:teamcity_url) { 'http://gitlab.com' }
- let(:response_code) { 200 }
- let(:response) do
- TeamcityServiceSpec::Response.new(response_code, { 'build' => { 'id' => '666' } })
- end
- subject do
- TeamcityService.create(
- project: create(:project),
- properties: {
- teamcity_url: teamcity_url,
- username: 'mic',
- password: 'password',
- build_type: 'foo'
- })
+ expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildTypeId=foo')
+ end
end
- before { allow(HTTParty).to receive(:get).and_return(response) }
- context 'when teamcity_url has no trailing slash' do
- it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') }
- end
+ context 'when response has result' do
+ before do
+ WebMock.stub_request(:get, teamcity_full_url).to_return(
+ status: 200,
+ headers: { 'Content-Type': 'application/json' },
+ body: %Q({"build":{"id":"666"}})
+ )
+ end
+ subject do
+ TeamcityService.create(
+ project: build_stubbed(:empty_project),
+ properties: {
+ teamcity_url: teamcity_url,
+ username: 'mic',
+ password: 'password',
+ build_type: 'foo'
+ }
+ )
+ end
- context 'when teamcity_url has a trailing slash' do
- let(:teamcity_url) { 'http://gitlab.com/' }
+ context 'when teamcity_url has no trailing slash' do
+ let(:teamcity_url) { 'http://gitlab.com' }
- it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') }
- end
+ it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') }
+ end
- context 'when response code is not 200' do
- let(:response_code) { 500 }
+ context 'when teamcity_url has a trailing slash' do
+ let(:teamcity_url) { 'http://gitlab.com/' }
- it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildTypeId=foo') }
+ it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') }
+ end
end
end
describe '#commit_status' do
- let(:teamcity_url) { 'http://gitlab.com' }
- let(:response_code) { 200 }
- let(:build_status) { 'YAY SUCCESS!' }
- let(:response) do
- TeamcityServiceSpec::Response.new(response_code, {
- 'build' => {
- 'status' => build_status,
- 'id' => '666'
- }
- })
- end
+ let(:teamcity_full_url) { 'http://mic:password@gitlab.com/httpAuth/app/rest/builds/branch:unspecified:any,number:123' }
subject do
TeamcityService.create(
- project: create(:project),
+ project: build_stubbed(:empty_project),
properties: {
- teamcity_url: teamcity_url,
+ teamcity_url: 'http://gitlab.com',
username: 'mic',
password: 'password',
build_type: 'foo'
- })
+ }
+ )
end
- before { allow(HTTParty).to receive(:get).and_return(response) }
context 'when response code is not 200' do
- let(:response_code) { 500 }
+ before do
+ WebMock.stub_request(:get, teamcity_full_url).to_return(status: 500)
+ end
it { expect(subject.commit_status('123', 'unused')).to eq(:error) }
end
context 'when response code is 404' do
- let(:response_code) { 404 }
+ before do
+ WebMock.stub_request(:get, teamcity_full_url).to_return(status: 404)
+ end
- it { expect(subject.commit_status('123', 'unused')).to eq(:pending) }
+ it { expect(subject.commit_status('123', 'unused')).to eq('pending') }
end
- context 'when response code is 200' do
+ context 'when response has results' do
+ let(:build_status) { 'YAY SUCCESS!' }
+ before do
+ WebMock.stub_request(:get, teamcity_full_url).to_return(
+ status: 200,
+ headers: { 'Content-Type': 'application/json' },
+ body: %Q({"build":{"status":"#{build_status}","id":"666"}})
+ )
+ end
+
context 'when build status contains SUCCESS' do
- it { expect(subject.commit_status('123', 'unused')).to eq(:success) }
+ it { expect(subject.commit_status('123', 'unused')).to eq('success') }
end
context 'when build status contains FAILURE' do
let(:build_status) { 'NO FAILURE!' }
- it { expect(subject.commit_status('123', 'unused')).to eq(:failed) }
+ it { expect(subject.commit_status('123', 'unused')).to eq('failed') }
end
context 'when build status contains Pending' do
let(:build_status) { 'NO Pending!' }
- it { expect(subject.commit_status('123', 'unused')).to eq(:pending) }
+ it { expect(subject.commit_status('123', 'unused')).to eq('pending') }
end
context 'when build status contains anything else' do