blob: 53c42ec0e0041fe817f8ce1bdc2c61adba1a3f51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# frozen_string_literal: true
RSpec.shared_examples 'issuable supports timelog creation service' do
shared_examples 'success_response' do
it 'sucessfully saves the timelog' do
is_expected.to be_success
timelog = subject.payload[:timelog]
expect(timelog).to be_persisted
expect(timelog.time_spent).to eq(time_spent)
expect(timelog.spent_at).to eq('Fri, 08 Jul 2022 00:00:00.000000000 UTC +00:00')
expect(timelog.summary).to eq(summary)
expect(timelog.issuable).to eq(issuable)
end
end
context 'when the user does not have permission' do
let(:user) { create(:user) }
it 'returns an error' do
is_expected.to be_error
expect(subject.message).to eq(
"#{issuable.base_class_name} doesn't exist or you don't have permission to add timelog to it.")
expect(subject.http_status).to eq(404)
end
end
context 'when the user has permissions' do
let(:user) { author }
before do
users_container.add_reporter(user)
end
context 'when the timelog save fails' do
before do
allow_next_instance_of(Timelog) do |timelog|
allow(timelog).to receive(:save).and_return(false)
end
end
it 'returns an error' do
is_expected.to be_error
expect(subject.message).to eq('Failed to save timelog')
end
end
context 'when the creation completes sucessfully' do
it_behaves_like 'success_response'
end
end
end
RSpec.shared_examples 'issuable does not support timelog creation service' do
shared_examples 'error_response' do
it 'returns an error' do
is_expected.to be_error
issuable_type = if issuable.nil?
'Issuable'
else
issuable.base_class_name
end
expect(subject.message).to eq(
"#{issuable_type} doesn't exist or you don't have permission to add timelog to it."
)
expect(subject.http_status).to eq(404)
end
end
context 'when the user does not have permission' do
let(:user) { create(:user) }
it_behaves_like 'error_response'
end
context 'when the user has permissions' do
let(:user) { author }
before do
users_container.add_reporter(user)
end
it_behaves_like 'error_response'
end
end
|