Skip to content

Commit

Permalink
Merge pull request #246 from vietqhoang/handle-string-response-for-fi…
Browse files Browse the repository at this point in the history
…nd-latest-version

Handle String response for "find latest version"
  • Loading branch information
rafaelfranca authored Apr 19, 2024
2 parents 61054a1 + 38fb116 commit 1d93e41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/importmap/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_json(uri)
end

def find_latest_version(response)
latest_version = response.dig('dist-tags', 'latest')
latest_version = response.is_a?(String) ? response : response.dig('dist-tags', 'latest')
return latest_version if latest_version

return unless response['versions']
Expand Down
10 changes: 10 additions & 0 deletions test/npm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,14 @@ def code() "200" end
end
end
end

test "return latest version response is a String type" do
response = "version not found".to_json

@npm.stub(:get_json, response) do
outdated_packages = @npm.outdated_packages

assert_equal('version not found', outdated_packages[0].latest_version)
end
end
end

0 comments on commit 1d93e41

Please sign in to comment.