11require File . dirname ( __FILE__ ) + '/../test_helper.rb'
2+ require "base64"
23
34class Drip ::ClientTest < Drip ::TestCase
45 context "initialization" do
@@ -10,6 +11,14 @@ class Drip::ClientTest < Drip::TestCase
1011 assert_equal "aaaa" , client . api_key
1112 end
1213
14+ should "accept access token" do
15+ client = Drip ::Client . new do |config |
16+ config . access_token = "aaaa"
17+ end
18+
19+ assert_equal "aaaa" , client . access_token
20+ end
21+
1322 should "accept default account id" do
1423 client = Drip ::Client . new do |config |
1524 config . account_id = "1234567"
@@ -30,4 +39,32 @@ class Drip::ClientTest < Drip::TestCase
3039 assert_equal ( { @key => [ @data ] } , @client . generate_resource ( @key , @data ) )
3140 end
3241 end
42+
43+ context "given a personal api key" do
44+ setup do
45+ @key = "aaaa"
46+ @client = Drip ::Client . new do |config |
47+ config . api_key = @key
48+ end
49+ end
50+
51+ should "use Basic authentication" do
52+ header = "Basic #{ Base64 . encode64 ( @key + ":" ) } " . strip
53+ assert_equal header , @client . connection . headers [ "Authorization" ]
54+ end
55+ end
56+
57+ context "given a OAuth access token" do
58+ setup do
59+ @key = "aaaa"
60+ @client = Drip ::Client . new do |config |
61+ config . access_token = @key
62+ end
63+ end
64+
65+ should "use Bearer token authentication" do
66+ header = "Bearer #{ @key } "
67+ assert_equal header , @client . connection . headers [ "Authorization" ]
68+ end
69+ end
3370end
0 commit comments