scinote-web/spec/controllers/result_tables_controller_spec.rb
Soufiane 857bda6f69
Fix broken unit tests [SCI-8972] (#6342)
- Models tests
- Controllers tests
- Jobs tests
- Permissions tests
- Utilities tests
2023-10-12 16:16:43 +02:00

61 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe ResultTablesController, type: :controller do
login_user
include_context 'reference_project_structure', {
result_table: true
}
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id,
result:
{ name: 'result name created',
table_attributes:
{ contents: '{\"data\":[[\"a\",\"b\",\"1\",null,null]]}',
metadata: "{\"cells\":[{\"row\":\"0\",\"col\":\"0\",\"className\":\"\",\"calculated\":\"\"}]}" } } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :add_result))
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
{ id: result_table.id,
result: { name: result_table.result.name } }
end
it 'calls create activity service (edit_result)' do
params[:result][:name] = 'test result changed'
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :edit_result))
action
end
it 'calls create activity service (archive_result)' do
params[:result][:archived] = 'true'
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :archive_result))
action
end
it 'adds activity in DB' do
params[:result][:archived] = 'true'
expect { action }
.to(change { Activity.count })
end
end
end