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 }
|
2019-03-12 15:49:56 +08:00
|
|
|
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' } } }
|
|
|
|
|
2019-04-18 21:18:10 +08:00
|
|
|
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)))
|
|
|
|
|
2019-03-12 15:49:56 +08:00
|
|
|
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 } }
|
2019-03-12 15:49:56 +08:00
|
|
|
let(:action) { delete :destroy, params: params }
|
2019-03-07 02:27:40 +08:00
|
|
|
|
2019-04-18 21:18:10 +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)))
|
|
|
|
|
2019-03-12 15:49:56 +08:00
|
|
|
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
|
2019-03-12 15:49:56 +08:00
|
|
|
let(:action) { put :update, params: params, format: :json }
|
2019-03-07 02:27:40 +08:00
|
|
|
|
2019-04-18 21:18:10 +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)))
|
|
|
|
|
2019-03-12 15:49:56 +08:00
|
|
|
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 }
|
|
|
|
|
2019-04-18 21:18:10 +08:00
|
|
|
it 'calls create activity for exporting inventory items' do
|
2019-03-12 15:49:56 +08:00
|
|
|
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
|
2019-04-18 21:18:10 +08:00
|
|
|
|
|
|
|
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',
|
2019-04-18 21:18:10 +08:00
|
|
|
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
|
|
|
|
2019-04-18 21:18:10 +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
|
|
|
|
2019-04-18 21:18:10 +08:00
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
2019-03-07 02:27:40 +08:00
|
|
|
end
|