2020-01-17 18:08:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ::SystemNotes::TimeTrackingService do
|
2020-01-17 18:08:41 +00:00
|
|
|
let_it_be(:author) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
describe '#change_due_date' do
|
|
|
|
subject { described_class.new(noteable: noteable, project: project, author: author).change_due_date(due_date) }
|
|
|
|
|
|
|
|
let(:due_date) { Date.today }
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when noteable is an issue' do
|
|
|
|
let_it_be(:noteable) { create(:issue, project: project) }
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
it_behaves_like 'a note with overridable created_at'
|
|
|
|
|
|
|
|
it_behaves_like 'a system note' do
|
|
|
|
let(:action) { 'due_date' }
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when due date added' do
|
|
|
|
it 'sets the note text' do
|
|
|
|
expect(subject.note).to eq "changed due date to #{due_date.to_s(:long)}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when due date removed' do
|
|
|
|
let(:due_date) { nil }
|
|
|
|
|
|
|
|
it 'sets the note text' do
|
|
|
|
expect(subject.note).to eq 'removed due date'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tracks the issue event in usage ping' do
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_due_date_changed_action).with(author: author)
|
|
|
|
|
|
|
|
subject
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when noteable is a merge request' do
|
|
|
|
let_it_be(:noteable) { create(:merge_request, source_project: project) }
|
|
|
|
|
|
|
|
it 'does not track the issue event in usage ping' do
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_due_date_changed_action).with(author: author)
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
subject
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
describe '#change_time_estimate' do
|
2020-01-17 18:08:41 +00:00
|
|
|
subject { described_class.new(noteable: noteable, project: project, author: author).change_time_estimate }
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when noteable is an issue' do
|
|
|
|
let_it_be(:noteable, reload: true) { create(:issue, project: project) }
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
it_behaves_like 'a system note' do
|
|
|
|
let(:action) { 'time_tracking' }
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'with a time estimate' do
|
2020-01-17 18:08:41 +00:00
|
|
|
it 'sets the note text' do
|
|
|
|
noteable.update_attribute(:time_estimate, 277200)
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
expect(subject.note).to eq "changed time estimate to 1w 4d 5h"
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when time_tracking_limit_to_hours setting is true' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(time_tracking_limit_to_hours: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the note text' do
|
|
|
|
noteable.update_attribute(:time_estimate, 277200)
|
|
|
|
|
|
|
|
expect(subject.note).to eq "changed time estimate to 77h"
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'without a time estimate' do
|
|
|
|
it 'sets the note text' do
|
|
|
|
expect(subject.note).to eq "removed time estimate"
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
it 'tracks the issue event in usage ping' do
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_time_estimate_changed_action).with(author: author)
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
subject
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when noteable is a merge request' do
|
|
|
|
let_it_be(:noteable) { create(:merge_request, source_project: project) }
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
it 'does not track the issue event in usage ping' do
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_time_estimate_changed_action).with(author: author)
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
subject
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
2020-10-15 06:09:14 +00:00
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
describe '#change_time_spent' do
|
|
|
|
subject { described_class.new(noteable: noteable, project: project, author: author).change_time_spent }
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when noteable is an issue' do
|
|
|
|
let_it_be(:noteable, reload: true) { create(:issue, project: project) }
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
it_behaves_like 'a system note' do
|
|
|
|
let(:action) { 'time_tracking' }
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
before do
|
|
|
|
spend_time!(277200)
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when time was added' do
|
|
|
|
it 'sets the note text' do
|
|
|
|
spend_time!(277200)
|
|
|
|
|
|
|
|
expect(subject.note).to eq "added 1w 4d 5h of time spent"
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when time was subtracted' do
|
|
|
|
it 'sets the note text' do
|
|
|
|
spend_time!(360000)
|
|
|
|
spend_time!(-277200)
|
|
|
|
|
|
|
|
expect(subject.note).to eq "subtracted 1w 4d 5h of time spent"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when time was removed' do
|
|
|
|
it 'sets the note text' do
|
|
|
|
spend_time!(:reset)
|
|
|
|
|
|
|
|
expect(subject.note).to eq "removed time spent"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when time_tracking_limit_to_hours setting is true' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(time_tracking_limit_to_hours: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the note text' do
|
|
|
|
spend_time!(277200)
|
|
|
|
|
|
|
|
expect(subject.note).to eq "added 77h of time spent"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tracks the issue event in usage ping' do
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_time_spent_changed_action).with(author: author)
|
|
|
|
|
|
|
|
spend_time!(277200)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
context 'when noteable is a merge request' do
|
|
|
|
let_it_be(:noteable) { create(:merge_request, source_project: project) }
|
|
|
|
|
|
|
|
it 'does not track the issue event in usage ping' do
|
|
|
|
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_time_estimate_changed_action).with(author: author)
|
|
|
|
|
|
|
|
spend_time!(277200)
|
2020-01-17 18:08:41 +00:00
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
subject
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-15 06:09:14 +00:00
|
|
|
def spend_time!(seconds)
|
|
|
|
noteable.spend_time(duration: seconds, user_id: author.id)
|
|
|
|
noteable.save!
|
|
|
|
end
|
2020-01-17 18:08:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|