diff options
| author | Teddy Wing | 2017-09-05 13:10:42 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-09-05 13:10:42 +0200 | 
| commit | 1c3148a40966f0457117e317bb1144967d39c839 (patch) | |
| tree | 7f6f86746e8fdbfbca9035b6b303aa4c75ccef91 /spec/workers | |
| parent | bf56f221a0eedbceea99a1e20c2876383aa6c0dd (diff) | |
| download | chouette-core-1c3148a40966f0457117e317bb1144967d39c839.tar.bz2 | |
WorkbenchImportWorker spec: Use `subdirs` in place of `entry_groups`
Since the concept of `entry_groups` was changed to `subdirs`, this
change needs to be reflected in the tests.
Instead of looping over `entry_groups`, we now loop over `subdirs`, and
pass this object directly to `mock_post`.
The `mock_post` helper is now rewritten to reflect the new structure
of post parameters. Remove the `params` `let` because it's not used
anywhere else and we need to pass the arguments to `mock_post` into it.
This currently errors because `Faraday::UploadIO` isn't passed the
parameters that are expected in `mock_post`.
Diffstat (limited to 'spec/workers')
| -rw-r--r-- | spec/workers/workbench_import_worker_spec.rb | 51 | 
1 files changed, 26 insertions, 25 deletions
| diff --git a/spec/workers/workbench_import_worker_spec.rb b/spec/workers/workbench_import_worker_spec.rb index d30857320..9f7f61471 100644 --- a/spec/workers/workbench_import_worker_spec.rb +++ b/spec/workers/workbench_import_worker_spec.rb @@ -6,11 +6,6 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do    let( :workbench ){ import.workbench }    let( :referential ){ import.referential }    let( :api_key ){ build_stubbed :api_key, referential: referential, token: "#{referential.id}-#{SecureRandom.hex}" } -  let( :params ) do -    { netex_import: -      { referential_id: referential.id, workbench_id: workbench.id } -    } -  end    # http://www.example.com/workbenches/:workbench_id/imports/:id/download    let( :host ){ Rails.configuration.rails_host } @@ -31,11 +26,6 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do        )      end    end -  let( :entry_groups ) do -    entry_count.times.map do | i | -      {"entry_group_name#{i}" => subdirs[i] } -    end -  end    let( :zip_service ){ double("zip service") }    let( :zip_file ){ open_fixture('multiple_references_import.zip') } @@ -75,8 +65,8 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do          .with(host: host, path: path, params: {token: download_token})          .and_return( download_zip_response ) -      entry_groups.each do | entry_group_name, entry_group_stream | -        mock_post entry_group_name, entry_group_stream, post_response_ok +      subdirs.each do |subdir| +        mock_post subdir, post_response_ok        end        expect( import ).to receive(:update).with(total_steps: 2) @@ -97,14 +87,14 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do          .with(host: host, path: path, params: {token: download_token})          .and_return( download_zip_response ) -      # First entry_group succeeds -      entry_groups[0..0].each do | entry_group_name, entry_group_stream | -        mock_post entry_group_name, entry_group_stream, post_response_ok +      # First subdir succeeds +      subdirs[0..0].each do |subdir| +        mock_post subdir, post_response_ok        end -      # Second entry_group fails (M I S E R A B L Y) -      entry_groups[1..1].each do | entry_group_name, entry_group_stream | -        mock_post entry_group_name, entry_group_stream, post_response_failure +      # Second subdir fails (M I S E R A B L Y) +      subdirs[1..1].each do |subdir| +        mock_post subdir, post_response_failure        end        expect( import ).to receive(:update).with(total_steps: 3) @@ -117,13 +107,24 @@ RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do      end    end -  def mock_post entry_group_name, entry_group_stream, response +  def mock_post subdir, response      expect( HTTPService ).to receive(:post_resource) -      .with(host: host, -            path: upload_path, -            token: api_key.token, -            params: params, -            upload: {file: [entry_group_stream, 'application/zip', entry_group_name]}) -      .and_return(response) +      .with( +        host: host, +        path: upload_path, +        params: { +          netex_import: { +            parent_id: import.id, +            parent_type: import.class.name, +            workbench_id: workbench.id, +            name: subdir.name, +            file: HTTPService.upload( +              subdir.stream, +              'application/zip', +              "#{subdir.name}.zip" +            ) +          } +        } +      ).and_return(response)    end  end | 
