klarna 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/.gitignore +9 -0
  2. data/.travis.yml +13 -0
  3. data/Gemfile +14 -0
  4. data/Guardfile +16 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.textile +139 -0
  7. data/Rakefile +22 -0
  8. data/TODO +30 -0
  9. data/examples/Gemfile +8 -0
  10. data/examples/config/initializer.rb +15 -0
  11. data/examples/console.rb +71 -0
  12. data/examples/public/images/klarna.png +0 -0
  13. data/examples/public/images/ruby.png +0 -0
  14. data/examples/views/_address.haml +22 -0
  15. data/examples/views/_articles.haml +21 -0
  16. data/examples/views/checkout_page_example.haml +2 -0
  17. data/examples/views/essential/add_transaction/_form.haml +32 -0
  18. data/examples/views/essential/add_transaction/result.haml +7 -0
  19. data/examples/views/essential/calculate_monthly_cost/_form.haml +16 -0
  20. data/examples/views/essential/calculate_monthly_cost/result.haml +7 -0
  21. data/examples/views/essential/get_addresses/_form.haml +9 -0
  22. data/examples/views/essential/get_addresses/result.haml +8 -0
  23. data/examples/views/index.haml +296 -0
  24. data/examples/views/layout.haml +48 -0
  25. data/examples/views/payment_terms_example.haml +102 -0
  26. data/examples/views/product_page_example.haml +2 -0
  27. data/examples/views/reservation/activate_reservation/_form.haml +54 -0
  28. data/examples/views/reservation/activate_reservation/result.haml +7 -0
  29. data/examples/views/reservation/cancel_reservation/_form.haml +8 -0
  30. data/examples/views/reservation/cancel_reservation/result.haml +7 -0
  31. data/examples/views/reservation/change_reservation/_form.haml +10 -0
  32. data/examples/views/reservation/change_reservation/result.haml +7 -0
  33. data/examples/views/reservation/reserve_amount/_form.haml +58 -0
  34. data/examples/views/reservation/reserve_amount/result.haml +7 -0
  35. data/examples/views/reservation/reserve_ocr_numbers/_form.haml +8 -0
  36. data/examples/views/reservation/reserve_ocr_numbers/result.haml +7 -0
  37. data/examples/views/reservation/split_reservation/_form.haml +14 -0
  38. data/examples/views/reservation/split_reservation/result.haml +7 -0
  39. data/examples/views/special/get_pclasses/_form.haml +8 -0
  40. data/examples/views/special/get_pclasses/result.haml +7 -0
  41. data/examples/views/special/invoice_address/_form.haml +8 -0
  42. data/examples/views/special/invoice_address/result.haml +7 -0
  43. data/examples/views/special/invoice_amount/_form.haml +8 -0
  44. data/examples/views/special/invoice_amount/result.haml +7 -0
  45. data/examples/views/special/is_invoice_paid/_form.haml +8 -0
  46. data/examples/views/special/is_invoice_paid/result.haml +7 -0
  47. data/examples/views/special/update_charge_amount/_form.haml +15 -0
  48. data/examples/views/special/update_charge_amount/result.haml +7 -0
  49. data/examples/views/special/update_goods_quantity/_form.haml +17 -0
  50. data/examples/views/special/update_goods_quantity/result.haml +7 -0
  51. data/examples/views/special/update_order_number/_form.haml +10 -0
  52. data/examples/views/special/update_order_number/result.haml +7 -0
  53. data/examples/views/useful/activate_invoice/_form.haml +9 -0
  54. data/examples/views/useful/activate_invoice/result.haml +7 -0
  55. data/examples/views/useful/credit_invoice/_form.haml +11 -0
  56. data/examples/views/useful/credit_invoice/result.haml +7 -0
  57. data/examples/views/useful/delete_invoice/_form.haml +9 -0
  58. data/examples/views/useful/delete_invoice/result.haml +7 -0
  59. data/examples/views/useful/email_invoice/_form.haml +9 -0
  60. data/examples/views/useful/email_invoice/result.haml +7 -0
  61. data/examples/views/useful/has_account/_form.haml +9 -0
  62. data/examples/views/useful/has_account/result.haml +7 -0
  63. data/examples/views/useful/return_amount/_form.haml +15 -0
  64. data/examples/views/useful/return_amount/result.haml +7 -0
  65. data/examples/views/useful/send_invoice/_form.haml +9 -0
  66. data/examples/views/useful/send_invoice/result.haml +7 -0
  67. data/examples/web.rb +349 -0
  68. data/klarna.gemspec +34 -0
  69. data/lib/klarna.rb +175 -0
  70. data/lib/klarna/api.rb +170 -0
  71. data/lib/klarna/api/client.rb +128 -0
  72. data/lib/klarna/api/constants.rb +638 -0
  73. data/lib/klarna/api/errors.rb +154 -0
  74. data/lib/klarna/api/methods.rb +16 -0
  75. data/lib/klarna/api/methods/cost_calculations.rb +134 -0
  76. data/lib/klarna/api/methods/invoicing.rb +304 -0
  77. data/lib/klarna/api/methods/reservation.rb +149 -0
  78. data/lib/klarna/api/methods/standard.rb +123 -0
  79. data/lib/klarna/version.rb +5 -0
  80. data/test/fixtures/api/companies.yml +97 -0
  81. data/test/fixtures/api/pclasses.yml +37 -0
  82. data/test/fixtures/api/persons.yml +144 -0
  83. data/test/fixtures/api/stores.yml +6 -0
  84. data/test/fixtures/klarna.yml +10 -0
  85. data/test/klarna/api/client_test.rb +272 -0
  86. data/test/klarna/api/errors_test.rb +46 -0
  87. data/test/klarna/api/methods/cost_calculations_test.rb +78 -0
  88. data/test/klarna/api/methods/invoicing_test.rb +409 -0
  89. data/test/klarna/api/methods/reservation_test.rb +66 -0
  90. data/test/klarna/api/methods/standard_test.rb +244 -0
  91. data/test/klarna/api_test.rb +137 -0
  92. data/test/klarna_test.rb +204 -0
  93. data/test/support/assertions_helper.rb +40 -0
  94. data/test/test_helper.rb +55 -0
  95. metadata +312 -0
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe Klarna::API::Methods::Reservation do
5
+
6
+ # TODO: Mock responses using VCR.
7
+
8
+ before do
9
+ valid_credentials!
10
+ @client = Klarna::API::Client.new
11
+
12
+ @protocol_version = ::Klarna::API::PROTOCOL_VERSION.to_s
13
+ @user_agent = ::XMLRPC::Client::USER_AGENT.to_s
14
+
15
+ expose_protected_methods_in @client.class
16
+ end
17
+
18
+ # Spec: http://integration.klarna.com/en/api/advanced-integration/functions/reserveamount
19
+ describe '#reserve_amount' do
20
+ it 'should be defined' do
21
+ assert_respond_to @client, :reserve_amount
22
+ end
23
+ end
24
+
25
+ # Spec: http://integration.klarna.com/en/api/advanced-integration/functions/activatereservation
26
+ describe '#activate_reservation' do
27
+ it 'should be defined' do
28
+ assert_respond_to @client, :activate_reservation
29
+ end
30
+ end
31
+
32
+ # Spec: http://integration.klarna.com/en/api/advanced-integration/functions/cancelreservation
33
+ describe '#cancel_reservation' do
34
+ it 'should be defined' do
35
+ assert_respond_to @client, :cancel_reservation
36
+ end
37
+ end
38
+
39
+ describe '#split_reservation' do
40
+ it 'should be defined' do
41
+ assert_respond_to @client, :split_reservation
42
+ end
43
+ end
44
+
45
+ # Spec: http://integration.klarna.com/en/api/advanced-integration/functions/changereservation
46
+ describe '#change_reservation' do
47
+ it 'should be defined' do
48
+ assert_respond_to @client, :change_reservation
49
+ end
50
+ end
51
+
52
+ # Spec: http://integration.klarna.com/en/api/advanced-integration/functions/reserveocrnums
53
+ describe '#reserve_ocr_numbers' do
54
+ it 'should be defined' do
55
+ assert_respond_to @client, :reserve_ocr_numbers
56
+ end
57
+ end
58
+
59
+ # http://integration.klarna.com/en/api/advanced-integration/functions/mkaddress
60
+ describe '#make_reservation_address' do
61
+ it 'should be defined' do
62
+ assert_respond_to @client, :make_reservation_address
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,244 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe Klarna::API::Methods::Standard do
5
+
6
+ # TODO: Mock responses using VCR.
7
+
8
+ before do
9
+ valid_credentials!
10
+ @klarna = Klarna::API::Client.new
11
+ @klarna.client_ip = '127.0.0.1'
12
+
13
+ @protocol_version = ::Klarna::API::PROTOCOL_VERSION.to_s
14
+ @user_agent = ::XMLRPC::Client::USER_AGENT.to_s
15
+
16
+ @pno_format_sweden = ::Klarna::API::COUNTRIES[:SE]
17
+ @country_sweden = ::Klarna::API::COUNTRIES[:SE]
18
+
19
+ expose_protected_methods_in @klarna.class
20
+ end
21
+
22
+ # Spec:
23
+ # http://integration.klarna.com/en/api/standard-integration/functions/getaddresses
24
+ describe '#get_addresses' do
25
+ it 'should be defined' do
26
+ assert_respond_to @klarna, :get_addresses
27
+ end
28
+
29
+ # it 'should require: pno, country'
30
+
31
+ it 'should handle pno-format as integer (pno-format ID)' do
32
+ assert @klarna.get_addresses("4304158399", 2) # a.k.a. ::Klarna::API::PNO_FORMATS[:SE]
33
+ end
34
+
35
+ it 'should handle pno-format as integer (pno-format ID)' do
36
+ assert @klarna.get_addresses("4304158399", :SE)
37
+ end
38
+
39
+ # it 'should pre-validate the specified pno, and raise validation error if it s invalid without any service call'
40
+
41
+ describe "SE" do
42
+ it 'should return address for a valid pno' do
43
+ result = @klarna.get_addresses("4304158399", :SE)
44
+ assert_equal [@protocol_version, @user_agent, "4304158399", @klarna.store_id, @klarna.digest("4304158399"), 2, 5, '127.0.0.1'], @klarna.last_request_params
45
+ assert_equal [["Karl", "Lidin", "Junibacksg 42", "23634", "Hollviken", 209]], result
46
+
47
+ result = @klarna.get_addresses("5311096845", :SE)
48
+ assert_equal [@protocol_version, @user_agent, "5311096845", @klarna.store_id, @klarna.digest("5311096845"), 2, 5, '127.0.0.1'], @klarna.last_request_params
49
+ assert_equal [["Maud", "Johansson", "Köpmansg 7", "12149", "Johanneshov", 209]], result
50
+ end
51
+
52
+ it 'should ignore format symbols in pno' do
53
+ result = @klarna.get_addresses("430415-8399", :SE)
54
+ assert_equal [@protocol_version, @user_agent, "4304158399", @klarna.store_id, @klarna.digest("4304158399"), 2, 5, '127.0.0.1'], @klarna.last_request_params
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#get_address' do
60
+ it 'should be defined' do
61
+ assert_respond_to @klarna, :get_address
62
+ end
63
+
64
+ it 'should only return first returned address for a valid SSN' do
65
+ result = @klarna.get_address("4304158399", :SE)
66
+ assert_equal ["Karl", "Lidin", "Junibacksg 42", "23634", "Hollviken", 209], result
67
+ end
68
+ end
69
+
70
+ # Spec:
71
+ # http://integration.klarna.com/en/api/standard-integration/functions/mkaddr
72
+ describe '#make_address' do
73
+ it 'should be defined' do
74
+ assert_respond_to @klarna, :make_address
75
+ end
76
+
77
+ describe "SE" do
78
+ it 'should generate an valid address array' do
79
+ assert_equal ({
80
+ 'careof' => "c/o Lidin",
81
+ 'street' => "Junibackg. 42",
82
+ 'postno' => "23634",
83
+ 'city' => "Hollviken",
84
+ 'country' => 209,
85
+ 'telno' => "0765260000",
86
+ 'cellno' => "0765260000",
87
+ 'email' => "karl.lidin@klarna.com"
88
+ }),
89
+ @klarna.make_address("c/o Lidin", "Junibackg. 42", "23634", "Hollviken", :SE, "076 526 00 00", "076 526 00 00", "karl.lidin@klarna.com")
90
+ end
91
+
92
+ # TODO
93
+ describe 'argument constraints: raise argument error if not true (no API-call)' do
94
+ describe 'care_of' do
95
+ # it 'should be a string or nil'
96
+ end
97
+
98
+ describe 'street' do
99
+ # it 'should be a string'
100
+ end
101
+
102
+ describe 'postal code' do
103
+ # it 'should be a string/integer'
104
+ end
105
+
106
+ describe 'city' do
107
+ # it 'should be a string'
108
+ end
109
+
110
+ describe 'country' do
111
+ # it 'should be a string/symbol/integer (-> valid Klarna country ID)'
112
+ end
113
+
114
+ describe 'phone' do
115
+ # it 'should be a string/integer'
116
+
117
+ # it 'should ignore whitespace'
118
+ end
119
+
120
+ describe 'cell_phone' do
121
+ # it 'should be a string/integer'
122
+
123
+ # it 'should ignore whitespace'
124
+ end
125
+
126
+ describe 'email' do
127
+ # it 'should be a valid email (string)'
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ # Spec:
134
+ # http://integration.klarna.com/en/api/standard-integration/functions/mkgoodsflags
135
+ describe '#make_goods' do
136
+ it 'should be defined' do
137
+ assert_respond_to @klarna, :make_goods
138
+ end
139
+
140
+ # it 'should require: quantity, artno vs title, price, vat'
141
+
142
+ # it 'should pre-validate the specified address values, and raise validation error if it s invalid without any service call'
143
+
144
+ describe 'argument constraints: raise argument error if not true (no API-call)' do
145
+ describe 'quantity' do
146
+ # it 'should be a integer/string'
147
+
148
+ # it 'should be >= 1'
149
+ end
150
+
151
+ describe 'artno' do
152
+ # it 'should be a integer/string if no title is specified'
153
+ end
154
+
155
+ describe 'title' do
156
+ # it 'should be a integer/string if no artno is specified'
157
+ end
158
+
159
+ describe 'price' do
160
+ # it 'should be a integer/string/decimal if no artno is specified'
161
+
162
+ # it 'should convert to cents if decimal (assumption)'
163
+ end
164
+
165
+ describe 'vat' do
166
+ # it 'should be a integer/string/decimal if no artno is specified'
167
+ end
168
+ end
169
+
170
+ it 'should generate an valid address structure: quantity, artno, title, price, vat' do
171
+ assert_equal ({
172
+ 'goods' => {
173
+ 'artno' => "ABC123",
174
+ 'title' => "T-shirt",
175
+ 'price' => 2500,
176
+ 'vat' => 25.00,
177
+ 'discount' => 0.00,
178
+ 'flags' => 0
179
+ },
180
+ 'qty' => 5
181
+ }),
182
+ @klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25)
183
+ end
184
+
185
+ it 'should generate an valid address structure: quantity, artno, title, price, vat, discount' do
186
+ assert_equal ({
187
+ 'goods' => {
188
+ 'artno' => "ABC123",
189
+ 'title' => "T-shirt",
190
+ 'price' => 2500,
191
+ 'vat' => 25.00,
192
+ 'discount' => 10.00,
193
+ 'flags' => 0
194
+ },
195
+ 'qty' => 5
196
+ }),
197
+ @klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25, 10)
198
+ end
199
+
200
+ it 'should generate an valid address structure: quantity, artno, title, price, vat, discount, flags' do
201
+ assert_equal ({
202
+ 'goods' => {
203
+ 'artno' => "ABC123",
204
+ 'title' => "T-shirt",
205
+ 'price' => 2500,
206
+ 'vat' => 25.00,
207
+ 'discount' => 10.00,
208
+ 'flags' => 32
209
+ },
210
+ 'qty' => 5
211
+ }),
212
+ @klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25, 10, ::Klarna::API::GOODS[:INC_VAT])
213
+ end
214
+
215
+ it 'should be possible to set flags via options' do
216
+ assert_equal ({
217
+ 'goods' => {
218
+ 'artno' => "ABC123",
219
+ 'title' => "T-shirt",
220
+ 'price' => 2500,
221
+ 'vat' => 25.00,
222
+ 'discount' => 0.00,
223
+ 'flags' => 48
224
+ },
225
+ 'qty' => 5
226
+ }),
227
+ @klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25, 0, :inc_vat => true, :is_handling => true)
228
+ end
229
+ end
230
+
231
+ # Spec:
232
+ # http://integration.klarna.com/en/api/advanced-integration/functions/hasaccount
233
+ describe '#has_account?' do
234
+ it 'should be defined' do
235
+ assert_respond_to @klarna, :has_account?
236
+ end
237
+
238
+ # FIXME: Throws error "Unknown call (-99)". :S
239
+ it 'should be true' # do
240
+ # assert_equal true, @klarna.has_account?("4304158399", :SE)
241
+ # end
242
+ end
243
+
244
+ end
@@ -0,0 +1,137 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe ::Klarna::API do
5
+
6
+ before do
7
+ ::Klarna.setup do |c|
8
+ c.store_id = VALID_STORE_ID
9
+ c.store_secret = VALID_STORE_SECRET
10
+ end
11
+ end
12
+
13
+ describe "Helpers" do
14
+
15
+ describe '.client' do
16
+ it 'should be defined' do
17
+ assert_respond_to ::Klarna::API, :client
18
+ end
19
+
20
+ it 'should create a new ::Klarna RPC-API client with default settings' do
21
+ client = ::Klarna::API.client
22
+ assert_instance_of ::Klarna::API::Client, client
23
+ end
24
+
25
+ it 'should reuse existing ::Klarna RPC-API client instance if exists' do
26
+ assert_equal ::Klarna::API.client, ::Klarna::API.client
27
+ end
28
+
29
+ it 'should be possible to force-re-initialize the client even though it is already initialized' do
30
+ client_1 = ::Klarna::API.client(true)
31
+ client_2 = ::Klarna::API.client(true)
32
+ refute_equal client_1, client_2
33
+ end
34
+ end
35
+
36
+ describe '.validated_kind' do
37
+ it 'should be defined' do
38
+ assert_respond_to ::Klarna::API, :validated_kind
39
+ end
40
+
41
+ it 'should only allow kinds: :country, :currency, :language, :pno_format, :address_format' do
42
+ assert_equal :COUNTRIES, ::Klarna::API.validated_kind(:country)
43
+ assert_equal :COUNTRIES, ::Klarna::API.validated_kind('country')
44
+
45
+ assert_equal :CURRENCIES, ::Klarna::API.validated_kind(:currency)
46
+ assert_equal :CURRENCIES, ::Klarna::API.validated_kind('currency')
47
+
48
+ assert_equal :LANGUAGES, ::Klarna::API.validated_kind(:language)
49
+ assert_equal :LANGUAGES, ::Klarna::API.validated_kind('language')
50
+
51
+ assert_equal :PNO_FORMATS, ::Klarna::API.validated_kind(:pno_format)
52
+ assert_equal :PNO_FORMATS, ::Klarna::API.validated_kind('pno_format')
53
+
54
+ assert_equal :ADDRESS_FORMATS, ::Klarna::API.validated_kind(:address_format)
55
+ assert_equal :ADDRESS_FORMATS, ::Klarna::API.validated_kind('address_format')
56
+
57
+ assert_raises ::Klarna::API::KlarnaArgumentError do
58
+ ::Klarna::API.validated_kind(:hello)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '.key_for' do
64
+ it 'should be defined' do
65
+ assert_respond_to ::Klarna::API, :key_for
66
+ end
67
+
68
+ it 'should return valid format KEY for a specified kind-key' do
69
+ assert_equal :SE, ::Klarna::API.key_for(:pno_format, 'SE')
70
+ assert_equal :SE, ::Klarna::API.key_for(:pno_format, :SE)
71
+ end
72
+
73
+ it 'should return valid format KEY for a specified kind-value' do
74
+ assert_equal :SE, ::Klarna::API.key_for(:pno_format, '2')
75
+ assert_equal :SE, ::Klarna::API.key_for(:pno_format, 2)
76
+ end
77
+ end
78
+
79
+ describe '.id_for' do
80
+ it 'should be defined' do
81
+ assert_respond_to ::Klarna::API, :id_for
82
+ end
83
+
84
+ it 'should return valid format ID for a specified kind-key' do
85
+ assert_equal 2, ::Klarna::API.id_for(:pno_format, 'SE')
86
+ assert_equal 2, ::Klarna::API.id_for(:pno_format, :SE)
87
+ end
88
+
89
+ it 'should return valid format ID for a specified kind-value' do
90
+ assert_equal 2, ::Klarna::API.id_for(:pno_format, '2')
91
+ assert_equal 2, ::Klarna::API.id_for(:pno_format, 2)
92
+ end
93
+ end
94
+
95
+ describe '.validate_arg' do
96
+ it 'should be defined' do
97
+ assert_respond_to ::Klarna::API, :validate_arg
98
+ end
99
+
100
+ # it 'should...'
101
+ end
102
+
103
+ describe '.digest' do
104
+ it 'should be defined' do
105
+ assert_respond_to ::Klarna::API, :digest
106
+ end
107
+
108
+ it 'should calculate a valid digest secret for one value' do
109
+ # TODO
110
+ # skip
111
+ end
112
+
113
+ it 'should calculate a valid digest secret for an array of values' do
114
+ # TODO
115
+ # skip
116
+ end
117
+
118
+ it 'should raise error if specified value is nor a string or an array' do
119
+ # TODO
120
+ # skip
121
+ end
122
+ end
123
+
124
+ describe '.encode' do
125
+ it 'should be defined' do
126
+ assert_respond_to ::Klarna::API, :encode
127
+ end
128
+
129
+ it 'should encode a specified string from "UTF-8" to "iso-8859-1" properly' do
130
+ # TODO
131
+ # skip
132
+ end
133
+ end
134
+
135
+ end
136
+
137
+ end
@@ -0,0 +1,204 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe Klarna do
5
+
6
+ before do
7
+ Klarna.reset!
8
+ Klarna.store_config_file = File.join(File.dirname(__FILE__), 'fixtures', 'klarna.yml')
9
+ end
10
+
11
+ describe "Constants" do
12
+
13
+ describe 'VALID_COUNTRIES' do
14
+ it 'should be defined' do
15
+ assert defined?(Klarna::VALID_COUNTRIES)
16
+ end
17
+
18
+ # TODO: Add additional countries
19
+ it 'should have values: SE, NO, FI, DK' do
20
+ assert_equal [:SE, :NO, :FI, :DK], Klarna::VALID_COUNTRIES
21
+ end
22
+ end
23
+
24
+ describe 'DEFAULT_COUNTRY' do
25
+ it 'should be defined' do
26
+ assert defined?(Klarna::DEFAULT_COUNTRY)
27
+ end
28
+
29
+ it 'should have value: SE' do
30
+ assert_equal :SE, Klarna::DEFAULT_COUNTRY
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ describe "Configuration" do
37
+
38
+ describe '.mode' do
39
+ it 'should be defined' do
40
+ assert_respond_to Klarna, :mode
41
+ end
42
+
43
+ it 'should have default setting: :test' do
44
+ assert_equal :test, Klarna.mode
45
+ end
46
+
47
+ it 'should be configurable' do
48
+ swap Klarna, :mode => :production do
49
+ assert_equal :production, Klarna.mode
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '.country' do
55
+ it 'should be defined' do
56
+ assert_respond_to Klarna, :country
57
+ end
58
+
59
+ it 'should have default setting: SE' do
60
+ assert_equal :SE, Klarna.country
61
+ end
62
+
63
+ it 'should be configurable' do
64
+ swap Klarna, :country => :NO do
65
+ assert_equal :NO, Klarna.country
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '.store_id' do
71
+ it 'should be defined' do
72
+ assert_respond_to Klarna, :store_id
73
+ end
74
+
75
+ it 'should have default setting: nil' do
76
+ assert_equal nil, Klarna.store_id
77
+ end
78
+
79
+ it 'should be configurable' do
80
+ swap Klarna, :store_id => '123' do
81
+ assert_equal 123, Klarna.store_id
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '.store_secret' do
87
+ it 'should be defined' do
88
+ assert_respond_to Klarna, :store_secret
89
+ end
90
+
91
+ it 'should have default setting: nil' do
92
+ assert_equal nil, Klarna.store_secret
93
+ end
94
+
95
+ it 'should be configurable' do
96
+ swap Klarna, :store_secret => 'ABC123' do
97
+ assert_equal 'ABC123', Klarna.store_secret
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '.store_pclasses' do
103
+ it 'should be defined' do
104
+ assert_respond_to Klarna, :store_pclasses
105
+ end
106
+
107
+ it 'should have default setting: SE' do
108
+ assert_equal nil, Klarna.store_pclasses
109
+ end
110
+
111
+ # TODO:
112
+ # it 'should be configurable' do
113
+ # end
114
+ end
115
+
116
+ describe '.store_config_file' do
117
+ it 'should be defined' do
118
+ assert_respond_to Klarna, :mode
119
+ end
120
+
121
+ it 'should have default setting: nil' do
122
+ Klarna.reset!
123
+ assert_equal File.join(ENV['HOME'], '.klarna.yml'), Klarna.store_config_file
124
+ end
125
+
126
+ it 'should be configurable' do
127
+ swap Klarna, :store_config_file => '/path/to/a/file' do
128
+ assert_equal '/path/to/a/file', Klarna.store_config_file
129
+ end
130
+ end
131
+ end
132
+
133
+ describe '.logger' do
134
+ it 'should be defined' do
135
+ assert_respond_to Klarna, :logger
136
+ end
137
+
138
+ it 'should have default logger' do
139
+ assert_instance_of Logger, Klarna.logger
140
+ end
141
+
142
+ it 'should be configurable' do
143
+ custom_logger = ::Logger.new(::STDOUT)
144
+ swap Klarna, :logger => custom_logger do
145
+ assert_equal custom_logger, Klarna.logger
146
+ end
147
+ end
148
+ end
149
+
150
+ describe '.http_logging' do
151
+ it 'should be defined' do
152
+ assert_respond_to Klarna, :http_logging
153
+ end
154
+
155
+ it 'should have default setting: false' do
156
+ assert_equal false, Klarna.http_logging
157
+ end
158
+
159
+ it 'should be configurable' do
160
+ swap Klarna, :http_logging => true do
161
+ assert_equal true, Klarna.http_logging
162
+ end
163
+ end
164
+ end
165
+
166
+ end
167
+
168
+ describe "Helpers" do
169
+
170
+ describe '.setup' do
171
+ it 'should be defined' do
172
+ assert_respond_to Klarna, :setup
173
+ end
174
+
175
+ it 'should be possible to change settings in a block' do
176
+ Klarna.http_logging = false
177
+ assert_equal false, Klarna.http_logging
178
+
179
+ Klarna.setup do |c|
180
+ c.http_logging = true
181
+ end
182
+ assert_equal true, Klarna.http_logging
183
+ end
184
+ end
185
+
186
+ describe '.log' do
187
+ it 'should be defined' do
188
+ assert_respond_to Klarna, :log
189
+ end
190
+ end
191
+
192
+ describe '.load_credentials_from_file' do
193
+ it 'should be defined' do
194
+ assert_respond_to Klarna, :load_credentials_from_file
195
+ end
196
+
197
+ it 'should load settings from a external YAML config file' do
198
+ # TODO: Test loading settings from fixtures/klarna.yml
199
+ end
200
+ end
201
+
202
+ end
203
+
204
+ end