boq_com_au 0.0.2 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e8b7799cae1e5018367e722f35b0c1bb22dae5bd4405cbc1e20319b7b6fd9d9
4
- data.tar.gz: 68b9c98144244ffe4bc0c14eb499595884c9e5a3bffc3b866c7484363ba28cea
3
+ metadata.gz: 4ee1609019ff26e0055fe57d7e98bb43efcaa7708da26b4e3df98f310ecffb3a
4
+ data.tar.gz: 14545bd78bf644f95d33a0df3e0794a3a58ac2c88c070a2341a22e3acf2a91a9
5
5
  SHA512:
6
- metadata.gz: 59fcd1b13e6f05cc96ff15056e54bd44565a2ee236c79568d1a341632747971fd6c9f42e29df8e4fd0970ed2a006fce28f2c1c3ed700876fad2badb66d48e949
7
- data.tar.gz: 38405561fc456dcd62b48e0bb32529d4a8ef08ef75ec6e8b6a56fd6bee006a07dfcf9c159bfad35ef40f2e8612dd4bd5a5ffb5cb4ed07a6b9f49d9c95b4ebd19
6
+ metadata.gz: fdcf36437f2ce71868d7b4ce856b035b103f180fc517d3cd3e51b50bdba59db0bad95fcf7a36b2dde86562ef397fcdd352b182a62390b6b50950452b69a2c511
7
+ data.tar.gz: 9a95829cdd54d422172206b69f0a869191a046ea7b6472fc23f89b655253baa0a64640fa1f373a6fbc5378b7c78e6d328afa3e8bb801ccfca085226b58ff3096
data/CHANGELOG CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  ## 20261103
4
4
 
5
+ 0.1.0: + BoqComAu::Account#download_transactions, exporting an account's transactions as a CSV file.
6
+
7
+ 1. + BoqComAu::Account::TRANSACTIONS_SELECTORS
8
+ 2. + BoqComAu::Account#download_transactions(account_number:): Transaction History, the account chosen by the digits of its number, then Export All as CSV; returns the file downloaded.
9
+ 3. + BoqComAu::Account#initialize(download_directory:), #download_directory: Chrome downloads there without asking, and opens nothing.
10
+ 4. + BoqComAu::Account#click, #wait_for, #choose_option: a link not displayed is clicked by JavaScript; a select hidden by Chosen is chosen from by its own list, once Chosen has drawn it.
11
+ 5. + BoqComAu::Account#newest_csv_filename, #wait_for_download: the file is the newest CSV since Download was clicked, rather than BOQ's name for it, which Chrome numbers where a download of the same day is there already.
12
+ 6. + BoqComAu::Transactions.download_csv_file: login, download and shutdown in one, shutting down even where the download fails.
13
+ 7. ~ test/BoqComAu/Account_test.rb, + test/BoqComAu/Transactions_test.rb
14
+ 8. ~ README.md, boq_com_au.gemspec: downloading transactions.
15
+ 9. ~ BoqComAu::VERSION: /0.0.3/0.1.0/
16
+
17
+ 0.0.3: BoqComAu::Account#login is WebAccount's, which waits for the log off link.
18
+
19
+ 1. - BoqComAu::Account#login, #logon
20
+ 2. ~ BoqComAu::VERSION: /0.0.2/0.0.3/
21
+
5
22
  0.0.2: BoqComAu::Account#shutdown is WebAccount 0.6.1's, which quits the browser even where logging out fails.
6
23
 
7
24
  1. - BoqComAu::Account#shutdown
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Description
4
4
 
5
- Log into BOQ Classic Internet Banking (ib.boq.com.au), via Selenium WebDriver and WebAccount.
5
+ Log into BOQ Classic Internet Banking (ib.boq.com.au) and export an account's transactions as a CSV file, via Selenium WebDriver and WebAccount.
6
6
 
7
7
  myBOQ, BOQ's newer internet banking site, isn't covered.
8
8
 
@@ -23,16 +23,25 @@ $ gem install boq_com_au
23
23
 
24
24
  ## Usage
25
25
 
26
- ### Logging in, out, and shutting down
26
+ ### Downloading transactions
27
27
  ```ruby
28
28
  require 'boq_com_au'
29
29
 
30
30
  boq_account = BoqComAu::Account.new
31
31
  boq_account.login
32
- boq_account.driver # The logged-in browser.
33
- boq_account.logout
32
+ boq_account.download_transactions(account_number: '12345678')
33
+ # => "/Users/me/Downloads/12345678_20261103.csv"
34
34
  boq_account.shutdown # Logs out if still logged in, then quits Chrome.
35
35
  ```
36
+ The account is picked from the list by the digits of its number alone, so `'12345678'` and `'1234 5678'` are the same. Its transactions are those BOQ shows on choosing it, exported with Export All as Comma Delimited Format (CSV).
37
+
38
+ `download_transactions` waits for the download to finish, and returns the newest CSV file to have appeared in the download directory since Download was clicked. BOQ names it after the account number and the day's date, and Chrome adds a number to that where a file of the name is there already.
39
+
40
+ Or in one step, logging in, downloading, and shutting down even where the download fails:
41
+ ```ruby
42
+ BoqComAu::Transactions.download_csv_file(account_number: '12345678')
43
+ ```
44
+ Any other keyword arguments are passed to `BoqComAu::Account.new`.
36
45
 
37
46
  ### Credentials
38
47
 
@@ -49,13 +58,19 @@ Chrome is started with its automation flags masked. Given a `chrome_profile_dire
49
58
  ```ruby
50
59
  BoqComAu::Account.new(chrome_profile_directory: '~/path/to/chrome-profile')
51
60
  ```
61
+ Chrome downloads into `download_directory`, `~/Downloads` unless given, without asking where, and opens nothing it downloads:
62
+ ```ruby
63
+ BoqComAu::Account.new(download_directory: '~/path/to/statements')
64
+ ```
52
65
  Passing `browser:` or `driver_options:` to `BoqComAu::Account.new` replaces all of that, as for any WebAccount.
53
66
 
54
67
  Where BOQ asks for a one-time code after logging on, `login` waits up to 30 seconds for it to be entered in the browser.
55
68
 
56
69
  ## Limitations
57
70
 
58
- The login page's selectors were taken from the live page. BOQ's ids are generated, so things are found by their labels and text, and a change to the wording of the site will break it.
71
+ The selectors were taken from the live site. BOQ's ids are generated, so things are found by their labels and text, and a change to the wording of the site will break it.
72
+
73
+ The date range is BOQ's own, as shown on choosing the account; it can't yet be chosen.
59
74
 
60
75
  The tests cover only what doesn't depend on BOQ's site.
61
76
 
data/boq_com_au.gemspec CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.name = 'boq_com_au'
15
15
  spec.version = BoqComAu::VERSION
16
16
 
17
- spec.summary = "Log into BOQ Classic Internet Banking via Selenium WebDriver."
18
- spec.description = "Log into BOQ Classic Internet Banking with a Customer Access Number and password."
17
+ spec.summary = "Download transactions from BOQ Classic Internet Banking via Selenium WebDriver."
18
+ spec.description = "Log into BOQ Classic Internet Banking with a Customer Access Number and password, and export an account's transactions as a CSV file."
19
19
 
20
20
  spec.author = 'thoran'
21
21
  spec.email = 'code@thoran.com'
@@ -3,9 +3,13 @@
3
3
 
4
4
  # Notes:
5
5
  # 1. The login page's ids and names (id4, 8, ...) appear to be generated, so the fields are found by their labels.
6
- # 2. Where a one-time code is asked for after logging on, login() waits default_wait_timeout seconds for it to be entered by hand.
7
- # 3. Chrome is started with its automation flags masked; and, given a chrome_profile_directory, with that profile, kept between runs, so as the bank sees a returning browser rather than a fresh automated one.
8
- # 4. A username or password not given stops login, saying which is missing.
6
+ # 2. The ids and names after login (id121, 74, ...) appear to be generated too, so TRANSACTIONS_SELECTORS find things by their text.
7
+ # 3. BankFast's links are javascript:void(0) where they aren't the session's key and a callback number, and some, such as Transaction History, are in a menu which is closed. A link which isn't displayed is clicked by JavaScript.
8
+ # 4. Dropdowns are Chosen's, which hides the select and draws its own: <select id>_chosen, opened by its a.chosen-single and chosen from its li.active-result. A select which is displayed is used as it is.
9
+ # 5. Where a one-time code is asked for after logging on, login() waits default_wait_timeout seconds for it to be entered by hand.
10
+ # 6. Chrome is started with its automation flags masked; and, given a chrome_profile_directory, with that profile, kept between runs, so as the bank sees a returning browser rather than a fresh automated one. It downloads into download_directory without asking, and opens nothing it downloads.
11
+ # 7. A username or password not given stops login, saying which is missing.
12
+ # 8. BOQ names the exported file after the account number and the date, as 12345678_20261103.csv, and Chrome numbers a second download of the same name; so the newest CSV file to appear in download_directory once Download is clicked is taken to be it. Chrome names a download in progress .crdownload, so a CSV file is a finished one.
9
13
 
10
14
  require 'webaccount'
11
15
 
@@ -20,6 +24,15 @@ module BoqComAu
20
24
  logged_out_xpath: '//a[normalize-space()="Log On Again"] | //input[@id="btnSignIn"]'
21
25
  }
22
26
 
27
+ TRANSACTIONS_SELECTORS = {
28
+ transaction_history_link: {xpath: '//a[normalize-space()="Transaction History"]'},
29
+ account_select_list: {xpath: '//select[option[contains(., "Select one of the Accounts")]]'},
30
+ export_all_link: {xpath: '//a[normalize-space()="Export All"]'},
31
+ export_format_select_list: {xpath: '//select[option[contains(., "Comma Delimited Format (CSV)")]]'},
32
+ download_button: {xpath: '//*[self::a or self::button][normalize-space()="Download"] | //input[@value="Download"]'}
33
+ }
34
+
35
+ attr_reader :download_directory
23
36
  def username
24
37
  @username || raise("No username: it's given as username:.")
25
38
  end
@@ -28,24 +41,18 @@ module BoqComAu
28
41
  @password || raise("No password: it's given as password:.")
29
42
  end
30
43
 
31
- def login(username: nil, password: nil)
32
- @logged_in = false
33
- username ||= self.username
34
- password ||= self.password
35
- driver.attempt do
36
- get_login_page
37
- enter_username(username)
38
- enter_password(password)
39
- login_page_submit_button.click
40
- end
41
- @logged_in = driver_wait.until{!driver.element_present?(:id, 'btnSignIn')}
44
+ # Returns the name of the CSV file downloaded.
45
+ def download_transactions(account_number:)
46
+ get_transactions_page
47
+ select_bank_account(account_number)
48
+ export_csv
42
49
  end
43
- alias_method :logon, :login
44
50
 
45
51
  private
46
52
 
47
- def initialize(username: nil, password: nil, chrome_profile_directory: nil, browser: nil, driver_options: nil)
53
+ def initialize(username: nil, password: nil, chrome_profile_directory: nil, download_directory: File.join('~', 'Downloads'), browser: nil, driver_options: nil)
48
54
  @chrome_profile_directory = chrome_profile_directory && File.expand_path(chrome_profile_directory)
55
+ @download_directory = File.expand_path(download_directory)
49
56
  super(
50
57
  username: username, password: password,
51
58
  browser: browser, driver_options: driver_options,
@@ -67,7 +74,78 @@ module BoqComAu
67
74
  o.add_argument('--disable-blink-features=AutomationControlled')
68
75
  o.exclude_switches << 'enable-automation'
69
76
  o.add_preference(:credentials_enable_service, false)
77
+ o.add_preference(:download, default_directory: @download_directory, prompt_for_download: false, directory_upgrade: true, extensions_to_open: '')
78
+ end
79
+ end
80
+
81
+ # page interaction
82
+
83
+ # Found afresh on each attempt, so as an element replaced by a redrawn page is retried rather than ending in StaleElementReferenceError.
84
+ def click(selector)
85
+ driver.attempt do
86
+ element = find(selector)
87
+ element.displayed? ? element.click : driver.execute_script('arguments[0].click();', element)
88
+ end
89
+ end
90
+
91
+ def wait_for(selector)
92
+ driver_wait.until{driver.find_elements(*selector.first).any?(&:displayed?)}
93
+ end
94
+
95
+ def chosen_list(select_element)
96
+ driver.find_elements(id: "#{select_element.attribute('id')}_chosen").first
97
+ end
98
+
99
+ # Yields the text of each option in turn, and chooses the first for which the block is true; nil where there's none. A select hidden by Chosen is waited on until Chosen has drawn its list, which it does after the page has loaded.
100
+ def choose_option(select_element)
101
+ driver_wait.until{select_element.displayed? || chosen_list(select_element)}
102
+ if select_element.displayed?
103
+ option = Selenium::WebDriver::Support::Select.new(select_element).options.detect{|option| yield(option.text)}
104
+ else
105
+ chosen = chosen_list(select_element)
106
+ chosen.find_element(css: 'a.chosen-single').click
107
+ option = chosen.find_elements(css: 'li.active-result').detect{|option| yield(option.text)}
108
+ end
109
+ option&.click
110
+ option
111
+ end
112
+
113
+ # downloads
114
+
115
+ def newest_csv_filename(since:)
116
+ Dir.glob(File.join(@download_directory, '*.csv')).select{|filename| File.mtime(filename) >= since}.max_by{|filename| File.mtime(filename)}
117
+ end
118
+
119
+ def wait_for_download(since:)
120
+ driver_wait.until{newest_csv_filename(since: since)}
121
+ end
122
+
123
+ # transactions
124
+
125
+ def get_transactions_page
126
+ login unless logged_in?
127
+ click(TRANSACTIONS_SELECTORS[:transaction_history_link])
128
+ driver_wait.until{driver.element_present?(*TRANSACTIONS_SELECTORS[:account_select_list].first)}
129
+ end
130
+
131
+ def select_bank_account(account_number)
132
+ digits = account_number.to_s.delete('^0-9')
133
+ raise ArgumentError, "No digits in the account number #{account_number.inspect}." if digits.empty?
134
+ unless choose_option(find(TRANSACTIONS_SELECTORS[:account_select_list])){|text| text.delete('^0-9').include?(digits)}
135
+ raise "Can't find account #{account_number} in the account list."
136
+ end
137
+ wait_for(TRANSACTIONS_SELECTORS[:export_all_link])
138
+ end
139
+
140
+ def export_csv
141
+ click(TRANSACTIONS_SELECTORS[:export_all_link])
142
+ driver_wait.until{driver.element_present?(*TRANSACTIONS_SELECTORS[:export_format_select_list].first)}
143
+ unless choose_option(find(TRANSACTIONS_SELECTORS[:export_format_select_list])){|text| text.include?('(CSV)')}
144
+ raise "Can't find the CSV export format."
70
145
  end
146
+ clicked_at = Time.now
147
+ click(TRANSACTIONS_SELECTORS[:download_button])
148
+ wait_for_download(since: clicked_at)
71
149
  end
72
150
  end
73
151
  end
@@ -0,0 +1,18 @@
1
+ # BoqComAu/Transactions.rb
2
+ # BoqComAu::Transactions
3
+
4
+ require_relative './Account'
5
+
6
+ module BoqComAu
7
+ module Transactions
8
+ class << self
9
+ # Returns the name of the CSV file downloaded.
10
+ def download_csv_file(account_number:, **account_args)
11
+ boq_account = BoqComAu::Account.new(**account_args)
12
+ boq_account.download_transactions(account_number: account_number)
13
+ ensure
14
+ boq_account&.shutdown
15
+ end
16
+ end # class << self
17
+ end
18
+ end
@@ -2,5 +2,5 @@
2
2
  # BoqComAu::VERSION
3
3
 
4
4
  module BoqComAu
5
- VERSION = '0.0.2'
5
+ VERSION = '0.1.0'
6
6
  end
data/lib/boq_com_au.rb CHANGED
@@ -2,4 +2,5 @@
2
2
  # BoqComAu
3
3
 
4
4
  require_relative './BoqComAu/Account'
5
+ require_relative './BoqComAu/Transactions'
5
6
  require_relative './BoqComAu/VERSION'
@@ -1,14 +1,77 @@
1
1
  # test/BoqComAu/Account_test.rb
2
2
 
3
3
  # Notes:
4
- # 1. No browser and no BOQ: only what doesn't depend on the site is tested.
4
+ # 1. No browser and no BOQ: only what doesn't depend on the site is tested. Every account which might reach for its browser is given a stand-in, so as none is started.
5
5
 
6
6
  require_relative '../../lib/boq_com_au'
7
7
 
8
8
  require 'minitest/autorun'
9
9
  require 'minitest-spec-context'
10
+ require 'tmpdir'
10
11
 
11
12
  describe BoqComAu::Account do
13
+ def stand_in_element(text: '', displayed: true, id: nil)
14
+ element = Object.new
15
+ element.define_singleton_method(:text){text}
16
+ element.define_singleton_method(:displayed?){displayed}
17
+ element.define_singleton_method(:attribute){|name| id if name == 'id'}
18
+ element.define_singleton_method(:click){@clicked = true}
19
+ element.define_singleton_method(:clicked?){!!@clicked}
20
+ element
21
+ end
22
+
23
+ # What Chosen draws for a hidden select: <select id>_chosen, with a.chosen-single to open it and li.active-result to choose from.
24
+ def stand_in_chosen(*texts)
25
+ opener = stand_in_element
26
+ options = texts.map{|text| stand_in_element(text: text)}
27
+ chosen = Object.new
28
+ chosen.define_singleton_method(:find_element){|*| opener}
29
+ chosen.define_singleton_method(:find_elements){|*| options}
30
+ [chosen, opener, options]
31
+ end
32
+
33
+ # Goes stale, as a link does when the page redraws it, once stale! is called.
34
+ def stand_in_link
35
+ link = stand_in_element
36
+ link.define_singleton_method(:stale!){@stale = true}
37
+ link.define_singleton_method(:displayed?){@stale ? raise(Selenium::WebDriver::Error::StaleElementReferenceError) : true}
38
+ link
39
+ end
40
+
41
+ # Finds the elements by id given, though only after the number of looks given in drawn_after, as for a list Chosen hasn't drawn yet.
42
+ def stand_in_driver(elements_by_id: {}, drawn_after: 0)
43
+ driver = Object.new
44
+ looks = 0
45
+ driver.define_singleton_method(:attempt){|&block| block.call(self)}
46
+ driver.define_singleton_method(:find_elements){|*, **by| (looks += 1) > drawn_after ? [elements_by_id[by[:id]]].compact : []}
47
+ driver.define_singleton_method(:element_present?){|*| true}
48
+ driver.define_singleton_method(:execute_script){|script, *args| (@scripts ||= []) << [script, *args]}
49
+ driver.define_singleton_method(:scripts){@scripts || []}
50
+ driver
51
+ end
52
+
53
+ def account_with_driver(driver, **args)
54
+ account = BoqComAu::Account.new(**args)
55
+ account.instance_variable_set(:@driver, driver)
56
+ account.instance_variable_set(:@logged_in, true)
57
+ account
58
+ end
59
+
60
+ # An account whose account list is a hidden select drawn by Chosen, as BOQ's is.
61
+ def account_with_accounts(*texts, drawn_after: 0)
62
+ chosen, opener, options = stand_in_chosen(*texts)
63
+ select_list = stand_in_element(displayed: false, id: 'id71')
64
+ account = account_with_driver(stand_in_driver(elements_by_id: {'id71_chosen' => chosen}, drawn_after: drawn_after))
65
+ account.define_singleton_method(:find){|*| select_list}
66
+ account.define_singleton_method(:wait_for){|*| true}
67
+ [account, opener, options]
68
+ end
69
+
70
+ def touch(filename, mtime)
71
+ File.write(filename, '')
72
+ File.utime(mtime, mtime, filename)
73
+ end
74
+
12
75
  describe "#username and #password" do
13
76
  it "are those given" do
14
77
  account = BoqComAu::Account.new(username: 'customer', password: 'secret')
@@ -47,8 +110,103 @@ describe BoqComAu::Account do
47
110
  _(options.args).must_include("--user-data-dir=#{File.expand_path('~/profiles/boq')}")
48
111
  end
49
112
 
113
+ it "downloads into the download directory without asking, opening nothing" do
114
+ options = BoqComAu::Account.new(download_directory: '~/statements').send(:default_driver_options)
115
+ download = options.prefs[:download]
116
+ _(download[:default_directory]).must_equal(File.expand_path('~/statements'))
117
+ _(download[:prompt_for_download]).must_equal(false)
118
+ _(download[:extensions_to_open]).must_equal('')
119
+ end
120
+
121
+ it "downloads into ~/Downloads where no directory is given" do
122
+ _(BoqComAu::Account.new.download_directory).must_equal(File.expand_path('~/Downloads'))
123
+ end
124
+
50
125
  it "is nil for browsers other than Chrome" do
51
126
  _(BoqComAu::Account.new(browser: :firefox).send(:default_driver_options)).must_be_nil
52
127
  end
53
128
  end
129
+
130
+ describe "#click" do
131
+ it "finds the element afresh where the one found first has been redrawn" do
132
+ old_link, new_link = stand_in_link, stand_in_link
133
+ old_link.stale!
134
+ driver = stand_in_driver
135
+ attempts = 0
136
+ driver.define_singleton_method(:attempt) do |&block|
137
+ block.call(self)
138
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError
139
+ attempts += 1
140
+ retry if attempts < 3
141
+ raise
142
+ end
143
+ account = account_with_driver(driver)
144
+ links = [old_link, new_link]
145
+ account.define_singleton_method(:find){|*| links.shift}
146
+ account.send(:click, {xpath: '//a'})
147
+ _(new_link.clicked?).must_equal(true)
148
+ end
149
+ end
150
+
151
+ describe "#newest_csv_filename" do
152
+ it "is the newest CSV file in the download directory since the time given" do
153
+ Dir.mktmpdir do |directory|
154
+ since = Time.now - 60
155
+ touch(File.join(directory, 'old.csv'), since - 60)
156
+ touch(File.join(directory, 'new.csv'), since + 10)
157
+ touch(File.join(directory, 'newer.csv'), since + 20)
158
+ touch(File.join(directory, 'newest.csv.crdownload'), since + 30)
159
+ account = BoqComAu::Account.new(download_directory: directory)
160
+ _(account.send(:newest_csv_filename, since: since)).must_equal(File.join(directory, 'newer.csv'))
161
+ end
162
+ end
163
+
164
+ it "is nil where none has appeared since" do
165
+ Dir.mktmpdir do |directory|
166
+ since = Time.now
167
+ touch(File.join(directory, 'old.csv'), since - 60)
168
+ _(BoqComAu::Account.new(download_directory: directory).send(:newest_csv_filename, since: since)).must_be_nil
169
+ end
170
+ end
171
+ end
172
+
173
+ describe "#get_transactions_page" do
174
+ it "clicks the history link by JavaScript, the link being in a menu which is closed" do
175
+ driver = stand_in_driver
176
+ link = stand_in_element(displayed: false)
177
+ account = account_with_driver(driver)
178
+ account.define_singleton_method(:find){|*| link}
179
+ account.send(:get_transactions_page)
180
+ _(driver.scripts).must_equal([['arguments[0].click();', link]])
181
+ _(link.clicked?).must_equal(false)
182
+ end
183
+ end
184
+
185
+ describe "#select_bank_account" do
186
+ it "opens the account list and picks the account by the digits of its number, however either is written" do
187
+ account, opener, options = account_with_accounts('Everyday 1111 2222', 'Saver 3333-4444')
188
+ account.send(:select_bank_account, '33334444')
189
+ _(opener.clicked?).must_equal(true)
190
+ _(options.map(&:clicked?)).must_equal([false, true])
191
+ end
192
+
193
+ it "waits for Chosen to draw the list where it hasn't yet" do
194
+ account, opener, options = account_with_accounts('Everyday 1111 2222', drawn_after: 2)
195
+ account.send(:select_bank_account, '11112222')
196
+ _(opener.clicked?).must_equal(true)
197
+ _(options.map(&:clicked?)).must_equal([true])
198
+ end
199
+
200
+ it "says which account it couldn't find" do
201
+ account, _opener, _options = account_with_accounts('Everyday 1111 2222')
202
+ error = _{account.send(:select_bank_account, '9999')}.must_raise(RuntimeError)
203
+ _(error.message).must_include('9999')
204
+ end
205
+
206
+ it "refuses an account number without digits, which would match every account" do
207
+ account, _opener, options = account_with_accounts('Everyday 1111 2222')
208
+ _{account.send(:select_bank_account, '...')}.must_raise(ArgumentError)
209
+ _(options.map(&:clicked?)).must_equal([false])
210
+ end
211
+ end
54
212
  end
@@ -0,0 +1,43 @@
1
+ # test/BoqComAu/Transactions_test.rb
2
+
3
+ # Notes:
4
+ # 1. BoqComAu::Account.new is swapped for a stand-in for the length of each example and put back afterwards, so as no browser is started.
5
+
6
+ require_relative '../../lib/boq_com_au'
7
+
8
+ require 'minitest/autorun'
9
+ require 'minitest-spec-context'
10
+
11
+ describe BoqComAu::Transactions do
12
+ def with_stand_in_account(download: ->{'/downloads/transactions.csv'})
13
+ account = Object.new
14
+ account.define_singleton_method(:download_transactions){|account_number:| (@asked ||= []) << account_number; download.call}
15
+ account.define_singleton_method(:asked){@asked}
16
+ account.define_singleton_method(:shutdown){@shut_down = true}
17
+ account.define_singleton_method(:shut_down?){!!@shut_down}
18
+ arguments = []
19
+ original = BoqComAu::Account.method(:new)
20
+ BoqComAu::Account.define_singleton_method(:new){|**args| arguments << args; account}
21
+ yield account, arguments
22
+ ensure
23
+ BoqComAu::Account.define_singleton_method(:new, original)
24
+ end
25
+
26
+ describe ".download_csv_file" do
27
+ it "is the file downloaded, for the account given, the other arguments going to the account, which is shut down" do
28
+ with_stand_in_account do |account, arguments|
29
+ _(BoqComAu::Transactions.download_csv_file(account_number: '12345678', download_directory: '/downloads')).must_equal('/downloads/transactions.csv')
30
+ _(account.asked).must_equal(['12345678'])
31
+ _(arguments).must_equal([{download_directory: '/downloads'}])
32
+ _(account.shut_down?).must_equal(true)
33
+ end
34
+ end
35
+
36
+ it "shuts the account down even where the download fails" do
37
+ with_stand_in_account(download: ->{raise Selenium::WebDriver::Error::TimeoutError}) do |account, _arguments|
38
+ _{BoqComAu::Transactions.download_csv_file(account_number: '12345678')}.must_raise(Selenium::WebDriver::Error::TimeoutError)
39
+ _(account.shut_down?).must_equal(true)
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boq_com_au
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -80,7 +80,7 @@ dependencies:
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  description: Log into BOQ Classic Internet Banking with a Customer Access Number and
83
- password.
83
+ password, and export an account's transactions as a CSV file.
84
84
  email: code@thoran.com
85
85
  executables: []
86
86
  extensions: []
@@ -93,9 +93,11 @@ files:
93
93
  - Rakefile
94
94
  - boq_com_au.gemspec
95
95
  - lib/BoqComAu/Account.rb
96
+ - lib/BoqComAu/Transactions.rb
96
97
  - lib/BoqComAu/VERSION.rb
97
98
  - lib/boq_com_au.rb
98
99
  - test/BoqComAu/Account_test.rb
100
+ - test/BoqComAu/Transactions_test.rb
99
101
  homepage: https://github.com/thoran/boq_com_au
100
102
  licenses:
101
103
  - MIT
@@ -116,5 +118,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  requirements: []
117
119
  rubygems_version: 4.0.23
118
120
  specification_version: 4
119
- summary: Log into BOQ Classic Internet Banking via Selenium WebDriver.
121
+ summary: Download transactions from BOQ Classic Internet Banking via Selenium WebDriver.
120
122
  test_files: []