2019-03-08 17:57:09 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ProtocolsController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2023-10-12 22:16:43 +08:00
|
|
|
include_context 'reference_project_structure', { team_role: :owner }
|
2021-09-09 21:41:42 +08:00
|
|
|
|
2019-03-08 17:57:09 +08:00
|
|
|
describe 'POST create' do
|
2019-03-13 16:06:48 +08:00
|
|
|
let(:action) { post :create, params: params, format: :json }
|
2019-03-27 18:24:44 +08:00
|
|
|
let(:params) { { protocol: { name: 'protocol_name' } } }
|
2019-03-08 17:57:09 +08:00
|
|
|
|
|
|
|
it 'calls create activity for creating inventory column' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:create_protocol_in_repository)))
|
2019-03-13 16:06:48 +08:00
|
|
|
action
|
2019-03-08 17:57:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
2019-03-13 16:06:48 +08:00
|
|
|
expect { action }
|
2019-03-08 17:57:09 +08:00
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET export' do
|
2022-06-07 00:21:57 +08:00
|
|
|
let(:protocol) { create :protocol, :in_public_repository, team: team, added_by: user }
|
2019-03-08 17:57:09 +08:00
|
|
|
let(:second_protocol) do
|
2022-06-07 00:21:57 +08:00
|
|
|
create :protocol, :in_public_repository, team: team, added_by: user
|
2019-03-08 17:57:09 +08:00
|
|
|
end
|
|
|
|
let(:params) { { protocol_ids: [protocol.id, second_protocol.id] } }
|
|
|
|
let(:action) { get :export, params: params }
|
|
|
|
|
|
|
|
it 'calls create activity for exporting protocols' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:export_protocol_in_repository))).twice
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count }.by(2))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-02 17:50:37 +08:00
|
|
|
describe 'GET export from MyModule' do
|
2022-06-07 00:21:57 +08:00
|
|
|
let(:protocol) { create :protocol, :in_public_repository, team: team, added_by: user }
|
2019-04-02 17:50:37 +08:00
|
|
|
let(:params) { { protocol_ids: [protocol.id], my_module_id: my_module.id } }
|
|
|
|
let(:action) { get :export, params: params }
|
|
|
|
|
|
|
|
it 'calls create activity for exporting protocols' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:export_protocol_from_task)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count }.by(1))
|
|
|
|
expect(Activity.last.subject_type).to eq 'MyModule'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-08 17:57:09 +08:00
|
|
|
describe 'POST import' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
team_id: team.id,
|
|
|
|
type: 'public',
|
2021-01-28 21:43:45 +08:00
|
|
|
# protocol: file_fixture('files/my_test_protocol.eln',
|
2019-03-08 17:57:09 +08:00
|
|
|
# 'application/json'),
|
|
|
|
# Not sure where should I attache file?
|
|
|
|
protocol: {
|
|
|
|
name: 'my_test_protocol',
|
|
|
|
description: 'description',
|
2023-10-12 22:16:43 +08:00
|
|
|
authors: 'authors',
|
|
|
|
elnVersion: '1.0',
|
2019-03-08 17:57:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2023-10-12 22:16:43 +08:00
|
|
|
|
2019-03-08 17:57:09 +08:00
|
|
|
let(:action) { post :import, params: params, format: :json }
|
|
|
|
|
|
|
|
it 'calls create activity for importing protocols' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:import_protocol_in_repository)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-12 22:16:43 +08:00
|
|
|
describe 'PATCH description' do
|
2019-03-08 17:57:09 +08:00
|
|
|
let(:protocol) do
|
2023-10-12 22:16:43 +08:00
|
|
|
create :protocol, :in_repository_draft, team: team, added_by: user
|
2019-03-08 17:57:09 +08:00
|
|
|
end
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
id: protocol.id,
|
|
|
|
protocol: {
|
|
|
|
description: 'description'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2023-10-12 22:16:43 +08:00
|
|
|
let(:action) { patch :update_description, params: params, format: :json }
|
2019-03-08 17:57:09 +08:00
|
|
|
it 'calls create activity for updating description' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:edit_description_in_protocol_repository)))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
2019-03-08 17:57:09 +08:00
|
|
|
|
2023-10-12 22:16:43 +08:00
|
|
|
describe 'PATCH update_keywords' do
|
2019-03-27 18:24:44 +08:00
|
|
|
let(:protocol) do
|
2023-10-12 22:16:43 +08:00
|
|
|
create :protocol, :in_repository_draft, team: team, added_by: user
|
2019-03-27 18:24:44 +08:00
|
|
|
end
|
|
|
|
let(:params) do
|
|
|
|
{ id: protocol.id, keywords: ['keyword-1', 'keyword-2'] }
|
|
|
|
end
|
2023-10-12 22:16:43 +08:00
|
|
|
let(:action) { patch :update_keywords, params: params, format: :json }
|
2019-03-27 18:24:44 +08:00
|
|
|
|
|
|
|
it 'calls create activity for updating keywords' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:edit_keywords_in_protocol_repository)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'update protocol' do
|
|
|
|
let(:protocol_repo) do
|
2023-10-12 22:16:43 +08:00
|
|
|
create :protocol, :in_repository_published_original, name: ' test protocol',
|
2019-03-27 18:24:44 +08:00
|
|
|
team: team,
|
|
|
|
added_by: user
|
|
|
|
end
|
|
|
|
let(:protocol) do
|
|
|
|
create :protocol, :linked_to_repository, name: ' test protocol',
|
|
|
|
my_module: my_module,
|
|
|
|
parent: protocol_repo,
|
|
|
|
team: team,
|
|
|
|
added_by: user
|
|
|
|
end
|
|
|
|
let(:params) { { id: protocol.id } }
|
|
|
|
|
|
|
|
describe 'POST revert' do
|
2023-10-12 22:16:43 +08:00
|
|
|
let(:action) { post :revert, params: params, format: :json }
|
2019-03-27 18:24:44 +08:00
|
|
|
|
|
|
|
it 'calls create activity for updating protocol in task from repository' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:update_protocol_in_task_from_repository)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST load_from_repository' do
|
|
|
|
let(:protocol_source) do
|
2023-10-12 22:16:43 +08:00
|
|
|
create :protocol, :in_repository_published_original, team: team, added_by: user
|
2019-03-27 18:24:44 +08:00
|
|
|
end
|
2020-09-09 18:04:43 +08:00
|
|
|
let(:protocol) { create :protocol, team: team, added_by: user, my_module: my_module }
|
2019-03-27 18:24:44 +08:00
|
|
|
let(:params) do
|
|
|
|
{ source_id: protocol_source.id, id: protocol.id }
|
|
|
|
end
|
2023-10-12 22:16:43 +08:00
|
|
|
let(:action) { post :load_from_repository, params: params, format: :json }
|
2019-03-27 18:24:44 +08:00
|
|
|
|
|
|
|
it 'calls create activity for loading protocol to task from repository' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type:
|
|
|
|
:load_protocol_to_task_from_repository)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
2019-03-08 17:57:09 +08:00
|
|
|
end
|