Skip to content

Commit 8106e18

Browse files
committed
Tests
1 parent 711d316 commit 8106e18

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

spec/errbit_github_plugin/issue_tracker_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,24 @@
185185
end
186186

187187
describe "#close_issue" do
188+
subject { tracker.close_issue("url", user: user) }
189+
190+
let(:options) do
191+
{username: "foo", password: "bar", github_repo: "user/repository"}
192+
end
193+
194+
let(:fake_github_client) do
195+
double("Fake GitHub Client").tap do |github_client|
196+
expect(github_client).to receive(:close_issue).and_return(fake_issue)
197+
end
198+
end
199+
200+
let(:fake_issue) do
201+
double("Fake Issue").tap do |issue|
202+
expect(issue).to receive(:html_url).and_return("http://github.com/user/repos/issues/878").twice
203+
end
204+
end
205+
188206
context "signed in with token" do
189207
let(:user) do
190208
{
@@ -193,8 +211,39 @@
193211
}
194212
end
195213

214+
it "return issue url" do
215+
expect(Octokit::Client).to receive(:new).with(
216+
login: user["github_login"], access_token: user["github_oauth_token"]
217+
).and_return(fake_github_client)
196218

219+
expect(subject).to eq(fake_issue.html_url)
220+
end
221+
end
197222

223+
context "signed in with password" do
224+
let(:user) { {} }
225+
226+
it "return issue url" do
227+
expect(Octokit::Client).to receive(:new).with(
228+
login: options["username"], password: options["password"]
229+
).and_return(fake_github_client)
230+
231+
expect(subject).to eq(fake_issue.html_url)
232+
end
233+
end
234+
235+
context "when unauthentication error" do
236+
let(:user) do
237+
{"github_login" => "alice", "github_oauth_token" => "invalid_token"}
238+
end
239+
#
240+
it "raise AuthenticationError" do
241+
expect(Octokit::Client).to receive(:new).with(
242+
login: user["github_login"], access_token: user["github_oauth_token"]
243+
).and_raise(Octokit::Unauthorized)
244+
245+
expect { subject }.to raise_error(ErrbitGithubPlugin::AuthenticationError)
246+
end
198247
end
199248
end
200249
end

0 commit comments

Comments
 (0)