Skip to content

Commit

Permalink
fix: properly handle data wrapper in API response and update test inf…
Browse files Browse the repository at this point in the history
…rastructure
  • Loading branch information
devin-ai-integration[bot] committed Nov 11, 2024
1 parent e0d5b61 commit 6cafa4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/omniauth/strategies/mlh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def data
def fetch_and_process_data
response = access_token.get(build_api_url)
data = JSON.parse(response.body, symbolize_names: true)
return {} unless data.is_a?(Hash)
return {} unless data.is_a?(Hash) && data[:data].is_a?(Hash)

symbolize_nested_arrays(data)
symbolize_nested_arrays(data[:data])
end

def build_api_url
Expand Down
8 changes: 6 additions & 2 deletions spec/omni_auth/strategies/mlh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
end

shared_context 'with oauth response' do |response_data|
let(:oauth_response) { instance_double(OAuth2::Response, parsed: { 'data' => response_data }) }
let(:oauth_response) do
instance_double(OAuth2::Response,
body: { 'data' => response_data }.to_json,
parsed: { 'data' => response_data })
end
before do
allow(access_token).to receive(:get)
.with('https://api.mlh.com/v4/users/me')
Expand All @@ -23,7 +27,7 @@

describe '#data' do
context 'with expandable fields' do
let(:response) { instance_double(OAuth2::Response, parsed: { 'data' => {} }) }
let(:response) { instance_double(OAuth2::Response, body: { 'data' => {} }.to_json, parsed: { 'data' => {} }) }
let(:expand_url) { 'https://api.mlh.com/v4/users/me?expand[]=profile&expand[]=education' }

before do
Expand Down

0 comments on commit 6cafa4e

Please sign in to comment.