2019-08-06 17:16:58 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Repositories::MultipleShareUpdateService do
|
|
|
|
let(:user) { create :user }
|
|
|
|
let!(:user_team) { create :user_team, :admin, user: user, team: team }
|
|
|
|
let(:team) { create :team }
|
|
|
|
let(:team2) { create :team }
|
|
|
|
let(:team3) { create :team }
|
|
|
|
let(:repository) { create :repository, team: team }
|
|
|
|
|
|
|
|
context 'when share' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
|
|
|
team_ids_for_share: [{ id: team2.id, permission_level: :shared_read }])
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds TeamRepository record' do
|
|
|
|
expect { service_call }.to change { TeamRepository.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds Activity record' do
|
|
|
|
expect { service_call }.to(change { Activity.all.count }.by(1))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cannot generate share' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
|
|
|
team_ids_for_share: [{ id: -1, permission_level: :shared_read }])
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error' do
|
2019-08-06 21:17:13 +08:00
|
|
|
expect(service_call.warnings.count).to eq(1)
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unshare' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
2019-08-06 21:17:13 +08:00
|
|
|
team_ids_for_unshare: [team2.id])
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes TeamRepository record' do
|
|
|
|
create :team_repository, :write, team: team2, repository: repository
|
|
|
|
|
|
|
|
expect { service_call }.to change { TeamRepository.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds Activity record' do
|
|
|
|
create :team_repository, :write, team: team2, repository: repository
|
|
|
|
|
|
|
|
expect { service_call }.to(change { Activity.all.count }.by(1))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cannot delete share' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
2019-08-06 21:17:13 +08:00
|
|
|
team_ids_for_unshare: [-1])
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error' do
|
2019-08-06 21:17:13 +08:00
|
|
|
expect(service_call.warnings.count).to eq(1)
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when updates share permissions' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(
|
|
|
|
repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
|
|
|
team_ids_for_update: [{ id: team2.id, permission_level: :shared_read }]
|
|
|
|
)
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates permission for share record' do
|
|
|
|
tr = create :team_repository, :write, team: team2, repository: repository
|
|
|
|
|
|
|
|
expect { service_call }.to(change { tr.reload.permission_level })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds Activity record' do
|
|
|
|
create :team_repository, :write, team: team2, repository: repository
|
|
|
|
|
|
|
|
expect { service_call }.to(change { Activity.all.count }.by(1))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cannot update share' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
|
|
|
team_ids_for_update: [{ id: -1, permission_level: :shared_read }])
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns error' do
|
2019-08-06 21:17:13 +08:00
|
|
|
expect(service_call.warnings.count).to eq(1)
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-08-13 20:05:55 +08:00
|
|
|
|
|
|
|
context 'when share_with_all' do
|
|
|
|
let(:service_call) do
|
2019-08-29 23:17:38 +08:00
|
|
|
Repositories::MultipleShareUpdateService.call(repository: repository,
|
|
|
|
user: user,
|
|
|
|
team: team,
|
2019-08-13 20:05:55 +08:00
|
|
|
shared_with_all: true,
|
2019-08-29 23:17:38 +08:00
|
|
|
shared_permissions_level: :shared_write)
|
2019-08-13 20:05:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates permission for share record' do
|
|
|
|
expect { service_call }.to(change { repository.reload.permission_level })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds Activity record' do
|
|
|
|
expect { service_call }.to(change { Activity.all.count }.by(1))
|
|
|
|
end
|
|
|
|
end
|
2019-08-06 17:16:58 +08:00
|
|
|
end
|