diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-09 15:51:14 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-03-09 15:51:14 -0600 |
| commit | b83048a86262c1d40ab812d40dc65c416ae5637e (patch) | |
| tree | 4ff8f611aa1e9ef35e9295d267f02cd8e18b4f75 /spec/unit/dotnet | |
| parent | b31c3e0149a83bd354b6de16702744a8fbfed436 (diff) | |
Iterate through all nuget packages or starting from a specific page
Diffstat (limited to 'spec/unit/dotnet')
| -rw-r--r-- | spec/unit/dotnet/nuget_gateway_spec.rb | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/spec/unit/dotnet/nuget_gateway_spec.rb b/spec/unit/dotnet/nuget_gateway_spec.rb index 123a92f..4e08e7d 100644 --- a/spec/unit/dotnet/nuget_gateway_spec.rb +++ b/spec/unit/dotnet/nuget_gateway_spec.rb @@ -19,17 +19,55 @@ RSpec.describe Spandx::Dotnet::NugetGateway do end describe "#each" do - it 'fetches each item starting from a specific page' do - called = false + context "when iterating through every package" do + let(:n) { 10 } - VCR.use_cassette('nuget-catalogue-from-page-0') do - subject.each(page: 0) do |item, page| - called = true - expect(page).to end_with('page0.json') + before do + pages = n.times.map do |i| + { + '@id' => "https://api.nuget.org/v3/catalog0/page#{i}.json", + 'commitTimeStamp' => DateTime.now.iso8601 + } end + + stub_request(:get, "https://api.nuget.org/v3/catalog0/index.json") + .and_return(status: 200, body: JSON.generate({ items: pages })) + + n.times do |i| + stub_request(:get, "https://api.nuget.org/v3/catalog0/page#{i}.json") + .and_return(status: 200, body: JSON.generate({ + '@id' => "https://api.nuget.org/v3/catalog0/page#{i}.json", + items: [{ '@id' => "https://api.nuget.org/v3/catalog0/data/2020.01.01.00.00.00/spandx.0.1.#{i}.json" }] + })) + + stub_request(:get, "https://api.nuget.org/v3/catalog0/data/2020.01.01.00.00.00/spandx.0.1.#{i}.json") + .and_return(status: 200, body: JSON.generate({ id: 'spandx', version: "0.1.#{i}", licenseExpression: 'MIT' })) + end + end + + it 'fetches each item' do + collection = [] + subject.each do |item, page| + collection << item + expect(page).to match(/page(\d+)\.json/) + end + expect(collection).to match_array(n.times.map { |i| {"id"=>"spandx", "licenseExpression"=>"MIT", "version"=>"0.1.#{i}"} }) end + end + + context "when iterating through packages starting from a specific page" do + it 'fetches each item starting from a specific page' do + called = false - expect(called).to be(true) + VCR.use_cassette('nuget-catalogue-from-page-0') do + subject.each(page: 0) do |item, page| + called = true + expect(page).to end_with('page0.json') + end + end + + expect(called).to be(true) + end end end end |
