2020-08-11 23:10:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Resolvers::IssueStatusCountsResolver do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
2020-08-26 05:10:16 -04:00
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project, state: :opened, created_at: 3.hours.ago, updated_at: 3.hours.ago) }
|
2020-08-11 23:10:17 -04:00
|
|
|
let_it_be(:incident) { create(:incident, project: project, state: :closed, created_at: 1.hour.ago, updated_at: 1.hour.ago, closed_at: 1.hour.ago) }
|
|
|
|
|
2020-08-26 05:10:16 -04:00
|
|
|
# This issue should not be included in the counts
|
|
|
|
let_it_be(:other_project) { create(:project) }
|
|
|
|
let_it_be(:other_proj_issue) { create(:issue, state: :opened, project: other_project) }
|
|
|
|
|
|
|
|
let(:parent) { project }
|
2020-08-11 23:10:17 -04:00
|
|
|
let(:args) { {} }
|
|
|
|
|
2020-08-26 05:10:16 -04:00
|
|
|
before_all do
|
2020-08-11 23:10:17 -04:00
|
|
|
project.add_developer(current_user)
|
2020-08-26 05:10:16 -04:00
|
|
|
other_project.add_developer(current_user)
|
2020-08-11 23:10:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { resolve_issue_status_counts(args) }
|
|
|
|
|
|
|
|
it { is_expected.to be_a(Gitlab::IssuablesCountForState) }
|
|
|
|
specify { expect(subject.project).to eq(project) }
|
|
|
|
|
2020-08-26 05:10:16 -04:00
|
|
|
shared_examples 'returns expected results' do
|
|
|
|
it 'returns expected results', :aggregate_failures do
|
|
|
|
result = resolve_issue_status_counts
|
2020-08-11 23:10:17 -04:00
|
|
|
|
2020-08-26 05:10:16 -04:00
|
|
|
expect(result.all).to eq 2
|
|
|
|
expect(result.opened).to eq 1
|
|
|
|
expect(result.closed).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'returns expected results'
|
|
|
|
|
2020-09-18 08:09:50 -04:00
|
|
|
context 'project used as parent' do
|
|
|
|
let(:parent) { project }
|
|
|
|
|
|
|
|
it_behaves_like 'returns expected results'
|
|
|
|
end
|
|
|
|
|
2020-08-26 05:10:16 -04:00
|
|
|
context 'group used as parent' do
|
|
|
|
let(:parent) { project.group }
|
|
|
|
|
|
|
|
it_behaves_like 'returns expected results'
|
2020-08-11 23:10:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by search', :aggregate_failures do
|
|
|
|
result = resolve_issue_status_counts(search: issue.title)
|
|
|
|
|
|
|
|
expect(result.all).to eq 1
|
|
|
|
expect(result.opened).to eq 1
|
|
|
|
expect(result.closed).to eq 0
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by issue type', :aggregate_failures do
|
2020-12-13 22:10:06 -05:00
|
|
|
result = resolve_issue_status_counts(types: ['incident'])
|
2020-08-11 23:10:17 -04:00
|
|
|
|
|
|
|
expect(result.all).to eq 1
|
|
|
|
expect(result.opened).to eq 0
|
|
|
|
expect(result.closed).to eq 1
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def resolve_issue_status_counts(args = {}, context = { current_user: current_user })
|
2020-08-26 05:10:16 -04:00
|
|
|
resolve(described_class, obj: parent, args: args, ctx: context)
|
2020-08-11 23:10:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|