Commit a3733f1b authored by Max Woolf's avatar Max Woolf

Merge branch 'bw-cleanup-timelog-resolver' into 'master'

Refactor some redundant code in timelog_resolver_spec.rb

See merge request gitlab-org/gitlab!71868
parents 72e3ebbd 28d84751
......@@ -11,6 +11,8 @@ RSpec.describe Resolvers::TimelogResolver do
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:error_class) { Gitlab::Graphql::Errors::ArgumentError }
let(:timelogs) { resolve_timelogs(**args) }
specify do
expect(described_class).to have_non_null_graphql_type(::Types::TimelogType.connection_type)
end
......@@ -24,8 +26,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: 6.days.ago, end_time: 2.days.ago.noon } }
it 'finds all timelogs within given dates' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog1)
end
......@@ -33,8 +33,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { {} }
it 'finds all timelogs' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog1, timelog2, timelog3)
end
end
......@@ -43,8 +41,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: 2.days.ago.noon } }
it 'finds timelogs after the start_time' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog2)
end
end
......@@ -53,8 +49,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { end_time: 2.days.ago.noon } }
it 'finds timelogs before the end_time' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog1, timelog3)
end
end
......@@ -63,8 +57,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: 6.days.ago, end_date: 2.days.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
......@@ -73,8 +65,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_date: 6.days.ago, end_time: 2.days.ago.noon } }
it 'finds all timelogs within start_date and end_time' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog1)
end
end
......@@ -96,7 +86,7 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: 6.days.ago, start_date: 6.days.ago } }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Provide either a start date or time, but not both/)
end
end
......@@ -105,7 +95,7 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { end_time: 2.days.ago, end_date: 2.days.ago } }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Provide either an end date or time, but not both/)
end
end
......@@ -114,14 +104,14 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: 2.days.ago, end_time: 6.days.ago } }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Start argument must be before End argument/)
end
end
end
end
shared_examples "with a group" do
shared_examples 'with a group' 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 }
......@@ -141,8 +131,6 @@ RSpec.describe Resolvers::TimelogResolver do
end
it 'finds all timelogs within given dates' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog1)
end
......@@ -150,8 +138,6 @@ RSpec.describe Resolvers::TimelogResolver 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
......@@ -160,8 +146,6 @@ RSpec.describe Resolvers::TimelogResolver 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(timelogs).to contain_exactly(timelog3)
end
end
......@@ -170,8 +154,6 @@ RSpec.describe Resolvers::TimelogResolver do
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)
expect(timelogs).to contain_exactly(timelog1, timelog2)
end
end
......@@ -180,8 +162,6 @@ RSpec.describe Resolvers::TimelogResolver do
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)
expect(timelogs).to contain_exactly(timelog1)
end
end
......@@ -191,7 +171,7 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: short_time_ago, start_date: short_time_ago } }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Provide either a start date or time, but not both/)
end
end
......@@ -200,7 +180,7 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { end_time: short_time_ago, end_date: short_time_ago } }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Provide either an end date or time, but not both/)
end
end
......@@ -209,14 +189,14 @@ RSpec.describe Resolvers::TimelogResolver do
let(:args) { { start_time: short_time_ago, end_time: medium_time_ago } }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Start argument must be before End argument/)
end
end
end
end
shared_examples "with a user" do
shared_examples 'with a user' 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 }
......@@ -228,20 +208,18 @@ RSpec.describe Resolvers::TimelogResolver do
let_it_be(:timelog3) { create(:merge_request_timelog, merge_request: merge_request, user: current_user) }
it 'blah' do
timelogs = resolve_timelogs(**args)
expect(timelogs).to contain_exactly(timelog1, timelog3)
end
end
context "on a project" do
context 'on a project' do
let(:object) { project }
let(:extra_args) { {} }
it_behaves_like 'with a project'
end
context "with a project filter" do
context 'with a project filter' do
let(:object) { nil }
let(:extra_args) { { project_id: project.to_global_id } }
......@@ -285,8 +263,6 @@ RSpec.describe Resolvers::TimelogResolver do
let(:extra_args) { {} }
it 'pagination returns `default_max_page_size` and sets `has_next_page` true' do
timelogs = resolve_timelogs(**args)
expect(timelogs.items.count).to be(100)
expect(timelogs.has_next_page).to be(true)
end
......@@ -298,7 +274,7 @@ RSpec.describe Resolvers::TimelogResolver do
let(:extra_args) { {} }
it 'returns correct error' do
expect { resolve_timelogs(**args) }
expect { timelogs }
.to raise_error(error_class, /Provide at least one argument/)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment