Skip to content

Commit 599d1b8

Browse files
committed
Fix bad expired token test!
1 parent 7b5862a commit 599d1b8

File tree

7 files changed

+152
-84
lines changed

7 files changed

+152
-84
lines changed

spec/berkeley_library/location/world_cat/oclc_auth_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'spec_helper'
2+
require 'time'
23

34
module BerkeleyLibrary
45
module Location
@@ -12,17 +13,26 @@ module WorldCat
1213
end
1314
end
1415

15-
it 'refreshes a token' do
16+
it 'refreshes an expired token' do
1617
VCR.use_cassette('oclc_auth/refresh_token') do
18+
# First get a token....
1719
token = OCLCAuth.instance.token
1820

1921
# Need to set the token expiration to a time in the past
20-
token[:expires_at] = (Time.now - 1).to_s
22+
token[:expires_at] = (Time.now - 60).to_s
23+
token[:access_token] = 'expired_token'
24+
25+
# Now we need to set the token instance to the token with the updated expiration
2126
OCLCAuth.instance.token = token
2227

28+
# Trigger a refresh by calling access_token
2329
OCLCAuth.instance.access_token
2430

25-
expect(OCLCAuth.instance.token[:access_token]).to be_a(String)
31+
# Now check that the token has been refreshed
32+
token = OCLCAuth.instance.token
33+
34+
expect(token[:access_token]).not_to eq('expired_token')
35+
expect(Time.parse(token[:expires_at])).to be >= Time.now
2636
end
2737
end
2838

spec/cassettes/libraries_request/execute_holdings_1.yml

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/libraries_request/execute_holdings_2.yml

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/libraries_request/execute_holdings_3.yml

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/libraries_request/execute_holdings_4.yml

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)