Skip to content

Commit

Permalink
Add unit test for aus pay net api client
Browse files Browse the repository at this point in the history
  • Loading branch information
astley92 committed Sep 6, 2024
1 parent 3ae5a4f commit d9b44dc
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ gem 'minitest-stub-const'
gem 'net-ftp', '~> 0.1.3'
gem 'rake', '~> 13.0'
gem 'rubocop'
gem 'vcr'
1 change: 0 additions & 1 deletion lib/bsb/database_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'bsb/base_generator'
require 'bsb/aus_pay_net/client'
require 'faraday'

module BSB
class DatabaseGenerator < BaseGenerator
Expand Down
19 changes: 19 additions & 0 deletions test/bsb/aus_pay_net/client_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'bsb/aus_pay_net/client'
require 'test_helper'

describe BSB::AusPayNet::Client do
describe '.fetch_all_bsbs' do
before { ENV['AUSPAYNET_SUB_KEY'] = 'something' }

it 'returns the expected response' do
VCR.use_cassette('auspaynet_fetch_all_bsbs') do
response = BSB::AusPayNet::Client.fetch_all_bsbs
assert_equal(response.class, BSB::AusPayNet::Client::Response)
assert_equal(response.body.class, String)
assert_equal(JSON.parse(response.body).count, 2)
end
end
end
end
80 changes: 80 additions & 0 deletions test/fixtures/vcr_cassettes/auspaynet_fetch_all_bsbs.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
require 'bsb'
require 'minitest/autorun'
require 'minitest/stub_const'
require 'vcr'

Minitest.after_run do
Dir.glob('test/tmp/**/*.json').each { File.delete(_1) }
end

VCR.configure do |config|
config.cassette_library_dir = 'test/fixtures/vcr_cassettes'
config.hook_into :faraday
config.filter_sensitive_data('<AUSPAYNET_SUB_KEY>') do |interaction|
interaction.request.headers['Ocp-apim-subscription-key'][0]
end
end

class Account
include ActiveModel::API

Expand Down

0 comments on commit d9b44dc

Please sign in to comment.