scinote-web/spec/controllers/reports_controller_spec.rb

85 lines
2.7 KiB
Ruby
Raw Normal View History

2019-03-11 20:26:54 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe ReportsController, type: :controller do
login_user
include_context 'reference_project_structure'
let(:my_module2) { create :my_module, experiment: experiment, created_by: experiment.created_by }
2019-03-11 20:26:54 +08:00
let(:report) do
create :report, user: user, project: project, team: team,
name: 'test repot A1', description: 'test description A1'
end
describe 'POST create' do
2019-03-11 20:26:54 +08:00
context 'in JSON format' do
let(:action) { post :create, params: params, format: :json }
2019-03-11 20:26:54 +08:00
let(:params) do
{ project_id: project.id,
report: { name: 'test report created',
2021-05-03 19:03:26 +08:00
description: 'test description created',
settings: Report::DEFAULT_SETTINGS },
project_content: { experiments: [{ id: experiment.id, my_module_ids: [my_module.id] }] },
2021-05-03 19:03:26 +08:00
template_values: [] }
2019-03-11 20:26:54 +08:00
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
2021-07-05 18:34:39 +08:00
.once.with(hash_including(activity_type: :create_report)).ordered
expect(Activities::CreateActivityService).to receive(:call)
.once.with(hash_including(activity_type: :generate_pdf_report)).ordered
action
end
2019-03-11 20:26:54 +08:00
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-11 20:26:54 +08:00
end
end
end
describe 'PUT update' do
2019-03-11 20:26:54 +08:00
context 'in JSON format' do
let(:action) { put :update, params: params, format: :json }
2019-03-11 20:26:54 +08:00
let(:params) do
{ project_id: project.id,
id: report.id,
report: { name: 'test report update',
description: 'test description update' },
2021-07-05 18:34:39 +08:00
project_content: { experiments: [{ id: experiment.id, my_module_ids: [my_module2.id] }] },
2021-05-03 19:03:26 +08:00
template_values: [] }
2019-03-11 20:26:54 +08:00
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
2021-07-05 18:34:39 +08:00
.once.with(hash_including(activity_type: :edit_report)).ordered
expect(Activities::CreateActivityService).to receive(:call)
.once.with(hash_including(activity_type: :generate_pdf_report)).ordered
action
end
2019-03-11 20:26:54 +08:00
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-11 20:26:54 +08:00
end
end
end
describe 'DELETE destroy' do
let(:action) { delete :destroy, params: params }
2019-03-11 20:26:54 +08:00
let(:params) { { report_ids: "[#{report.id}]" } }
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :delete_report))
action
end
2019-03-11 20:26:54 +08:00
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-11 20:26:54 +08:00
end
end
end