blob: a69b56c3d5817f305fadfec9e5d30e042369eb86 (
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
|
# frozen_string_literal: true
RSpec.shared_examples 'updating time estimate' do
context 'when setting time estimate', :aggregate_failures do
using RSpec::Parameterized::TableSyntax
let(:input_params) { input.merge(extra_params).merge({ timeEstimate: time_estimate }) }
before do
resource.update!(time_estimate: 1800)
end
context 'when time estimate is not provided' do
let(:input_params) { input.merge(extra_params).except(:timeEstimate) }
it 'does not update' do
expect { post_graphql_mutation(mutation, current_user: current_user) }
.not_to change { resource.reload.time_estimate }
end
end
context 'when time estimate is not a valid numerical value' do
let(:time_estimate) { '-3.5d' }
it 'does not update' do
expect { post_graphql_mutation(mutation, current_user: current_user) }
.not_to change { resource.reload.time_estimate }
end
it 'returns error' do
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => /must be greater than or equal to zero/))
end
end
context 'when time estimate is not a number' do
let(:time_estimate) { 'nonsense' }
it 'does not update' do
expect { post_graphql_mutation(mutation, current_user: current_user) }
.not_to change { resource.reload.time_estimate }
end
it 'returns error' do
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => /must be formatted correctly/))
end
end
context 'when time estimate is valid' do
let(:time_estimate) { "1h" }
before do
post_graphql_mutation(mutation, current_user: current_user)
end
it_behaves_like 'a working GraphQL mutation'
where(:time_estimate, :value) do
'1h' | 3600
'0h' | 0
'-0h' | 0
nil | 0
end
with_them do
specify do
expect(graphql_data_at(mutation_name, resource.class.to_s.underscore, 'timeEstimate')).to eq(value)
end
end
end
end
end
|