2019-03-27 18:24:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe MyModuleCommentsController, type: :controller do
|
2021-09-14 18:45:44 +08:00
|
|
|
login_user
|
|
|
|
include_context 'reference_project_structure' , {
|
2021-09-30 17:32:11 +08:00
|
|
|
role: :normal_user,
|
2021-09-14 16:10:14 +08:00
|
|
|
my_module_comment: true
|
|
|
|
}
|
2021-09-09 21:41:42 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'POST create' do
|
|
|
|
let(:action) { post :create, params: params, format: :json }
|
|
|
|
let(:params) do
|
|
|
|
{ my_module_id: my_module.id, comment: { message: 'comment created' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for adding comment to task' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type: :add_comment_to_module)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT update' do
|
|
|
|
let(:action) { put :update, params: params, format: :json }
|
|
|
|
let(:params) do
|
|
|
|
{ my_module_id: my_module.id,
|
2021-09-14 16:10:14 +08:00
|
|
|
id: my_module_comment.id,
|
2019-03-27 18:24:44 +08:00
|
|
|
comment: { message: 'comment updated' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for editing comment on task' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type: :edit_module_comment)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
let(:action) { delete :destroy, params: params, format: :json }
|
|
|
|
let(:params) do
|
2021-09-14 16:10:14 +08:00
|
|
|
{ my_module_id: my_module.id, id: my_module_comment.id }
|
2019-03-27 18:24:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for deleting comment on task' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type: :delete_module_comment)))
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|