Fix export spec

pull/8453/head
Oliver Günther 4 years ago
parent 2d61cb92be
commit 88cb21a594
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 7
      app/controllers/work_packages_controller.rb
  2. 2
      app/workers/work_packages/exports/export_job.rb
  3. 23
      frontend/src/app/components/modals/export-modal/wp-table-export.modal.ts
  4. 12
      modules/bim/spec/controllers/work_packages_controller_spec.rb
  5. 8
      modules/bim/spec/features/bcf/export_spec.rb
  6. 32
      modules/bim/spec/workers/work_packages/exports/export_job_spec.rb
  7. 2
      modules/job_status/app/workers/job_status/application_job_with_status.rb
  8. 17
      modules/xls_export/spec/patches/work_packages_controller_patch_spec.rb
  9. 5
      spec/controllers/projects_controller_spec.rb
  10. 11
      spec/controllers/work_packages_controller_spec.rb
  11. 5
      spec/features/projects/template_spec.rb
  12. 2
      spec/features/work_packages/export_spec.rb
  13. 2
      spec/requests/api/v3/attachments/work_packages_export_spec.rb
  14. 30
      spec/workers/work_packages/exports/export_job_spec.rb

@ -87,7 +87,12 @@ class WorkPackagesController < ApplicationController
.new(user: current_user)
.call(query: @query, mime_type: mime_type, params: params)
.result
render plain: job_id
if request.headers['Accept']&.include?('application/json')
render json: { job_id: job_id }
else
redirect_to job_status_path(job_id)
end
end
def export_single(mime_type)

@ -71,7 +71,7 @@ module WorkPackages
download_url = ::API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(attachment.id)
update_status status: :success,
upsert_status status: :success,
message: I18n.t('export.succeeded'),
payload: download_payload(download_url)
end

@ -19,8 +19,8 @@ interface ExportLink extends HalLink {
}
/**
Modal for exporting work packages to different formats. The user may choose from a variety of formats (e.g. PDF and CSV).
The modal might also be used to only display the progress of an export. This will happen if a link for exporting is provided via the locals.
Modal for exporting work packages to different formats. The user may choose from a variety of formats (e.g. PDF and CSV).
The modal might also be used to only display the progress of an export. This will happen if a link for exporting is provided via the locals.
*/
@Component({
templateUrl: './wp-table-export.modal.html',
@ -82,13 +82,7 @@ export class WpTableExportModal extends OpModalComponent implements OnInit {
private triggerByLink(url:string, event:MouseEvent) {
event.preventDefault();
this
.requestExport(url)
.subscribe(
jobId => this.replaceWithJobModal(jobId),
error => this.handleError(error)
);
this.requestExport(url);
}
/**
@ -96,10 +90,15 @@ export class WpTableExportModal extends OpModalComponent implements OnInit {
*
* @param url
*/
private requestExport(url:string):Observable<string> {
return this
private requestExport(url:string):void {
this
.httpClient
.get(url, { observe: 'body', responseType: 'text' });
.get(url, { observe: 'body', responseType: 'json' })
.subscribe(
(json:{ job_id:string }) => this.replaceWithJobModal(json.job_id),
error => this.handleError(error)
);
}
private replaceWithJobModal(jobId:string) {

@ -64,14 +64,20 @@ describe WorkPackagesController, type: :controller do
allow(service_instance)
.to receive(:call)
.with(query: query, mime_type: mime_type.to_sym, params: anything)
.and_return(ServiceResult.new(result: export_storage))
.and_return(ServiceResult.new(result: 'uuid of the export job'))
end
it 'redirects to the export' do
get 'index', params: { format: 'bcf' }
expect(response).to redirect_to job_status_path('uuid of the export job')
end
expect(response)
.to redirect_to work_packages_export_path(export_storage.id)
context 'with json accept' do
it 'should fulfill the defined should_receives' do
request.headers['Accept'] = 'application/json'
get 'index', params: { format: 'bcf' }
expect(response.body).to eq({ job_id: 'uuid of the export job' }.to_json)
end
end
end
end

@ -79,11 +79,19 @@ describe 'bcf export',
::DownloadedFile::clear_downloads
page.find('.export-bcf-button').click
# Expect to get a response regarding queuing
expect(page).to have_content I18n.t('js.job_status.generic_messages.in_queue'),
wait: 10
perform_enqueued_jobs
# Wait for the file to download
::DownloadedFile.wait_for_download
::DownloadedFile.wait_for_download_content
# Close the modal
page.find('.op-modal--modal-close-button').click
# Check the downloaded file
OpenProject::Bim::BcfXml::Importer.new(
::DownloadedFile.download,

@ -32,19 +32,26 @@ require 'spec_helper'
describe WorkPackages::Exports::ExportJob do
let(:user) { FactoryBot.build_stubbed(:user) }
let(:attachment) { double('Attachment', id: 1234) }
let(:export) do
FactoryBot.build_stubbed(:work_packages_export, user: user)
FactoryBot.build_stubbed(:work_packages_export)
end
let(:query) { FactoryBot.build_stubbed(:query) }
let(:instance) { described_class.new }
let(:options) { {} }
let(:job) { described_class.new(jobs_args) }
let(:jobs_args) do
{
export: export,
mime_type: mime_type,
user: user,
options: {},
query: query,
query_attributes: {}
}
end
subject do
instance.perform(export: export,
mime_type: mime_type,
options: options,
query: query,
query_attributes: {})
job.tap(&:perform_now)
end
describe '#perform' do
@ -74,14 +81,17 @@ describe WorkPackages::Exports::ExportJob do
.to receive(:perform_after_grace)
expect(service)
.to receive(:call)
.with(uploaded_file: file, description: '')
.to(receive(:call))
.and_return attachment
allow(OpenProject::Bim::BcfXml::Exporter)
.to receive(:list)
.and_yield(result)
subject
# expect to create a status
expect(subject.job_status).to be_present
expect(subject.job_status[:status]).to eq 'success'
expect(subject.job_status[:payload]['download']).to eq '/api/v3/attachments/1234/content'
end
end
end

@ -68,7 +68,7 @@ module JobStatus
message: nil,
payload: nil,
reference_id: status_reference&.id,
reference_type: status_reference&.type,
reference_type: status_reference&.class.to_s,
user_id: User.current.id,
job_id: job_id
)

@ -121,7 +121,7 @@ describe WorkPackagesController, type: :controller do
let(:params) { {} }
let(:call_action) { get('index', params: params.merge(format: mime_type)) }
let(:mime_type) { 'xls' }
let(:export_storage) { FactoryBot.build_stubbed(:work_packages_export) }
let(:export_result) { 'uuid of the job' }
requires_export_permission do
before do
@ -134,15 +134,22 @@ describe WorkPackagesController, type: :controller do
allow(service_instance)
.to receive(:call)
.with(query: query, mime_type: mime_type.to_sym, params: anything)
.and_return(ServiceResult.new(result: export_storage))
.with(query: query, mime_type: mime_type.to_sym, params: anything)
.and_return(ServiceResult.new(result: export_result))
end
it 'should fulfill the defined should_receives' do
call_action
expect(response)
.to redirect_to(work_packages_export_path(export_storage.id))
expect(response).to redirect_to job_status_path('uuid of the job')
end
context 'with json accept' do
it 'should fulfill the defined should_receives' do
request.headers['Accept'] = 'application/json'
call_action
expect(response.body).to eq({ job_id: 'uuid of the job' }.to_json)
end
end
end
end

@ -334,6 +334,7 @@ describe ProjectsController, type: :controller do
describe 'with template project' do
let!(:template) { FactoryBot.create :template_project, identifier: 'template' }
let(:service_result) { double('Job', job_id: 'uuid of the job') }
let(:service_double) { double('Projects::InstantiateTemplateService') }
let(:project_params) do
{
@ -358,7 +359,7 @@ describe ProjectsController, type: :controller do
expect(service_double)
.to receive(:call) do |params|
expect(params.to_h).to eq(project_params.stringify_keys)
ServiceResult.new success: true, result: template
ServiceResult.new success: true, result: service_result
end
post :create,
@ -367,7 +368,7 @@ describe ProjectsController, type: :controller do
project: project_params
}
expect(response).to be_redirect
expect(response).to redirect_to job_status_path('uuid of the job')
end
end
end

@ -179,10 +179,17 @@ describe WorkPackagesController, type: :controller do
.and_return(ServiceResult.new(result: 'uuid of the export job'))
end
it 'should fulfill the defined should_receives' do
it 'redirects to the job status' do
call_action
expect(response).to redirect_to job_status_path('uuid of the export job')
end
expect(response.body).to eq 'uuid of the export job'
context 'with json accept' do
it 'should fulfill the defined should_receives' do
request.headers['Accept'] = 'application/json'
call_action
expect(response.body).to eq({ job_id: 'uuid of the export job' }.to_json)
end
end
end
end

@ -89,7 +89,8 @@ describe 'Project templates', type: :feature, js: true do
click_on 'Create'
expect(page).to have_content I18n.t('project.template.copying')
expect(page).to have_current_path home_path
expect(page).to have_content I18n.t('js.job_status.generic_messages.in_queue')
expect(page).to have_current_path /\/job_statuses\/[\w-]+/
# Email notification should be sent
perform_enqueued_jobs
@ -100,6 +101,8 @@ describe 'Project templates', type: :feature, js: true do
expect(mail).not_to be_nil
expect(page).to have_current_path '/projects/foo/', wait: 20
project = Project.find_by identifier: 'foo'
expect(project.name).to eq 'Foo bar'
expect(project).not_to be_templated

@ -70,7 +70,7 @@ describe 'work package export', type: :feature do
click_on export_type
# Expect to get a response regarding queuing
expect(page).to have_content 'The job has been queued and will be processed shortly.',
expect(page).to have_content I18n.t('js.job_status.generic_messages.in_queue'),
wait: 10
begin

@ -37,7 +37,7 @@ describe "WorkPackages::Export attachments" do
let(:read_permission) { :export_work_packages }
let(:update_permission) { :export_work_packages }
let(:export) { FactoryBot.create(:work_packages_export, user: author) }
let(:export) { FactoryBot.create(:work_packages_export) }
let(:missing_permissions_user) { FactoryBot.create(:user) }
let(:other_user) { FactoryBot.create(:user) }

@ -32,20 +32,28 @@ require 'spec_helper'
describe WorkPackages::Exports::ExportJob do
let(:user) { FactoryBot.build_stubbed(:user) }
let(:attachment) { double('Attachment', id: 1234) }
let(:export) do
FactoryBot.build_stubbed(:work_packages_export, user: user)
FactoryBot.create(:work_packages_export)
end
let(:query) { FactoryBot.build_stubbed(:query) }
let(:query_attributes) { {} }
let(:instance) { described_class.new }
let(:job) { described_class.new(jobs_args) }
let(:jobs_args) do
{
export: export,
mime_type: mime_type,
user: user,
options: options,
query: query,
query_attributes: query_attributes
}
end
let(:options) { {} }
subject do
instance.perform(export: export,
mime_type: mime_type,
options: options,
query: query,
query_attributes: query_attributes)
job.tap(&:perform_now)
end
shared_examples_for 'exporter returning string' do
@ -74,13 +82,19 @@ describe WorkPackages::Exports::ExportJob do
expect(File.basename(uploaded_file))
.to end_with ".#{mime_type}"
attachment
end
allow("WorkPackage::Exporter::#{mime_type.upcase}".constantize)
.to receive(:list)
.and_yield(result)
subject
# expect to create a status
expect(subject.job_status).to be_present
expect(subject.job_status.reference).to eq export
expect(subject.job_status[:status]).to eq 'success'
expect(subject.job_status[:payload]['download']).to eq '/api/v3/attachments/1234/content'
end
end

Loading…
Cancel
Save