boq_com_au 0.5.1 → 0.5.2

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: a51ff6b8ec0798bb6b8f4f87fe886c4bf8bc4caa01426574c3f087112a77d98d
4
- data.tar.gz: 719743f285019db673f69fcaf9fe091996071cefa35a613b7d227553f9d1457f
3
+ metadata.gz: 32b6644bfbc2facf0fa6c3d286b4d2a27b4f3f3e888c232df16d6d9fa97fb9dd
4
+ data.tar.gz: 6d6cc7fd0cfdef852614acf68a9fad30436e970983299fde1e364be39a4dc278
5
5
  SHA512:
6
- metadata.gz: 0535d93ec7097e5b7781318a1d37270d6a9eacb2aa584ebd4098fd1baf199efe62bfbd4bbe5a0072206312f3e17ba8cf781032e1eaef560dfff70f9f522a1a81
7
- data.tar.gz: 1424c6752bb7a2382f399278940c20e28dbc2e144bcd3d6fec9903c020019fc9d5e52e3067a116d57d0c4976d581dbdcb65e4ed76566f5a464806e08faee243b
6
+ metadata.gz: 308517ce6e17eafa31b2bbf783f68302554ef879032e8e9e8fc6f86b9d92481849b5234e6983be8beb4b5ee00fa07577ff722045a008ecfa20e5cb3983552153
7
+ data.tar.gz: 385ac117e104d6e153fe243aa1e708b0f2f8c5e7028eb16f22a2af83ba707bc20323cdc70bd19ce737271b25517997f9359ca21830dc4adbabe0917084805e76
data/CHANGELOG CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## 20261116
4
4
 
5
+ 0.5.2: ~ BoqComAu::Account#download_transactions returns nil where there are no transactions, rather than waiting for Export All until it times out.
6
+
7
+ 1. ~ BoqComAu::Account::TRANSACTIONS_SELECTORS: + results, Export All or BOQ's message that there are no transactions.
8
+ 2. ~ BoqComAu::Account#select_bank_account, #search: Wait for the results rather than for Export All.
9
+ 3. + BoqComAu::Account#transactions?
10
+ 4. ~ BoqComAu::Account#download_transactions: Exports only where there are transactions.
11
+ 5. ~ test/BoqComAu/Account_test.rb: Nothing is exported, and nil returned, where there are no transactions; transactions? is whether there's an Export All link.
12
+ 6. ~ README.md: Where there are no transactions, nil is returned.
13
+ 7. ~ BoqComAu::VERSION: /0.5.1/0.5.2/
14
+
5
15
  0.5.1: - BoqComAu::Account#login, #validate_args: Now uses superclass WebAccount.
6
16
 
7
17
  1. ~ boq_com_au.gemspec: webaccount /'~> 0.9'/'~> 0.10'/
data/README.md CHANGED
@@ -43,7 +43,7 @@ Without dates, the transactions are those BOQ shows on choosing the account. Giv
43
43
  ```
44
44
  Dates are Dates, or Strings `Date.parse` can read. Where only one of `from_date` and `to_date` is given, the other is a year ago or today.
45
45
 
46
- `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 the browser adds a number to that where a file of the name is there already.
46
+ `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 the browser adds a number to that where a file of the name is there already. Where there are no transactions in the range, BOQ says so in place of Export All, and nothing is exported: `download_transactions` returns nil.
47
47
 
48
48
  Or in one step, logging in, downloading, and shutting down even where the download fails:
49
49
  ```ruby
@@ -33,11 +33,12 @@ module BoqComAu
33
33
  text_fields: {xpath: '//input[@type="text"]'},
34
34
  search_link: {xpath: '//a[normalize-space()="Search"]'},
35
35
  export_all_link: {xpath: '//a[normalize-space()="Export All"]'},
36
+ results: {xpath: '//a[normalize-space()="Export All"] | //*[contains(text(), "There are no transactions that match your search requirements")]'},
36
37
  export_format_select_list: {xpath: '//select[option[contains(., "Comma Delimited Format (CSV)")]]'},
37
38
  download_button: {xpath: '//*[self::a or self::button][normalize-space()="Download"] | //input[@value="Download"]'}
38
39
  }
39
40
 
40
- # period is :all, the last year, or :last_month. Without it, from_date and to_date, either of which defaults to a year ago and today respectively where the other is given. Returns the name of the CSV file downloaded.
41
+ # period is :all, the last year, or :last_month. Without it, from_date and to_date, either of which defaults to a year ago and today respectively where the other is given. Returns the name of the CSV file downloaded, or nil where there are no transactions to export.
41
42
  def download_transactions(account_number:, period: nil, from_date: nil, to_date: nil)
42
43
  validate_args(account_number: account_number)
43
44
  from_date, to_date = dates(period: period, from_date: from_date, to_date: to_date)
@@ -47,7 +48,7 @@ module BoqComAu
47
48
  enter_dates(from_date: from_date, to_date: to_date)
48
49
  search
49
50
  end
50
- export_csv
51
+ export_csv if transactions?
51
52
  end
52
53
 
53
54
  private
@@ -111,7 +112,7 @@ module BoqComAu
111
112
  unless choose_option(find(TRANSACTIONS_SELECTORS[:account_select_list])){|text| text.delete('^0-9').include?(digits)}
112
113
  raise "Can't find account #{account_number} in the account list."
113
114
  end
114
- wait_for(TRANSACTIONS_SELECTORS[:export_all_link])
115
+ wait_for(TRANSACTIONS_SELECTORS[:results])
115
116
  end
116
117
 
117
118
  # The from and to fields are the two displayed text fields holding a date, as BOQ fills them in. Hidden ones are the form before Advanced Search has redrawn it.
@@ -131,12 +132,16 @@ module BoqComAu
131
132
  end
132
133
  end
133
134
 
134
- # Export All is already there before the search, and is replaced when the results are, so the old link is waited out first; otherwise it'd export what was there before.
135
+ # The results, Export All or BOQ's message that there are no transactions, are already there before the search, and are replaced when the search's are, so the old ones are waited out first; otherwise it'd export what was there before.
135
136
  def search
136
- export_all_link = driver.find_elements(*TRANSACTIONS_SELECTORS[:export_all_link].first).first
137
+ old_results = driver.find_elements(*TRANSACTIONS_SELECTORS[:results].first).first
137
138
  click(TRANSACTIONS_SELECTORS[:search_link])
138
- driver_wait.until{stale?(export_all_link)} if export_all_link
139
- wait_for(TRANSACTIONS_SELECTORS[:export_all_link])
139
+ driver_wait.until{stale?(old_results)} if old_results
140
+ wait_for(TRANSACTIONS_SELECTORS[:results])
141
+ end
142
+
143
+ def transactions?
144
+ driver.find_elements(*TRANSACTIONS_SELECTORS[:export_all_link].first).any?(&:displayed?)
140
145
  end
141
146
 
142
147
  def export_csv
@@ -2,5 +2,5 @@
2
2
  # BoqComAu::VERSION
3
3
 
4
4
  module BoqComAu
5
- VERSION = '0.5.1'
5
+ VERSION = '0.5.2'
6
6
  end
@@ -115,6 +115,7 @@ describe BoqComAu::Account do
115
115
  steps = []
116
116
  %i{get_transactions_page select_bank_account search export_csv}.each{|step| account.define_singleton_method(step){|*| steps << step}}
117
117
  account.define_singleton_method(:enter_dates){|from_date:, to_date:| steps << [:enter_dates, from_date, to_date]}
118
+ account.define_singleton_method(:transactions?){@transactions != false}
118
119
  [account, steps]
119
120
  end
120
121
 
@@ -130,6 +131,13 @@ describe BoqComAu::Account do
130
131
  _(steps).must_equal([:get_transactions_page, :select_bank_account, [:enter_dates, '2026-10-01', '2026-10-31'], :search, :export_csv])
131
132
  end
132
133
 
134
+ it "exports nothing, and returns nil, where there are no transactions" do
135
+ account, steps = account_recording_steps
136
+ account.instance_variable_set(:@transactions, false)
137
+ _(account.download_transactions(account_number: '12345678', period: :last_month)).must_be_nil
138
+ _(steps).must_equal([:get_transactions_page, :select_bank_account, [:enter_dates, *account.send(:dates, period: :last_month, from_date: nil, to_date: nil)], :search])
139
+ end
140
+
133
141
  it "names a missing account number, before going to the transactions page" do
134
142
  account, steps = account_recording_steps
135
143
  _(_{account.download_transactions(account_number: nil)}.must_raise(ArgumentError).message).must_equal('account_number is missing.')
@@ -294,7 +302,7 @@ describe BoqComAu::Account do
294
302
  end
295
303
 
296
304
  describe "#search" do
297
- it "waits for the results to replace the Export All link that was there before the search" do
305
+ it "waits for the results to replace those there before the search, Export All or BOQ's message that there are none" do
298
306
  old_export_all_link = stand_in_link
299
307
  account = account_with_driver(stand_in_driver(elements: [old_export_all_link]))
300
308
  account.define_singleton_method(:click){|*| old_export_all_link.stale!}
@@ -310,4 +318,11 @@ describe BoqComAu::Account do
310
318
  _(account.send(:search)).must_equal(true)
311
319
  end
312
320
  end
321
+
322
+ describe "#transactions?" do
323
+ it "is whether there's an Export All link, BOQ showing its message instead where there are none" do
324
+ _(account_with_driver(stand_in_driver(elements: [stand_in_element])).send(:transactions?)).must_equal(true)
325
+ _(account_with_driver(stand_in_driver(elements: [])).send(:transactions?)).must_equal(false)
326
+ end
327
+ end
313
328
  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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran