aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-07-19 16:40:45 +0200
committerRobert2017-07-20 11:49:34 +0200
commita1368a9730e20b2e3a85885740e6fb7ffec435ad (patch)
tree0c8b5ad5b6da7d9813abb7feb16601afae8b8507
parentfba2bbccba9670d8d786781e7ec82f06b7a7fddc (diff)
downloadchouette-core-a1368a9730e20b2e3a85885740e6fb7ffec435ad.tar.bz2
bup working on WorkbenchImportWorker's integration spec [amend me]
-rw-r--r--app/workers/workbench_import_worker.rb19
-rw-r--r--config/environments/development.rb3
-rw-r--r--spec/controllers/imports_controller_spec.rb1
-rw-r--r--spec/factories/api_keys.rb6
-rw-r--r--spec/support/api_key.rb4
-rw-r--r--spec/support/json_helper.rb11
-rw-r--r--spec/workers/stop_area_referential_sync_worker_spec.rb1
-rw-r--r--spec/workers/workbench_import_worker_spec.rb25
8 files changed, 68 insertions, 2 deletions
diff --git a/app/workers/workbench_import_worker.rb b/app/workers/workbench_import_worker.rb
new file mode 100644
index 000000000..3c3d19a66
--- /dev/null
+++ b/app/workers/workbench_import_worker.rb
@@ -0,0 +1,19 @@
+class WorkbenchImportWorker
+ include Sidekiq::Worker
+ attr_reader :import, :downloaded
+
+ def perform(import_id)
+ @import = Import.find(import_id)
+ @downloaded = nil
+ download
+ end
+
+ def download
+
+
+ require 'pry'
+ binding.pry
+ 42
+
+ end
+end
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 59cb9eefa..79fec2d35 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -80,7 +80,8 @@ Rails.application.configure do
config.portal_url = "http://stif-boiv-staging.af83.priv"
# IEV url
- config.iev_url = "localhost:8080"
+ config.iev_url = "http://localhost:8080"
+ config.fe_url = "http://localhost:3000"
# file to data for demo
config.demo_data = "tmp/demo.zip"
diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb
index 7b575ab61..f07190496 100644
--- a/spec/controllers/imports_controller_spec.rb
+++ b/spec/controllers/imports_controller_spec.rb
@@ -15,6 +15,7 @@ RSpec.describe ImportsController, :type => :controller do
it 'should be successful' do
get :download, workbench_id: workbench.id, id: import.id, token: import.token_download
expect(response).to be_success
+ expect( response.body ).to eq(import.file.read)
end
end
end
diff --git a/spec/factories/api_keys.rb b/spec/factories/api_keys.rb
new file mode 100644
index 000000000..bd31edecc
--- /dev/null
+++ b/spec/factories/api_keys.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :api_key, class: Api::V1::ApiKey do
+ token { "#{referential.id}-#{SecureRandom.hex}" }
+ referential
+ end
+end
diff --git a/spec/support/api_key.rb b/spec/support/api_key.rb
index 9353fac15..561e1f796 100644
--- a/spec/support/api_key.rb
+++ b/spec/support/api_key.rb
@@ -1,5 +1,9 @@
module ApiKeyHelper
+ def authorization_token_header(key)
+ {'Authorization' => "Token token=#{key}"}
+ end
+
def get_api_key
Api::V1::ApiKey.first_or_create( :referential_id => referential.id, :name => "test")
end
diff --git a/spec/support/json_helper.rb b/spec/support/json_helper.rb
new file mode 100644
index 000000000..a383981a0
--- /dev/null
+++ b/spec/support/json_helper.rb
@@ -0,0 +1,11 @@
+module Support
+ module JsonHelper
+ def json_response_body
+ JSON.parse(response.body)
+ end
+ end
+end
+
+RSpec.configure do | config |
+ config.include Support::JsonHelper, type: :request
+end
diff --git a/spec/workers/stop_area_referential_sync_worker_spec.rb b/spec/workers/stop_area_referential_sync_worker_spec.rb
index 48b64e55e..50c7cf45f 100644
--- a/spec/workers/stop_area_referential_sync_worker_spec.rb
+++ b/spec/workers/stop_area_referential_sync_worker_spec.rb
@@ -1,4 +1,3 @@
-require 'rails_helper'
RSpec.describe StopAreaReferentialSyncWorker, type: :worker do
let!(:stop_area_referential_sync) { create :stop_area_referential_sync }
diff --git a/spec/workers/workbench_import_worker_spec.rb b/spec/workers/workbench_import_worker_spec.rb
new file mode 100644
index 000000000..bfe631fc4
--- /dev/null
+++ b/spec/workers/workbench_import_worker_spec.rb
@@ -0,0 +1,25 @@
+RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do
+
+ let( :worker ) { described_class.new }
+ let( :import ){ build_stubbed :import }
+ let( :workbench ){ import.workbench }
+ let( :referential ){ import.referential }
+ let( :api_key ){ build_stubbed :api_key, referential: referential }
+
+ let( :path ){ download_workbench_import_path(workbench, import) }
+ let( :result ){ import.file.read }
+
+ before do
+ # That should be `build_stubbed's` job, no?
+ allow(Import).to receive(:find).with(import.id).and_return(import)
+ end
+ it 'downloads a zip file' do
+ # /workbenches/:workbench_id/imports/:id/download
+ stub_request(:get, path)
+ .with(headers: authorization_token_header(api_key))
+ .to_return(body: result)
+ # WTH was I trying to test ;) Ah yeah HTTP into download
+ worker.perform import.id
+ expect( worker.downloaded ).to eq( result )
+ end
+end