diff options
Diffstat (limited to 'spec/services/timelogs')
-rw-r--r-- | spec/services/timelogs/create_service_spec.rb | 47 | ||||
-rw-r--r-- | spec/services/timelogs/delete_service_spec.rb | 14 |
2 files changed, 54 insertions, 7 deletions
diff --git a/spec/services/timelogs/create_service_spec.rb b/spec/services/timelogs/create_service_spec.rb new file mode 100644 index 00000000000..b5ed4a005c7 --- /dev/null +++ b/spec/services/timelogs/create_service_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Timelogs::CreateService do + let_it_be(:author) { create(:user) } + let_it_be(:project) { create(:project, :public) } + let_it_be(:time_spent) { 3600 } + let_it_be(:spent_at) { "2022-07-08" } + let_it_be(:summary) { "Test summary" } + + let(:issuable) { nil } + let(:users_container) { project } + let(:service) { described_class.new(issuable, time_spent, spent_at, summary, user) } + + describe '#execute' do + subject { service.execute } + + context 'when issuable is an Issue' do + let_it_be(:issuable) { create(:issue, project: project) } + let_it_be(:note_noteable) { create(:issue, project: project) } + + it_behaves_like 'issuable supports timelog creation service' + end + + context 'when issuable is a MergeRequest' do + let_it_be(:issuable) { create(:merge_request, source_project: project, source_branch: 'branch-1') } + let_it_be(:note_noteable) { create(:merge_request, source_project: project, source_branch: 'branch-2') } + + it_behaves_like 'issuable supports timelog creation service' + end + + context 'when issuable is a WorkItem' do + let_it_be(:issuable) { create(:work_item, project: project, title: 'WorkItem-1') } + let_it_be(:note_noteable) { create(:work_item, project: project, title: 'WorkItem-2') } + + it_behaves_like 'issuable supports timelog creation service' + end + + context 'when issuable is an Incident' do + let_it_be(:issuable) { create(:incident, project: project) } + let_it_be(:note_noteable) { create(:incident, project: project) } + + it_behaves_like 'issuable supports timelog creation service' + end + end +end diff --git a/spec/services/timelogs/delete_service_spec.rb b/spec/services/timelogs/delete_service_spec.rb index c52cebdc5bf..ee1133af6b3 100644 --- a/spec/services/timelogs/delete_service_spec.rb +++ b/spec/services/timelogs/delete_service_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Timelogs::DeleteService do let_it_be(:author) { create(:user) } let_it_be(:project) { create(:project, :public) } let_it_be(:issue) { create(:issue, project: project) } - let_it_be(:timelog) { create(:timelog, user: author, issue: issue, time_spent: 1800)} + let_it_be(:timelog) { create(:timelog, user: author, issue: issue, time_spent: 1800) } let(:service) { described_class.new(timelog, user) } @@ -21,8 +21,8 @@ RSpec.describe Timelogs::DeleteService do end it 'returns the removed timelog' do - expect(subject).to be_success - expect(subject.payload).to eq(timelog) + is_expected.to be_success + expect(subject.payload[:timelog]).to eq(timelog) end end @@ -31,7 +31,7 @@ RSpec.describe Timelogs::DeleteService do let!(:timelog) { nil } it 'returns an error' do - expect(subject).to be_error + is_expected.to be_error expect(subject.message).to eq('Timelog doesn\'t exist or you don\'t have permission to delete it') expect(subject.http_status).to eq(404) end @@ -41,7 +41,7 @@ RSpec.describe Timelogs::DeleteService do let(:user) { create(:user) } it 'returns an error' do - expect(subject).to be_error + is_expected.to be_error expect(subject.message).to eq('Timelog doesn\'t exist or you don\'t have permission to delete it') expect(subject.http_status).to eq(404) end @@ -49,14 +49,14 @@ RSpec.describe Timelogs::DeleteService do context 'when the timelog deletion fails' do let(:user) { author } - let!(:timelog) { create(:timelog, user: author, issue: issue, time_spent: 1800)} + let!(:timelog) { create(:timelog, user: author, issue: issue, time_spent: 1800) } before do allow(timelog).to receive(:destroy).and_return(false) end it 'returns an error' do - expect(subject).to be_error + is_expected.to be_error expect(subject.message).to eq('Failed to remove timelog') expect(subject.http_status).to eq(400) end |