nordea-rb 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +19 -0
- data/README.markdown +163 -0
- data/Rakefile +25 -0
- data/VERSION +1 -0
- data/bin/nordea +66 -0
- data/lib/nordea/request.rb +42 -0
- data/lib/nordea/resources/account.rb +102 -0
- data/lib/nordea/resources/card.rb +5 -0
- data/lib/nordea/resources/fund.rb +5 -0
- data/lib/nordea/resources/loan.rb +5 -0
- data/lib/nordea/resources/resource.rb +7 -0
- data/lib/nordea/resources.rb +17 -0
- data/lib/nordea/session.rb +63 -0
- data/lib/nordea/support.rb +63 -0
- data/lib/nordea/transaction.rb +27 -0
- data/lib/nordea/version.rb +9 -0
- data/lib/nordea.rb +72 -0
- data/test/fixtures/account.wml +408 -0
- data/test/fixtures/account_10_transactions.wml +257 -0
- data/test/fixtures/account_15_transactions.wml +335 -0
- data/test/fixtures/account_5_transactions.wml +186 -0
- data/test/fixtures/accounts.wml +197 -0
- data/test/fixtures/accounts_overview.wml +111 -0
- data/test/fixtures/error.wml +32 -0
- data/test/fixtures/logged_in_main_menu.wml +133 -0
- data/test/fixtures/login.wml +44 -0
- data/test/fixtures/transfer_to_own_account.wml +175 -0
- data/test/fixtures/transfers.wml +74 -0
- data/test/fixtures/transfers_1.wml +116 -0
- data/test/fixtures/transfers_2.wml +115 -0
- data/test/fixtures/transfers_3.wml +121 -0
- data/test/test_account.rb +168 -0
- data/test/test_functional.rb +63 -0
- data/test/test_helper.rb +58 -0
- data/test/test_nordea.rb +49 -0
- data/test/test_request.rb +44 -0
- data/test/test_session.rb +129 -0
- data/test/test_transaction.rb +58 -0
- metadata +99 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestAccount < Test::Unit::TestCase
|
4
|
+
context Nordea::Account do
|
5
|
+
setup do
|
6
|
+
@session = Nordea::Session.new('foo', 'bar')
|
7
|
+
@account = Nordea::Account.new(:name => "savings account", :balance => 1234.50, :currency => 'EUR', :index => '2')
|
8
|
+
@account.session = @session
|
9
|
+
end
|
10
|
+
|
11
|
+
context "each Account instance" do
|
12
|
+
should "have a description of the account for #to_s" do
|
13
|
+
assert_equal 'savings account: 1234.50 EUR', @account.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have a pointer to the current session object" do
|
17
|
+
assert_equal @session, @account.session
|
18
|
+
end
|
19
|
+
|
20
|
+
should "request the transactions from the server" do
|
21
|
+
response = mock(:parse_xml => Hpricot.XML(fixture_content('account')))
|
22
|
+
@session.expects(:request).with('KF11TW', {}).returns(response)
|
23
|
+
@account.transactions
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "transfers" do
|
28
|
+
setup do
|
29
|
+
@savings = @account
|
30
|
+
@checking = Nordea::Account.new(:name => "checking account", :balance => 100.0, :currency => 'EUR', :index => '1')
|
31
|
+
@checking.session = @session
|
32
|
+
@session.stubs(:request)
|
33
|
+
@session.stubs(:accounts)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "withdraw" do
|
37
|
+
should "query phase 1" do
|
38
|
+
@session.expects(:request).with(Nordea::Commands::TRANSFER_TO_OWN_ACCOUNT_PHASE_1, has_entries({
|
39
|
+
:from_account_info => "2:EUR:savings account",
|
40
|
+
:amount => "6,5",
|
41
|
+
:currency_code => "EUR",
|
42
|
+
}));
|
43
|
+
|
44
|
+
@savings.withdraw(6.5, "EUR", :deposit_to => @checking)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "query phase 2" do
|
48
|
+
@session.expects(:request).with(Nordea::Commands::TRANSFER_TO_OWN_ACCOUNT_PHASE_2, has_entries({
|
49
|
+
:from_account_info => "2:EUR:savings account",
|
50
|
+
:to_account_info => "1:EUR:checking account",
|
51
|
+
:amount => "6,5",
|
52
|
+
:currency_code => "EUR",
|
53
|
+
}))
|
54
|
+
|
55
|
+
@savings.withdraw(6.5, "EUR", :deposit_to => @checking)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "query phase 3" do
|
59
|
+
@session.expects(:request).with(Nordea::Commands::TRANSFER_TO_OWN_ACCOUNT_PHASE_3, has_entries({
|
60
|
+
:currency_code => "EUR",
|
61
|
+
:from_account_number => "2",
|
62
|
+
:from_account_name => "savings account",
|
63
|
+
:to_account_number => "1",
|
64
|
+
:to_account_name => "checking account",
|
65
|
+
:amount => "6,5",
|
66
|
+
:exchange_rate => "0",
|
67
|
+
:from_currency_code => "EUR",
|
68
|
+
:to_currency_code => "EUR"
|
69
|
+
}))
|
70
|
+
|
71
|
+
@savings.withdraw(6.5, "EUR", :deposit_to => @checking)
|
72
|
+
end
|
73
|
+
|
74
|
+
should "reload the accounts" do
|
75
|
+
@session.expects(:accounts).with(true)
|
76
|
+
@savings.withdraw(6.5, "EUR", :deposit_to => @checking)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "deposit" do
|
81
|
+
should "should withdraw from the other account" do
|
82
|
+
@checking.expects(:withdraw).with(6.5, 'EUR', :deposit_to => @savings)
|
83
|
+
@savings.deposit(6.5, 'EUR', :withdraw_from => @checking)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "the list of transactions" do
|
89
|
+
setup do
|
90
|
+
response = stub(:parse_xml => Hpricot.XML(fixture_content('account')))
|
91
|
+
@session.stubs(:request).with('KF11TW', {}).returns(response)
|
92
|
+
@transactions = @account.transactions
|
93
|
+
end
|
94
|
+
|
95
|
+
should "find the accounts's transactions" do
|
96
|
+
assert_equal 20, @transactions.length
|
97
|
+
end
|
98
|
+
|
99
|
+
should "create an array with all transactions" do
|
100
|
+
assert_instance_of Array, @transactions
|
101
|
+
end
|
102
|
+
|
103
|
+
should "setup each transaction class" do
|
104
|
+
assert_instance_of Nordea::Transaction, @transactions.first
|
105
|
+
end
|
106
|
+
|
107
|
+
should "set transaction's date" do
|
108
|
+
assert_equal "2009-08-16", @transactions.first.date.to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
should "set transaction's amount" do
|
112
|
+
assert_equal -52.70, @transactions.first.amount
|
113
|
+
end
|
114
|
+
|
115
|
+
should "set transaction's text" do
|
116
|
+
assert_equal "Res. köp", @transactions.first.text
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "creating a new Account object from XML" do
|
121
|
+
setup do
|
122
|
+
@xml_node = <<-END
|
123
|
+
<card title="Översikt">
|
124
|
+
<p>
|
125
|
+
<anchor title="Kontoutdrag">Sparkonto
|
126
|
+
<go method="get" href="https://gfs.nb.se/bin2/gfskod">
|
127
|
+
<postfield name="OBJECT" value="KF11TW"/>
|
128
|
+
<postfield name="sid" value="123456789"/>
|
129
|
+
<postfield name="account_name" value="Sparkonto"/>
|
130
|
+
<postfield name="account_index" value="1"/>
|
131
|
+
<postfield name="account_type" value="001"/>
|
132
|
+
<postfield name="account_currency_code" value="SEK"/>
|
133
|
+
<postfield name="top_page" value="1"/>
|
134
|
+
</go>
|
135
|
+
</anchor>
|
136
|
+
<br/>  2.000,00 SEK<br/>
|
137
|
+
</p>
|
138
|
+
</card>
|
139
|
+
END
|
140
|
+
@account = Nordea::Account.new_from_xml(@xml_node, Nordea::Session.new('foo', 'bar'))
|
141
|
+
end
|
142
|
+
|
143
|
+
should "create a new Account instance" do
|
144
|
+
assert_instance_of Nordea::Account, @account
|
145
|
+
end
|
146
|
+
|
147
|
+
should "set the session object" do
|
148
|
+
assert_instance_of Nordea::Session, @account.session
|
149
|
+
end
|
150
|
+
|
151
|
+
should "have a name" do
|
152
|
+
assert_equal "Sparkonto", @account.name
|
153
|
+
end
|
154
|
+
|
155
|
+
should "have a currency" do
|
156
|
+
assert_equal "SEK", @account.currency
|
157
|
+
end
|
158
|
+
|
159
|
+
should "have a balance" do
|
160
|
+
assert_equal 2000.0, @account.balance
|
161
|
+
end
|
162
|
+
|
163
|
+
should "have an index" do
|
164
|
+
assert_equal "1", @account.index
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class FunctionalTest < Test::Unit::TestCase
|
4
|
+
context "functional testing" do
|
5
|
+
class ::Nordea::Request
|
6
|
+
alias_method :orig_connection, :connection
|
7
|
+
def faked_connection
|
8
|
+
FakedConnection.new(@command)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
setup do
|
13
|
+
Nordea::Request.send :alias_method, :connection, :faked_connection
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
Nordea::Request.send :alias_method, :connection, :orig_connection
|
18
|
+
end
|
19
|
+
|
20
|
+
should "login and display the number of accounts" do
|
21
|
+
def assert_requests_made(session, num_requests = 1, msg = nil, &blk)
|
22
|
+
before = session.num_requests
|
23
|
+
yield
|
24
|
+
after = session.num_requests
|
25
|
+
assert_equal before + num_requests, after, msg
|
26
|
+
end
|
27
|
+
|
28
|
+
Nordea.new('1234567890', '0987') do |n|
|
29
|
+
|
30
|
+
# logging in
|
31
|
+
assert_equal 2, n.num_requests # requires 2 requests to login
|
32
|
+
|
33
|
+
# listing the accounts
|
34
|
+
assert_requests_made(n, 1) { n.accounts.size }
|
35
|
+
assert_requests_made(n, 0) do
|
36
|
+
assert_equal %w[Sparkonto Huvudkonto Betalkonto], n.accounts.map(&:name)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_requests_made(n, 1, "reloading the accounts cache") { n.accounts(true) }
|
40
|
+
|
41
|
+
# getting one of the account's transactions
|
42
|
+
assert_requests_made(n, 1) do
|
43
|
+
assert_equal 5, n.accounts.first.transactions.size # we use the same ficture so all accounts have 20 transactions
|
44
|
+
end
|
45
|
+
|
46
|
+
# re-ask for the num of transactions
|
47
|
+
assert_requests_made(n, 0) do
|
48
|
+
assert_equal 5, n.accounts['Sparkonto'].transactions.size
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_requests_made(n, 1, "reload the cached transactions list") {
|
52
|
+
n.accounts['Sparkonto'].transactions(true).size
|
53
|
+
}
|
54
|
+
|
55
|
+
# ask for the other accounts's transactions
|
56
|
+
assert_requests_made(n, 2) do
|
57
|
+
assert_equal 10, n.accounts['Huvudkonto'].transactions.size
|
58
|
+
assert_equal 20, n.accounts['Betalkonto'].transactions.size
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w".. lib nordea")
|
2
|
+
require 'shoulda'
|
3
|
+
gem 'mocha', '=0.9.5'
|
4
|
+
require 'mocha'
|
5
|
+
require "test/unit"
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
class FakedConnection
|
9
|
+
def initialize(command)
|
10
|
+
@command = command
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(script, query, headers)
|
14
|
+
@fixture = {
|
15
|
+
Nordea::Commands::LOGIN_PHASE_1 => 'login',
|
16
|
+
Nordea::Commands::RESOURCE => 'accounts',
|
17
|
+
Nordea::Commands::TRANSACTIONS => 'account'
|
18
|
+
}[@command]
|
19
|
+
@query = query
|
20
|
+
OpenStruct.new(:body => _body_from_fixture)
|
21
|
+
end
|
22
|
+
|
23
|
+
def _body_from_fixture
|
24
|
+
@fixture = case @query
|
25
|
+
when /account_name=Betalkonto/ then fixture = 'account'
|
26
|
+
when /account_name=Huvudkonto/ then fixture = 'account_10_transactions'
|
27
|
+
when /account_name=Sparkonto/ then fixture = 'account_5_transactions'
|
28
|
+
end if @fixture == 'account'
|
29
|
+
@fixture ? fixture_contents(@fixture) : ""
|
30
|
+
end
|
31
|
+
|
32
|
+
# yes we redefined this for now
|
33
|
+
def fixture_contents(fixture)
|
34
|
+
IO.read(File.join(File.expand_path(File.join(File.dirname(__FILE__), "fixtures")), "#{fixture}.wml"))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Test::Unit::TestCase
|
39
|
+
FIXTURES_PATH = File.expand_path(File.join(File.dirname(__FILE__), "fixtures")) unless defined?(FIXTURES_PATH)
|
40
|
+
|
41
|
+
def fixture_content(filename)
|
42
|
+
IO.read(File.join(FIXTURES_PATH, "#{filename}.wml"))
|
43
|
+
end
|
44
|
+
|
45
|
+
# From Rails ActiveSupport::Testing::Declarative
|
46
|
+
def self.test(name, &block)
|
47
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
48
|
+
defined = instance_method(test_name) rescue false
|
49
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
50
|
+
if block_given?
|
51
|
+
define_method(test_name, &block)
|
52
|
+
else
|
53
|
+
define_method(test_name) do
|
54
|
+
flunk "No implementation provided for #{name}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/test_nordea.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestNordea < Test::Unit::TestCase
|
4
|
+
context "Setting personnummer and pincode" do
|
5
|
+
should "raise an error if no pnr and pin code are given" do
|
6
|
+
assert_raise(ArgumentError) { Nordea.new }
|
7
|
+
end
|
8
|
+
|
9
|
+
should "raise an ArgumentError if pnr is not exactly 10 digits" do
|
10
|
+
assert_raise(ArgumentError) { Nordea.new({ :pnr => "1234", :pin => "1234" }) }
|
11
|
+
end
|
12
|
+
|
13
|
+
should "raise an ArgumentError if the pin code is not exactly 4 digits" do
|
14
|
+
assert_raise(ArgumentError) { Nordea.new({ :pnr => "1234567890", :pin => "1" }) }
|
15
|
+
end
|
16
|
+
|
17
|
+
should "allow to set the pnr and pin code using two arguments" do
|
18
|
+
n = Nordea.new("1234567890", "1234")
|
19
|
+
assert_equal "1234567890", n.pnr
|
20
|
+
assert_equal "1234", n.pin
|
21
|
+
end
|
22
|
+
|
23
|
+
should "allow to set the pnr and pin using a hash" do
|
24
|
+
n = Nordea.new({ :pnr => '1234567890', :pin => '1234' })
|
25
|
+
assert_equal "1234567890", n.pnr
|
26
|
+
assert_equal "1234", n.pin
|
27
|
+
end
|
28
|
+
|
29
|
+
should "set the pnr and pin as strings" do
|
30
|
+
n = Nordea.new({ :pnr => 1234567890, :pin => "1234" })
|
31
|
+
assert_equal "1234567890", n.pnr
|
32
|
+
assert_equal "1234", n.pin
|
33
|
+
end
|
34
|
+
|
35
|
+
should "allow to set the pnr with seperators" do
|
36
|
+
n = Nordea.new({ :pnr => "12-34 56-7890", :pin => "1234" })
|
37
|
+
assert_equal "1234567890", n.pnr
|
38
|
+
end
|
39
|
+
|
40
|
+
should "allow to set the pin with seperators" do
|
41
|
+
n = Nordea.new({ :pnr => "1234567890", :pin => "12 - 34" })
|
42
|
+
assert_equal "1234", n.pin
|
43
|
+
end
|
44
|
+
|
45
|
+
should "raise an error if there is no pin provided" do
|
46
|
+
assert_raise(ArgumentError) { Nordea.new("1234567890") }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRequest < Test::Unit::TestCase
|
4
|
+
context "a request in general" do
|
5
|
+
setup do
|
6
|
+
@http = mock("Net::HTTP")
|
7
|
+
@response = mock("Net::HTTPResponse")
|
8
|
+
@response.stubs(:body => 'the body')
|
9
|
+
@http.stubs(:use_ssl= => true, :post => @response)
|
10
|
+
Net::HTTP.stubs(:new).returns(@http)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "use create a new Net:HTTP instance" do
|
14
|
+
Net::HTTP.expects(:new).returns(@http)
|
15
|
+
request = Nordea::Request.new('foo')
|
16
|
+
end
|
17
|
+
|
18
|
+
should "use ssl" do
|
19
|
+
@http.expects(:use_ssl=).with(true)
|
20
|
+
request = Nordea::Request.new('foo')
|
21
|
+
end
|
22
|
+
|
23
|
+
context "the query string" do
|
24
|
+
should "include the command as OBJECT" do
|
25
|
+
request = Nordea::Request.new('foo')
|
26
|
+
assert_match /OBJECT=foo/, request.query
|
27
|
+
end
|
28
|
+
|
29
|
+
should "include extra params if sent" do
|
30
|
+
request = Nordea::Request.new('cmd', { :foo => 'bar', :boo => 'far' })
|
31
|
+
assert_match /OBJECT=cmd/, request.query
|
32
|
+
assert_match /foo=bar/, request.query
|
33
|
+
assert_match /boo=far/, request.query
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should "parse the xml" do
|
38
|
+
Hpricot.expects(:XML).with("foo")
|
39
|
+
@response.stubs(:body).returns("foo")
|
40
|
+
request = Nordea::Request.new('cmd')
|
41
|
+
request.parse_xml
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestSession < Test::Unit::TestCase
|
4
|
+
context "a session in general" do
|
5
|
+
setup do
|
6
|
+
user, code = "1234567890", "1234"
|
7
|
+
@session = Nordea::Session.new(user, code)
|
8
|
+
@phase1_params = { :kundnr => user, :pinkod => code, :sid => "0" }
|
9
|
+
@response = stub(:parse_xml => '<foo></foo>')
|
10
|
+
end
|
11
|
+
|
12
|
+
context "logging in" do
|
13
|
+
setup do
|
14
|
+
@xml_fixture = fixture_content('login')
|
15
|
+
@xml_data = Hpricot.XML(@xml_fixture)
|
16
|
+
@response.stubs(:parse_xml).returns(@xml_data)
|
17
|
+
Nordea::Request.stubs(:new).returns(@response)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "send the first request (login phase #1)" do
|
21
|
+
Nordea::Request.expects(:new).with('WAP00', @phase1_params).returns(@response)
|
22
|
+
@session.login
|
23
|
+
end
|
24
|
+
|
25
|
+
should "parse the response xml" do
|
26
|
+
@response.expects(:parse_xml).returns(@xml_data)
|
27
|
+
@session.login
|
28
|
+
end
|
29
|
+
|
30
|
+
should 'set the token from the response xml' do
|
31
|
+
@session.login
|
32
|
+
assert_equal "123456789", @session.token
|
33
|
+
end
|
34
|
+
|
35
|
+
should "make the second request (login phase #2)" do
|
36
|
+
Nordea::Request.expects(:new).with('KK10', {
|
37
|
+
:bank => "mobile_light", :sid => '123456789',
|
38
|
+
:no_prev => "1", :contract => "0000000:HI:FOO+BAR" })
|
39
|
+
@session.login
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "invalid login" do
|
44
|
+
setup do
|
45
|
+
@xml_fixture = fixture_content('error')
|
46
|
+
@xml_data = Hpricot.XML(@xml_fixture)
|
47
|
+
@response.stubs(:parse_xml).returns(@xml_data)
|
48
|
+
Nordea::Request.stubs(:new).returns(@response)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "raise Nordea::InvalidLogin if login is invalid" do
|
52
|
+
assert_raise(Nordea::InvalidLogin) { @session.login }
|
53
|
+
end
|
54
|
+
|
55
|
+
should "get the error message from the xml doc" do
|
56
|
+
begin
|
57
|
+
@session.login
|
58
|
+
rescue Nordea::InvalidLogin => e
|
59
|
+
assert_equal "Pinkoden ni angivit är spärrad", e.message
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
should "use the sid param as token if set" do
|
65
|
+
Nordea::Request.expects(:new).with('cmd', { :sid => 't0k3n' })
|
66
|
+
@session.request('cmd', { :sid => 't0k3n' })
|
67
|
+
end
|
68
|
+
|
69
|
+
should "request a token unless there is one" do
|
70
|
+
@session.expects(:token).returns('my-token')
|
71
|
+
Nordea::Request.expects(:new).with('cmd', { :sid => 'my-token' })
|
72
|
+
@session.request('cmd')
|
73
|
+
end
|
74
|
+
|
75
|
+
should "logout" do
|
76
|
+
Nordea::Request.expects(:new).with('LL99', { :sid => 'token'})
|
77
|
+
@session.token = 'token'
|
78
|
+
@session.logout
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "creating the account objects" do
|
83
|
+
setup do
|
84
|
+
@session = Nordea::Session.new('1234567890', '1234')
|
85
|
+
@response = stub(:parse_xml => Hpricot.XML(fixture_content('accounts')))
|
86
|
+
Nordea::Request.stubs(:new).returns(@response)
|
87
|
+
end
|
88
|
+
|
89
|
+
should "should setup the accounts" do
|
90
|
+
assert_equal 3, @session.accounts.size
|
91
|
+
end
|
92
|
+
|
93
|
+
should "set each account's name" do
|
94
|
+
names = @session.accounts.map(&:name)
|
95
|
+
assert_equal ["Betalkonto", "Huvudkonto", "Sparkonto"], names.sort
|
96
|
+
end
|
97
|
+
|
98
|
+
should "find each accounts's balance" do
|
99
|
+
balances = { "Sparkonto" => 2000.00,
|
100
|
+
"Huvudkonto" => 5643.50,
|
101
|
+
"Betalkonto" => 179.05 }
|
102
|
+
@session.accounts.each do |account|
|
103
|
+
assert_equal balances[account.name], account.balance
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
should "find each accounts's currency" do
|
108
|
+
assert_equal ["SEK"], @session.accounts.map(&:currency).uniq
|
109
|
+
end
|
110
|
+
|
111
|
+
should "respond to #to_command_params with the extra parameters" do
|
112
|
+
assert_equal({
|
113
|
+
'account_name' => 'Sparkonto',
|
114
|
+
'account_index' => '1',
|
115
|
+
'account_type' => '001',
|
116
|
+
'account_currency_code' => 'SEK',
|
117
|
+
'top_page' => '1'
|
118
|
+
}, @session.accounts.first.to_command_params)
|
119
|
+
end
|
120
|
+
|
121
|
+
should "access the account by name using #[]" do
|
122
|
+
assert_equal @session.accounts[1], @session.accounts["Huvudkonto"]
|
123
|
+
end
|
124
|
+
|
125
|
+
should "find the account's name by pattern when using #[] with a regexp" do
|
126
|
+
assert_equal @session.accounts[1], @session.accounts[/huvud/i]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestTransaction < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@xml_node = <<-END
|
6
|
+
<anchor>090816  -52,70
|
7
|
+
<go href="#trans">
|
8
|
+
<setvar name="date" value="2009-08-16"/>
|
9
|
+
<setvar name="amount" value="-52,70"/>
|
10
|
+
<setvar name="text" value="Res. köp"/>
|
11
|
+
</go>
|
12
|
+
</anchor>
|
13
|
+
END
|
14
|
+
@transaction = Nordea::Transaction.new_from_xml(@xml_node)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "create a new transaction from a XML node" do
|
18
|
+
assert_instance_of Nordea::Transaction, @transaction
|
19
|
+
end
|
20
|
+
|
21
|
+
should "have a date" do
|
22
|
+
assert_instance_of Date, @transaction.date
|
23
|
+
assert_equal "2009-08-16", @transaction.date.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
should "have an amount" do
|
27
|
+
assert_equal -52.70, @transaction.amount
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have a text" do
|
31
|
+
assert_equal "Res. köp", @transaction.text
|
32
|
+
end
|
33
|
+
|
34
|
+
# should "allow to create a Transaction using a hash for params" do
|
35
|
+
# transaction = Nordea::Transaction.new(:date => '2009-10-11', :text => "foo", :amount => -13.37)
|
36
|
+
# assert_equal '2009-10-11', transaction.date.to_s
|
37
|
+
# assert_equal 'foo', transaction.text
|
38
|
+
# assert_equal -13.37, transaction.amount
|
39
|
+
# end
|
40
|
+
|
41
|
+
should "raise an ArgumentError if not enough arguments are given" do
|
42
|
+
assert_raise(ArgumentError) { Nordea::Transaction.new }
|
43
|
+
assert_raise(ArgumentError) { Nordea::Transaction.new('foo') }
|
44
|
+
assert_raise(ArgumentError) { Nordea::Transaction.new('foo', 'bar') }
|
45
|
+
end
|
46
|
+
|
47
|
+
should "know if it is a withdrawal" do
|
48
|
+
t = Nordea::Transaction.new('2009-01-01', -100.00, 'ACME Store')
|
49
|
+
assert t.withdrawal?
|
50
|
+
assert !t.deposit?
|
51
|
+
end
|
52
|
+
|
53
|
+
should "know if it is a deposit" do
|
54
|
+
t = Nordea::Transaction.new('2009-01-01', 10.00, 'Salery')
|
55
|
+
assert t.deposit?
|
56
|
+
assert !t.withdrawal?
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nordea-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Martin Str\xC3\xB6m"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-24 00:00:00 -04:00
|
13
|
+
default_executable: nordea
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby library for accessing your Nordea Bank account and transferring money between your own accounts.
|
17
|
+
email: name@my-domain.se
|
18
|
+
executables:
|
19
|
+
- nordea
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.markdown
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- bin/nordea
|
31
|
+
- lib/nordea.rb
|
32
|
+
- lib/nordea/request.rb
|
33
|
+
- lib/nordea/resources.rb
|
34
|
+
- lib/nordea/resources/account.rb
|
35
|
+
- lib/nordea/resources/card.rb
|
36
|
+
- lib/nordea/resources/fund.rb
|
37
|
+
- lib/nordea/resources/loan.rb
|
38
|
+
- lib/nordea/resources/resource.rb
|
39
|
+
- lib/nordea/session.rb
|
40
|
+
- lib/nordea/support.rb
|
41
|
+
- lib/nordea/transaction.rb
|
42
|
+
- lib/nordea/version.rb
|
43
|
+
- test/fixtures/account.wml
|
44
|
+
- test/fixtures/account_10_transactions.wml
|
45
|
+
- test/fixtures/account_15_transactions.wml
|
46
|
+
- test/fixtures/account_5_transactions.wml
|
47
|
+
- test/fixtures/accounts.wml
|
48
|
+
- test/fixtures/accounts_overview.wml
|
49
|
+
- test/fixtures/error.wml
|
50
|
+
- test/fixtures/logged_in_main_menu.wml
|
51
|
+
- test/fixtures/login.wml
|
52
|
+
- test/fixtures/transfer_to_own_account.wml
|
53
|
+
- test/fixtures/transfers.wml
|
54
|
+
- test/fixtures/transfers_1.wml
|
55
|
+
- test/fixtures/transfers_2.wml
|
56
|
+
- test/fixtures/transfers_3.wml
|
57
|
+
- test/test_account.rb
|
58
|
+
- test/test_functional.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
- test/test_nordea.rb
|
61
|
+
- test/test_request.rb
|
62
|
+
- test/test_session.rb
|
63
|
+
- test/test_transaction.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/haraldmartin/nordea-rb
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Ruby library for accessing your Nordea Bank account and transferring money between your own accounts.
|
92
|
+
test_files:
|
93
|
+
- test/test_account.rb
|
94
|
+
- test/test_functional.rb
|
95
|
+
- test/test_helper.rb
|
96
|
+
- test/test_nordea.rb
|
97
|
+
- test/test_request.rb
|
98
|
+
- test/test_session.rb
|
99
|
+
- test/test_transaction.rb
|