scinote-web/spec/controllers/protocols_controller_spec.rb

235 lines
7.1 KiB
Ruby
Raw Normal View History

2019-03-08 17:57:09 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe ProtocolsController, type: :controller do
login_user
include_context 'reference_project_structure'
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 }
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
let(:protocol) { create :protocol, :in_public_repository, team: team, added_by: user }
2019-03-08 17:57:09 +08:00
let(:second_protocol) do
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
describe 'GET export from MyModule' do
let(:protocol) { create :protocol, :in_public_repository, team: team, added_by: user }
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',
# 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',
authors: 'authors'
}
}
end
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
2019-11-15 23:23:48 +08:00
describe 'PUT description' do
2019-03-08 17:57:09 +08:00
let(:protocol) do
create :protocol, :in_public_repository, team: team, added_by: user
end
let(:params) do
{
id: protocol.id,
protocol: {
description: 'description'
}
}
end
2019-11-13 20:57:04 +08:00
let(:action) { put :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)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
2019-03-08 17:57:09 +08:00
describe 'POST update_keywords' do
let(:protocol) do
create :protocol, :in_public_repository, team: team, added_by: user
end
let(:action) { put :update_keywords, params: params, format: :json }
let(:params) do
{ id: protocol.id, keywords: ['keyword-1', 'keyword-2'] }
end
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
create :protocol, :in_public_repository, name: ' test protocol',
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
let(:action) { put :revert, params: params, format: :json }
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
create :protocol, :in_public_repository, team: team, added_by: user
end
2020-09-09 18:04:43 +08:00
let(:protocol) { create :protocol, team: team, added_by: user, my_module: my_module }
let(:action) { put :load_from_repository, params: params, format: :json }
let(:params) do
{ source_id: protocol_source.id, id: protocol.id }
end
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
describe 'POST load_from_file' do
let(:protocol) do
create :protocol, my_module: my_module, team: team, added_by: user
end
let(:action) { put :load_from_file, params: params, format: :json }
let(:params) do
{ id: protocol.id,
protocol: { name: 'my_test_protocol',
description: 'description',
authors: 'authors' } }
end
it 'calls create activity for loading protocol to task from file' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type:
:load_protocol_to_task_from_file)))
2019-03-08 17:57:09 +08:00
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end