2020-07-01 16:08:20 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
|
2021-09-04 01:27:46 +05:30
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:user) { project.namespace.owner }
|
|
|
|
let(:start_user_id) { user.id }
|
|
|
|
let(:end_user_id) { start_user_id }
|
|
|
|
let(:execute_worker) { subject.perform(start_user_id, end_user_id) }
|
|
|
|
|
|
|
|
it_behaves_like 'worker with data consistency',
|
|
|
|
described_class,
|
|
|
|
data_consistency: :delayed
|
2020-07-01 16:08:20 +05:30
|
|
|
|
|
|
|
describe '#perform' do
|
2021-09-04 01:27:46 +05:30
|
|
|
context 'checks if project authorization update is required' do
|
|
|
|
it 'checks if a project_authorization refresh is needed for each of the users' do
|
|
|
|
User.where(id: start_user_id..end_user_id).each do |user|
|
|
|
|
expect(AuthorizedProjectUpdate::FindRecordsDueForRefreshService).to(
|
|
|
|
receive(:new).with(user).and_call_original)
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
execute_worker
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
context 'when there are project authorization records due for either removal or addition for a specific user' do
|
|
|
|
before do
|
|
|
|
user.project_authorizations.delete_all
|
2020-07-01 16:08:20 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'enqueues a new project authorization update job for the user' do
|
|
|
|
expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).to receive(:perform_async).with(user.id)
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
execute_worker
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
context 'when there are no additions or removals to be made to project authorizations for a specific user' do
|
|
|
|
it 'does not enqueue a new project authorization update job for the user' do
|
|
|
|
expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).not_to receive(:perform_async)
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
execute_worker
|
|
|
|
end
|
2020-07-01 16:08:20 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|