scinote-web/spec/controllers/repositories_controller_spec.rb

137 lines
3.8 KiB
Ruby
Raw Normal View History

2019-03-07 02:27:40 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe RepositoriesController, type: :controller do
login_user
let!(:user) { controller.current_user }
let!(:team) { create :team, created_by: user }
let!(:user_team) { create :user_team, :admin, user: user, team: team }
let(:action) { post :create, params: params, format: :json }
2019-03-07 02:27:40 +08:00
describe 'POST create' do
let(:params) { { repository: { name: 'My Repository' } } }
it 'calls create activity for creating inventory' do
2019-03-07 02:27:40 +08:00
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :create_inventory)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-07 02:27:40 +08:00
end
end
describe 'DELETE destroy' do
let(:repository) { create :repository, team: team }
let(:params) { { id: repository.id, team_id: team.id } }
let(:action) { delete :destroy, params: params }
2019-03-07 02:27:40 +08:00
it 'calls create activity for deleting inventory' do
2019-03-07 02:27:40 +08:00
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :delete_inventory)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-07 02:27:40 +08:00
end
end
describe 'PUT update' do
let(:repository) { create :repository, team: team }
let(:params) do
{ id: repository.id, team_id: team.id, repository: { name: 'new_name' } }
end
let(:action) { put :update, params: params, format: :json }
2019-03-07 02:27:40 +08:00
it 'calls create activity for renaming inventory' do
2019-03-07 02:27:40 +08:00
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :rename_inventory)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe 'POST export_repository' do
let(:repository) { create :repository, team: team }
let(:repository_row) { create :repository_row, repository: repository }
let(:repository_column) do
create :repository_column, repository: repository
end
let(:repository_cell) do
create :repository_cell,
repository_row: repository_row,
repository_column: repository_column
end
let(:params) do
{
id: repository.id,
header_ids: [repository_column.id],
row_ids: [repository_row.id]
}
end
let(:action) { post :export_repository, params: params, format: :json }
it 'calls create activity for exporting inventory items' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :export_inventory_items)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-07 02:27:40 +08:00
end
end
describe 'POST import_records' do
let(:repository) { create :repository, team: team }
let(:mappings) do
{ '0': '-1', '1': '', '2': '', '3': '', '4': '', '5': '' }
end
let(:params) do
{ id: repository.id,
team_id: team.id,
2019-04-19 19:37:52 +08:00
file_id: 'file_id',
mappings: mappings }
end
let(:action) { post :import_records, params: params, format: :json }
it 'calls create activity for importing inventory items' do
2019-04-19 19:37:52 +08:00
ImportRepository::ImportRecords.any_instance.stub(:import!)
2019-04-19 19:56:21 +08:00
.and_return(status: :ok)
2019-04-19 19:37:52 +08:00
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :import_inventory_items)))
action
end
it 'adds activity in DB' do
2019-04-19 19:37:52 +08:00
ImportRepository::ImportRecords.any_instance.stub(:import!)
2019-04-19 19:56:21 +08:00
.and_return(status: :ok)
2019-04-19 19:37:52 +08:00
expect { action }
.to(change { Activity.count })
end
end
2019-03-07 02:27:40 +08:00
end