2019-07-15 23:00:55 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe TeamRepositoriesController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2022-06-07 00:21:57 +08:00
|
|
|
include_context 'reference_project_structure'
|
|
|
|
|
|
|
|
let(:repository) { create :repository, team: team, created_by: user }
|
2023-11-13 16:34:38 +08:00
|
|
|
let(:target_team) { create :team, created_by: user }
|
2019-07-15 23:00:55 +08:00
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
2022-06-07 00:21:57 +08:00
|
|
|
let(:second_team) { create :team, created_by: user }
|
2023-10-12 22:16:43 +08:00
|
|
|
let(:team_repository) { create :team_shared_object, :read, team: second_team, shared_object: repository }
|
2019-07-15 23:00:55 +08:00
|
|
|
|
|
|
|
context 'when resource can be deleted' do
|
2019-07-16 18:21:20 +08:00
|
|
|
let(:action) do
|
2023-11-13 16:34:38 +08:00
|
|
|
delete :destroy, params: { repository_id: repository.id, team_id: team.id, id: team_repository.id }
|
2019-07-16 18:21:20 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 204' do
|
|
|
|
action
|
2019-07-15 23:00:55 +08:00
|
|
|
|
|
|
|
expect(response).to have_http_status(204)
|
|
|
|
end
|
2019-07-16 18:21:20 +08:00
|
|
|
|
|
|
|
it 'calls create activity for deleting inventory' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type: :unshare_inventory)))
|
|
|
|
|
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }.to(change { Activity.count })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when resource is not found' do
|
|
|
|
it 'renders 422' do
|
|
|
|
delete :destroy, params: { repository_id: repository.id, team_id: team.id, id: -1 }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
2019-07-15 23:00:55 +08:00
|
|
|
end
|
|
|
|
|
2019-08-29 23:17:38 +08:00
|
|
|
context 'when user do not have access to inventory' do
|
|
|
|
it 'renders 404' do
|
2022-06-07 00:21:57 +08:00
|
|
|
repository.user_assignments.update(user_role: viewer_role)
|
|
|
|
delete :destroy, params: { repository_id: repository.id, team_id: team.id, id: team_repository.id }
|
|
|
|
expect(response).to have_http_status(403)
|
2019-07-15 23:00:55 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-08-06 21:17:13 +08:00
|
|
|
|
2019-08-29 23:17:38 +08:00
|
|
|
describe 'POST update' do
|
2019-08-06 21:17:13 +08:00
|
|
|
context 'when have valid params' do
|
|
|
|
before do
|
|
|
|
service = double('success_service')
|
|
|
|
allow(service).to(receive(:succeed?)).and_return(true)
|
|
|
|
allow(service).to(receive(:warnings)).and_return([])
|
|
|
|
|
|
|
|
allow_any_instance_of(Repositories::MultipleShareUpdateService).to(receive(:call)).and_return(service)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
repository_id: repository.id,
|
|
|
|
team_id: team.id,
|
|
|
|
permission_changes: '{"5":true}',
|
|
|
|
share_team_ids: %w(1 2 3),
|
|
|
|
write_permissions: %w(3)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders status ok' do
|
2019-08-29 23:17:38 +08:00
|
|
|
post :update, params: params
|
2019-08-06 21:17:13 +08:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when have invalid params' do
|
|
|
|
before do
|
|
|
|
service = double('unsuccess_service')
|
|
|
|
allow(service).to(receive(:succeed?)).and_return(false)
|
|
|
|
allow(service).to(receive(:errors)).and_return({})
|
|
|
|
|
|
|
|
allow_any_instance_of(Repositories::MultipleShareUpdateService).to(receive(:call)).and_return(service)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:new_repository) { create :repository }
|
|
|
|
let(:params) do
|
|
|
|
{
|
2019-08-29 23:17:38 +08:00
|
|
|
repository_id: repository.id,
|
2019-08-06 21:17:13 +08:00
|
|
|
team_id: team.id,
|
|
|
|
permission_changes: '{"5":true}',
|
|
|
|
share_team_ids: %w(1 2 3),
|
|
|
|
write_permissions: %w(3)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders status 422' do
|
2019-08-29 23:17:38 +08:00
|
|
|
post :update, params: params
|
2019-08-06 21:17:13 +08:00
|
|
|
|
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-15 23:00:55 +08:00
|
|
|
end
|