Commit e0139d61 authored by Sean Arnold's avatar Sean Arnold

Add specs for issue status count resolver

- Need to fix all count to be scoped
parent 227d2967
...@@ -8,7 +8,6 @@ module Resolvers ...@@ -8,7 +8,6 @@ module Resolvers
argument :iid, GraphQL::STRING_TYPE, argument :iid, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'IID of the issue. For example, "1"' description: 'IID of the issue. For example, "1"'
argument :iids, [GraphQL::STRING_TYPE], argument :iids, [GraphQL::STRING_TYPE],
required: false, required: false,
description: 'List of IIDs of issues. For example, [1, 2]' description: 'List of IIDs of issues. For example, [1, 2]'
...@@ -48,10 +47,6 @@ module Resolvers ...@@ -48,10 +47,6 @@ module Resolvers
argument :search, GraphQL::STRING_TYPE, argument :search, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'Search query for issue title or description' description: 'Search query for issue title or description'
argument :sort, Types::IssueSortEnum,
description: 'Sort issues by this criteria',
required: false,
default_value: 'created_desc'
argument :types, [Types::IssueTypeEnum], argument :types, [Types::IssueTypeEnum],
as: :issue_types, as: :issue_types,
description: 'Filter issues by the given issue types', description: 'Filter issues by the given issue types',
......
...@@ -4,6 +4,11 @@ module Resolvers ...@@ -4,6 +4,11 @@ module Resolvers
class IssuesResolver < BaseResolver class IssuesResolver < BaseResolver
prepend Resolvers::IssueResolverFields prepend Resolvers::IssueResolverFields
argument :sort, Types::IssueSortEnum,
description: 'Sort issues by this criteria',
required: false,
default_value: 'created_desc'
type Types::IssueType, null: true type Types::IssueType, null: true
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::IssueStatusCountsResolver do
include GraphqlHelpers
describe '#resolve' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let(:args) { {} }
subject { resolve_issue_status_counts(args) }
it { is_expected.to be_a(Gitlab::IssuablesCountForState) }
specify { expect(subject.project).to eq(project) }
private
def resolve_issue_status_counts(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['IssueStatusCountsType'] do
specify { expect(described_class.graphql_name).to eq('IssueStatusCountsType') }
it 'exposes the expected fields' do
expected_fields = %i[
all
opened
closed
merged
]
expect(described_class).to have_graphql_fields(*expected_fields)
end
end
...@@ -27,6 +27,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -27,6 +27,7 @@ RSpec.describe GitlabSchema.types['Project'] do
boards jira_import_status jira_imports services releases release boards jira_import_status jira_imports services releases release
alert_management_alerts alert_management_alert alert_management_alert_status_counts alert_management_alerts alert_management_alert alert_management_alert_status_counts
container_expiration_policy sast_ci_configuration service_desk_enabled service_desk_address container_expiration_policy sast_ci_configuration service_desk_enabled service_desk_address
issue_status_counts
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
...@@ -9,6 +9,21 @@ RSpec.describe Gitlab::IssuablesCountForState do ...@@ -9,6 +9,21 @@ RSpec.describe Gitlab::IssuablesCountForState do
let(:counter) { described_class.new(finder) } let(:counter) { described_class.new(finder) }
describe 'project given' do
let(:project) { build(:project) }
let(:counter) { described_class.new(finder, project) }
it 'provides the project' do
expect(counter.project).to eq(project)
end
end
describe '.declarative_policy_class' do
subject { described_class.declarative_policy_class }
it { is_expected.to eq('IssuablePolicy') }
end
describe '#for_state_or_opened' do describe '#for_state_or_opened' do
it 'returns the number of issuables for the given state' do it 'returns the number of issuables for the given state' do
expect(counter.for_state_or_opened(:closed)).to eq(1) expect(counter.for_state_or_opened(:closed)).to eq(1)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting Issue counts by status' do
include GraphqlHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user) }
let_it_be(:issue_opened) { create(:issue, project: project) }
let_it_be(:issue_closed) { create(:issue, :closed, project: project) }
# let_it_be(:other_project_issue) { create(:issue) }
let(:params) { { } }
let(:fields) do
<<~QUERY
#{all_graphql_fields_for('IssueStatusCountsType'.classify)}
QUERY
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('issueStatusCounts', params, fields)
)
end
context 'with issue count data' do
let(:issue_counts) { graphql_data.dig('project', 'issueStatusCounts') }
context 'without project permissions' do
let(:user) { create(:user) }
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it { expect(issue_counts).to be nil }
end
context 'with project permissions' do
before do
project.add_developer(current_user)
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it 'returns the correct counts for each status' do
expect(issue_counts).to eq(
'all' => 3,
'opened' => 1,
'closed' => 1,
'merged' => 0 # merged is not relevant for issues
) # but is included in the issuable type
end
end
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