diff options
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/resolvers/timelog_resolver_spec.rb | 131 | ||||
-rw-r--r-- | spec/graphql/types/timelog_type_spec.rb | 2 |
2 files changed, 42 insertions, 91 deletions
diff --git a/spec/graphql/resolvers/timelog_resolver_spec.rb b/spec/graphql/resolvers/timelog_resolver_spec.rb index 585cd657e35..bb4938c751f 100644 --- a/spec/graphql/resolvers/timelog_resolver_spec.rb +++ b/spec/graphql/resolvers/timelog_resolver_spec.rb @@ -11,26 +11,27 @@ RSpec.describe Resolvers::TimelogResolver do context "with a group" do let_it_be(:current_user) { create(:user) } - let_it_be(:group) { create(:group) } - let_it_be(:project) { create(:project, :public, group: group) } - - before_all do - group.add_developer(current_user) - project.add_developer(current_user) - end - - before do - group.clear_memoization(:timelogs) - end + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, :empty_repo, :public, group: group) } describe '#resolve' do + let_it_be(:short_time_ago) { 5.days.ago.beginning_of_day } + let_it_be(:medium_time_ago) { 15.days.ago.beginning_of_day } + let_it_be(:issue) { create(:issue, project: project) } - let_it_be(:issue2) { create(:issue, project: project) } - let_it_be(:timelog1) { create(:issue_timelog, issue: issue, spent_at: 2.days.ago.beginning_of_day) } - let_it_be(:timelog2) { create(:issue_timelog, issue: issue2, spent_at: 2.days.ago.end_of_day) } - let_it_be(:timelog3) { create(:issue_timelog, issue: issue2, spent_at: 10.days.ago) } + let_it_be(:merge_request) { create(:merge_request, source_project: project) } + + let_it_be(:timelog1) { create(:issue_timelog, issue: issue, spent_at: short_time_ago.beginning_of_day) } + let_it_be(:timelog2) { create(:issue_timelog, issue: issue, spent_at: short_time_ago.end_of_day) } + let_it_be(:timelog3) { create(:merge_request_timelog, merge_request: merge_request, spent_at: medium_time_ago) } + + let(:args) { { start_time: short_time_ago, end_time: short_time_ago.noon } } + + it 'finds all timelogs' do + timelogs = resolve_timelogs - let(:args) { { start_time: 6.days.ago, end_time: 2.days.ago.noon } } + expect(timelogs).to contain_exactly(timelog1, timelog2, timelog3) + end it 'finds all timelogs within given dates' do timelogs = resolve_timelogs(**args) @@ -38,15 +39,28 @@ RSpec.describe Resolvers::TimelogResolver do expect(timelogs).to contain_exactly(timelog1) end - it 'return nothing when user has insufficient permissions' do - user = create(:user) - group.add_guest(current_user) + context 'when only start_date is present' do + let(:args) { { start_date: short_time_ago } } + + it 'finds timelogs until the end of day of end_date' do + timelogs = resolve_timelogs(**args) + + expect(timelogs).to contain_exactly(timelog1, timelog2) + end + end + + context 'when only end_date is present' do + let(:args) { { end_date: medium_time_ago } } + + it 'finds timelogs until the end of day of end_date' do + timelogs = resolve_timelogs(**args) - expect(resolve_timelogs(user: user, **args)).to be_empty + expect(timelogs).to contain_exactly(timelog3) + end end context 'when start_time and end_date are present' do - let(:args) { { start_time: 6.days.ago, end_date: 2.days.ago } } + let(:args) { { start_time: short_time_ago, end_date: short_time_ago } } it 'finds timelogs until the end of day of end_date' do timelogs = resolve_timelogs(**args) @@ -56,7 +70,7 @@ RSpec.describe Resolvers::TimelogResolver do end context 'when start_date and end_time are present' do - let(:args) { { start_date: 6.days.ago, end_time: 2.days.ago.noon } } + let(:args) { { start_date: short_time_ago, end_time: short_time_ago.noon } } it 'finds all timelogs within start_date and end_time' do timelogs = resolve_timelogs(**args) @@ -68,95 +82,32 @@ RSpec.describe Resolvers::TimelogResolver do context 'when arguments are invalid' do let_it_be(:error_class) { Gitlab::Graphql::Errors::ArgumentError } - context 'when no time or date arguments are present' do - let(:args) { {} } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Start and End arguments must be present/) - end - end - - context 'when only start_time is present' do - let(:args) { { start_time: 6.days.ago } } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Both Start and End arguments must be present/) - end - end - - context 'when only end_time is present' do - let(:args) { { end_time: 2.days.ago } } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Both Start and End arguments must be present/) - end - end - - context 'when only start_date is present' do - let(:args) { { start_date: 6.days.ago } } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Both Start and End arguments must be present/) - end - end - - context 'when only end_date is present' do - let(:args) { { end_date: 2.days.ago } } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Both Start and End arguments must be present/) - end - end - context 'when start_time and start_date are present' do - let(:args) { { start_time: 6.days.ago, start_date: 6.days.ago } } + let(:args) { { start_time: short_time_ago, start_date: short_time_ago } } it 'returns correct error' do expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Both Start and End arguments must be present/) + .to raise_error(error_class, /Provide either a start date or time, but not both/) end end context 'when end_time and end_date are present' do - let(:args) { { end_time: 2.days.ago, end_date: 2.days.ago } } + let(:args) { { end_time: short_time_ago, end_date: short_time_ago } } it 'returns correct error' do expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Both Start and End arguments must be present/) - end - end - - context 'when three arguments are present' do - let(:args) { { start_date: 6.days.ago, end_date: 2.days.ago, end_time: 2.days.ago } } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /Only Time or Date arguments must be present/) + .to raise_error(error_class, /Provide either an end date or time, but not both/) end end context 'when start argument is after end argument' do - let(:args) { { start_time: 2.days.ago, end_time: 6.days.ago } } + let(:args) { { start_time: short_time_ago, end_time: medium_time_ago } } it 'returns correct error' do expect { resolve_timelogs(**args) } .to raise_error(error_class, /Start argument must be before End argument/) end end - - context 'when time range is more than 60 days' do - let(:args) { { start_time: 3.months.ago, end_time: 2.days.ago } } - - it 'returns correct error' do - expect { resolve_timelogs(**args) } - .to raise_error(error_class, /The time range period cannot contain more than 60 days/) - end - end end end end diff --git a/spec/graphql/types/timelog_type_spec.rb b/spec/graphql/types/timelog_type_spec.rb index 791c2fdb046..1344af89fb6 100644 --- a/spec/graphql/types/timelog_type_spec.rb +++ b/spec/graphql/types/timelog_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['Timelog'] do it { expect(described_class.graphql_name).to eq('Timelog') } it { expect(described_class).to have_graphql_fields(fields) } - it { expect(described_class).to require_graphql_authorizations(:read_group_timelogs) } + it { expect(described_class).to require_graphql_authorizations(:read_issue) } describe 'user field' do subject { described_class.fields['user'] } |