|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe Github::Authorizations::App, '#check' do |
| 6 | + let(:basic_auth) { 'login:password' } |
| 7 | + let(:host) { "https://#{basic_auth}@api.github.com" } |
| 8 | + let(:request_path) { "/applications/#{client_id}/tokens/#{access_token}" } |
| 9 | + let(:client_id) { 1 } |
| 10 | + let(:access_token) { 'abc123' } |
| 11 | + |
| 12 | + before { |
| 13 | + subject.basic_auth = basic_auth |
| 14 | + |
| 15 | + stub_get(request_path, host).to_return(body: body, status: status, |
| 16 | + headers: {content_type: 'application/json; charset=utf-8'}) |
| 17 | + } |
| 18 | + |
| 19 | + after { reset_authentication_for(subject) } |
| 20 | + |
| 21 | + context 'when app makes a request' do |
| 22 | + let(:body) { "" } |
| 23 | + let(:status) { 200 } |
| 24 | + |
| 25 | + it "checks resource successfully" do |
| 26 | + subject.check client_id, access_token |
| 27 | + a_get(request_path, host).should have_been_made |
| 28 | + end |
| 29 | + |
| 30 | + it "fails without client_id" do |
| 31 | + expect { subject.check }.to raise_error(ArgumentError) |
| 32 | + end |
| 33 | + |
| 34 | + it "fails without access_token" do |
| 35 | + expect {subject.check(client_id)}.to raise_error(ArgumentError) |
| 36 | + end |
| 37 | + |
| 38 | + end |
| 39 | + |
| 40 | + context 'when app checks a token that is valid' do |
| 41 | + let(:body) { fixture('auths/check.json') } |
| 42 | + let(:status) { 200 } |
| 43 | + |
| 44 | + |
| 45 | + it "returns the resource" do |
| 46 | + authorization = subject.check client_id, access_token |
| 47 | + authorization.should be_a Github::ResponseWrapper |
| 48 | + end |
| 49 | + |
| 50 | + it "gets the authorization information" do |
| 51 | + authorization = subject.check client_id, access_token |
| 52 | + authorization.token.should == 'abc123' |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + context 'when app checks a token that is not valid' do |
| 57 | + let(:body) { '' } |
| 58 | + let(:status) { 404 } |
| 59 | + |
| 60 | + it "does not raise error for expected 404" do |
| 61 | + expect { subject.check client_id, access_token }.to_not raise_error |
| 62 | + end |
| 63 | + |
| 64 | + it "returns nil" do |
| 65 | + authorization = subject.check client_id, access_token |
| 66 | + authorization.should be_nil |
| 67 | + end |
| 68 | + |
| 69 | + end |
| 70 | +end # check |
0 commit comments