|
185 | 185 | end
|
186 | 186 |
|
187 | 187 | 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 | + |
188 | 206 | context "signed in with token" do
|
189 | 207 | let(:user) do
|
190 | 208 | {
|
|
193 | 211 | }
|
194 | 212 | end
|
195 | 213 |
|
| 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) |
196 | 218 |
|
| 219 | + expect(subject).to eq(fake_issue.html_url) |
| 220 | + end |
| 221 | + end |
197 | 222 |
|
| 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 |
198 | 247 | end
|
199 | 248 | end
|
200 | 249 | end
|
0 commit comments