Commit d7a4f0fc authored by Kerri Miller's avatar Kerri Miller

Track approval rule create, update, delete events

Adds triggers of CUD event tracking
parent ae0971c5
......@@ -26,6 +26,9 @@ module ApprovalRules
def success
track_onboarding_progress
merge_request_activity_counter
.track_approval_rule_added_action(user: current_user)
super
end
......
......@@ -17,5 +17,12 @@ module ApprovalRules
error(rule.errors.messages)
end
end
def success
merge_request_activity_counter
.track_approval_rule_deleted_action(user: current_user)
super
end
end
end
......@@ -22,5 +22,12 @@ module ApprovalRules
params[:groups] += GroupFinder.new(rule, current_user).hidden_groups
end
end
def success
merge_request_activity_counter
.track_approval_rule_edited_action(user: current_user)
super
end
end
end
......@@ -10,22 +10,33 @@ RSpec.describe ApprovalRules::CreateService do
let(:new_approvers) { create_list(:user, 2) }
let(:new_groups) { create_list(:group, 2, :private) }
it 'creates approval, excluding non-eligible users and groups' do
result = described_class.new(target, user, {
name: 'security',
approvals_required: 1,
user_ids: new_approvers.map(&:id),
group_ids: new_groups.map(&:id)
}).execute
expect(result[:status]).to eq(:success)
rule = result[:rule]
expect(rule.name).to eq('security')
expect(rule.approvals_required).to eq(1)
expect(rule.users).to be_empty
expect(rule.groups).to be_empty
context 'basic creation action' do
let(:result) do
described_class.new(target, user, {
name: 'security',
approvals_required: 1,
user_ids: new_approvers.map(&:id),
group_ids: new_groups.map(&:id)
}).execute
end
it 'creates approval, excluding non-eligible users and groups' do
expect(result[:status]).to eq(:success)
rule = result[:rule]
expect(rule.name).to eq('security')
expect(rule.approvals_required).to eq(1)
expect(rule.users).to be_empty
expect(rule.groups).to be_empty
end
it 'tracks creation event via a usage counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_approval_rule_added_action).once.with(user: user)
result
end
end
context 'when some users and groups are eligible' do
......
......@@ -32,6 +32,13 @@ RSpec.describe ApprovalRules::MergeRequestRuleDestroyService do
it 'returns successful status' do
expect(result[:status]).to eq(:success)
end
it 'tracks delete event via a usage counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_approval_rule_deleted_action).once.with(user: user)
result
end
end
context 'when rule not successfully deleted' do
......@@ -42,6 +49,13 @@ RSpec.describe ApprovalRules::MergeRequestRuleDestroyService do
it 'returns error status' do
expect(result[:status]).to eq(:error)
end
it 'does not track delete event via a usage counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.not_to receive(:track_approval_rule_deleted_action)
result
end
end
end
end
......@@ -11,22 +11,33 @@ RSpec.describe ApprovalRules::UpdateService do
let(:new_approvers) { create_list(:user, 2) }
let(:new_groups) { create_list(:group, 2, :private) }
it 'updates approval, excluding non-eligible users and groups' do
result = described_class.new(approval_rule, user, {
name: 'security',
approvals_required: 1,
user_ids: new_approvers.map(&:id),
group_ids: new_groups.map(&:id)
}).execute
expect(result[:status]).to eq(:success)
rule = result[:rule]
expect(rule.name).to eq('security')
expect(rule.approvals_required).to eq(1)
expect(rule.users).to be_empty
expect(rule.groups).to be_empty
context 'basic update action' do
let(:result) do
described_class.new(approval_rule, user, {
name: 'security',
approvals_required: 1,
user_ids: new_approvers.map(&:id),
group_ids: new_groups.map(&:id)
}).execute
end
it 'updates approval, excluding non-eligible users and groups' do
expect(result[:status]).to eq(:success)
rule = result[:rule]
expect(rule.name).to eq('security')
expect(rule.approvals_required).to eq(1)
expect(rule.users).to be_empty
expect(rule.groups).to be_empty
end
it 'tracks update event via a usage counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_approval_rule_edited_action).once.with(user: user)
result
end
end
context 'when some users and groups are eligible' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment