-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ef4c03
commit f6a4bee
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GiteaAPI::V1::Client do | ||
let(:client) { described_class.new(api_endpoint: 'https://gitea.opensuse.org', token: '12345') } | ||
let(:faraday) { instance_double(Faraday::Connection) } | ||
|
||
describe '#create_commit_status' do | ||
context 'when it is successful' do | ||
let(:url) { 'repos/krauselukas/hello_world/statuses/abc123cdf' } | ||
|
||
before do | ||
allow(Faraday::Connection).to receive(:new).and_return(faraday) | ||
allow(faraday).to receive(:post).and_return(Faraday::Response) | ||
allow(Faraday::Response).to receive(:status).and_return(200) | ||
allow(Faraday::Response).to receive(:body).and_return(true) | ||
|
||
client.create_commit_status(owner: 'krauselukas', repo: 'hello_world', sha: 'abc123cdf', state: 'succeeded') | ||
end | ||
|
||
it 'sends a post request to the correct api endpoint' do | ||
expect(faraday).to have_received(:post).with(url, { context: nil, description: nil, state: 'succeeded', target_url: nil }) | ||
end | ||
end | ||
|
||
context 'when something goes wrong' do | ||
before do | ||
allow(Faraday::Connection).to receive(:new).and_return(faraday) | ||
allow(faraday).to receive(:post).and_return(Faraday::Response) | ||
allow(Faraday::Response).to receive(:status).and_return(400) | ||
allow(Faraday::Response).to receive(:body).and_return({ 'message' => 'upppsss something went wrong' }) | ||
end | ||
|
||
it 'sends a post request and returns the correct exception class' do | ||
expect { client.create_commit_status(owner: 'krauselukas', repo: 'hello_world', sha: 'abc123cdf', state: 'succeeded') }.to raise_error(GiteaAPI::V1::Client::BadRequestError) | ||
end | ||
end | ||
end | ||
end |