Skip to content

Commit

Permalink
add Alma get user to VCR
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Nov 22, 2024
1 parent 06ff3a9 commit 5aff064
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ yarn-debug.log*

config/settings.local.yml
config/settings/*.local.yml
config/settings/*
config/environments/*.local.yml

REVISION
Expand Down
11 changes: 10 additions & 1 deletion config/initializers/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

VCR.configure do |config|
config.cassette_library_dir = 'test/cassettes' # Directory to save cassettes
config.hook_into :webmock # Use WebMock to intercept HTTP requests
config.hook_into :webmock # Use WebMock to intercept HTTP requests

config.filter_sensitive_data('ALMA_API_KEY') { Settings.alma.api_key }
config.filter_sensitive_data('ALMA_TEST_USER_PRIMARY_ID') { Settings.alma.test_user_primary_id }
config.filter_sensitive_data('ALMA_TEST_USER_UNIV_ID') { Settings.alma.test_user_univ_id }
config.filter_sensitive_data('ALMA_TEST_USER_PASSWORD') { Settings.alma.test_user_password }

config.filter_sensitive_data('YPB_APPLICATION_PASSWORD') { Settings.ypb.application_password }
config.filter_sensitive_data('YPB_APPLICATION_ID') { Settings.ypb.application_id }
Expand All @@ -13,4 +16,10 @@
config.filter_sensitive_data('YPB_APPLICATION_LAW_PASSWORD') { Settings.ypb.application_law_password }
config.filter_sensitive_data('YPB_APPLICATION_LAW_ID') { Settings.ypb.application_law_id }
config.filter_sensitive_data('YPB_APPLICATION_LAW_NAME') { Settings.ypb.application_law_name }

if !Settings.alma.test_text_to_filter.nil?
Settings.alma.test_text_to_filter.each_with_index do |t,i|
config.filter_sensitive_data("FILTERED_TEXT_#{i}") { t }
end
end
end
59 changes: 59 additions & 0 deletions test/cassettes/get_test_user_fees_from_alma.yml

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

52 changes: 52 additions & 0 deletions test/cassettes/get_test_user_from_alma.yml

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

76 changes: 73 additions & 3 deletions test/lib/alma/fee_loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ class Alma::FeeLoaderTest < ActiveSupport::TestCase
assert new_one.original_amount == FEE_SAMPLE["original_amount"]
assert new_one.creation_time == FEE_SAMPLE["creation_time"]
assert new_one.item_title == FEE_SAMPLE["title"]

end


should "get values out of the HASH ## HELPER METHOD" do
assert_equal FEE_SAMPLE["status"]["value"], Alma::FeeLoader.get_val(FEE_SAMPLE, :status, :value)

Expand All @@ -127,7 +125,6 @@ class Alma::FeeLoaderTest < ActiveSupport::TestCase
assert_nil Alma::FeeLoader.get_val(FEE_SAMPLE, :something_else)
end


should "mark all active fees as stale for user" do
yorku_id = 101010
local_user = create :user, yorku_id: yorku_id
Expand All @@ -144,4 +141,77 @@ class Alma::FeeLoaderTest < ActiveSupport::TestCase

assert_equal 0, local_user.alma_fees.size
end

should "get test user from Alma" do
if Settings.alma.test_user_primary_id
VCR.use_cassette('get_test_user_from_alma') do
alma_test_user = Alma::User.find Settings.alma.test_user_primary_id
assert_equal Settings.alma.test_user_primary_id, alma_test_user.primary_id
end
end
end

should "get test user fees from Alma" do
alma_test_user = nil

if Settings.alma.test_user_primary_id
VCR.use_cassette('get_test_user_from_alma') do
alma_test_user = Alma::User.find Settings.alma.test_user_primary_id
assert_equal Settings.alma.test_user_primary_id, alma_test_user.primary_id
end

VCR.use_cassette('get_test_user_fees_from_alma') do
fees = alma_test_user.fines.response["fee"] if alma_test_user
assert_equal 4, fees.size
end
end
end

should "parse REAL Alma json fees into Alma::Fee objects" do
if Settings.alma.test_user_primary_id
fee_count_before = Alma::Fee.count

alma_test_user = nil

VCR.use_cassette('get_test_user_from_alma') do
alma_test_user = Alma::User.find Settings.alma.test_user_primary_id if Settings.alma.test_user_primary_id
assert_equal Settings.alma.test_user_primary_id, alma_test_user.primary_id
end

alma_test_user_fees = nil
VCR.use_cassette('get_test_user_fees_from_alma') do
alma_test_user_fees = alma_test_user.fines.response["fee"] if alma_test_user
assert_equal 4, alma_test_user_fees.size
end

univ_id = User.get_univ_id_from_alma_user(alma_test_user)
local_user = create :user, yorku_id: univ_id, username: alma_test_user.primary_id
alma_test_user_fees.each do |f|
fee = Alma::FeeLoader.parse_alma_fee f, local_user
assert fee.save

assert_equal fee.yorku_id, local_user.yorku_id
assert_equal fee.user_primary_id, local_user.username

assert_equal fee.fee_id, f["id"]
assert_equal fee.fee_type, f["type"]["value"]
assert_equal fee.fee_description, f["type"]["desc"]
assert_equal fee.fee_status, f["status"]["value"]
assert_equal fee.user_primary_id, f["user_primary_id"]["value"]
assert_equal fee.balance, f["balance"]
assert_equal fee.remaining_vat_amount, f["remaining_vat_amount"]
assert_equal fee.original_amount, f["original_amount"]
assert_equal fee.original_vat_amount, f["original_vat_amount"]
assert_equal fee.creation_time, Time.zone.parse(f["creation_time"])
assert_equal fee.status_time, Time.zone.parse(f["status_time"])
assert_equal fee.owner_id, f["owner"]["value"]
assert_equal fee.owner_description, f["owner"]["desc"]
assert_equal fee.item_title, f["title"]
assert_equal fee.item_barcode, f["barcode"]["value"]
end

fee_count_after = Alma::Fee.count
assert_equal fee_count_after, fee_count_before + alma_test_user_fees.size
end
end
end

0 comments on commit 5aff064

Please sign in to comment.