mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
try stubbing instead
This commit is contained in:
@@ -72,7 +72,7 @@ class DfcRequest
|
||||
# It results in an empty config hash and we lose our config.
|
||||
)
|
||||
client = strategy.client
|
||||
client.token_endpoint = strategy.config.token_endpoint
|
||||
client.token_endpoint = strategy.config.token_endpoint # tried to mock this but doesn't work.
|
||||
client.refresh_token = @user.oidc_account.refresh_token
|
||||
|
||||
token = client.access_token!
|
||||
|
||||
@@ -91,14 +91,15 @@ RSpec.describe DfcRequest do
|
||||
|
||||
context "with account tokens" do
|
||||
before do
|
||||
stub_request(:get, "http://example.net/api").
|
||||
to_return(status: 401)
|
||||
allow_any_instance_of(OpenIDConnect::Client).to receive(:config).and_return(double(token_endpoint: ""))
|
||||
|
||||
account.refresh_token = ENV.fetch("OPENID_REFRESH_TOKEN")
|
||||
api.call(
|
||||
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
|
||||
)
|
||||
expect(account.token).not_to be_nil
|
||||
account.token = "anything"
|
||||
end
|
||||
|
||||
it "clears the token if authentication fails", vcr: true do
|
||||
it "clears the token if authentication fails" do
|
||||
allow_any_instance_of(OpenIDConnect::Client).to receive(:access_token!).and_raise(
|
||||
Rack::OAuth2::Client::Error.new(
|
||||
1, { error: "invalid_grant", error_description: "session not active" }
|
||||
@@ -107,9 +108,9 @@ RSpec.describe DfcRequest do
|
||||
|
||||
expect {
|
||||
api.call(
|
||||
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
|
||||
"http://example.net/api"
|
||||
)
|
||||
}.to raise_error(Rack::OAuth2::Client::Error).and change {
|
||||
}.to change {
|
||||
account.token
|
||||
}.to(nil).and change {
|
||||
account.refresh_token
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user