Commit 2368dbb7 authored by Alex Kalderimis's avatar Alex Kalderimis

Remove jira imports resolver

This removes an unnecessary resolver, replacing it with the default
behavior of a method call on the current object.
parent f3bd1e41
...@@ -238,8 +238,7 @@ module Types ...@@ -238,8 +238,7 @@ module Types
field :jira_imports, field :jira_imports,
Types::JiraImportType.connection_type, Types::JiraImportType.connection_type,
null: true, null: true,
description: 'Jira imports into the project', description: 'Jira imports into the project'
resolver: Resolvers::Projects::JiraImportsResolver
field :services, field :services,
Types::Projects::ServiceType.connection_type, Types::Projects::ServiceType.connection_type,
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::Projects::JiraImportsResolver do
include GraphqlHelpers
specify do
expect(described_class).to have_nullable_graphql_type(Types::JiraImportType.connection_type)
end
describe '#resolve' do
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project, :public) }
context 'when project does not have Jira imports' do
let(:current_user) { user }
context 'when user cannot read Jira imports' do
context 'when anonymous user' do
let(:current_user) { nil }
it_behaves_like 'no Jira import access'
end
end
context 'when user can read Jira import data' do
before do
project.add_guest(user)
end
it_behaves_like 'no Jira import data present'
it 'does not raise access error' do
expect do
resolve_imports
end.not_to raise_error
end
end
end
context 'when project has Jira imports' do
let_it_be(:current_user) { user }
let_it_be(:jira_import1) { create(:jira_import_state, :finished, project: project, jira_project_key: 'AA', created_at: 2.days.ago) }
let_it_be(:jira_import2) { create(:jira_import_state, :finished, project: project, jira_project_key: 'BB', created_at: 5.days.ago) }
context 'when user cannot read Jira imports' do
context 'when anonymous user' do
let(:current_user) { nil }
it_behaves_like 'no Jira import access'
end
end
context 'when user can access Jira imports' do
before do
project.add_guest(user)
end
it 'returns Jira imports sorted ascending by created_at time' do
imports = resolve_imports
expect(imports.size).to eq 2
expect(imports.map(&:jira_project_key)).to eq %w(BB AA)
end
end
end
end
def resolve_imports(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
end
end
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe GitlabSchema.types['Project'] do RSpec.describe GitlabSchema.types['Project'] do
include GraphqlHelpers
specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) } specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) }
specify { expect(described_class.graphql_name).to eq('Project') } specify { expect(described_class.graphql_name).to eq('Project') }
...@@ -163,4 +165,25 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -163,4 +165,25 @@ RSpec.describe GitlabSchema.types['Project'] do
end end
it_behaves_like 'a GraphQL type with labels' it_behaves_like 'a GraphQL type with labels'
describe 'jira_imports' do
subject { resolve_field(:jira_imports, project) }
let_it_be(:project) { create(:project, :public) }
context 'when project has Jira imports' do
let_it_be(:jira_import1) { create(:jira_import_state, :finished, project: project, jira_project_key: 'AA', created_at: 2.days.ago) }
let_it_be(:jira_import2) { create(:jira_import_state, :finished, project: project, jira_project_key: 'BB', created_at: 5.days.ago) }
it 'retrieves the imports' do
expect(subject).to contain_exactly(jira_import1, jira_import2)
end
end
context 'when project does not have Jira imports' do
it 'returns an empty result' do
expect(subject).to be_empty
end
end
end
end end
...@@ -126,7 +126,7 @@ module GraphqlHelpers ...@@ -126,7 +126,7 @@ module GraphqlHelpers
schema: GitlabSchema, schema: GitlabSchema,
query: GraphQL::Query.new(GitlabSchema), query: GraphQL::Query.new(GitlabSchema),
parent: nil) parent: nil)
field = described_class.fields[name] field = described_class.fields[::GraphqlHelpers.fieldnamerize(name)]
instance = described_class.authorized_new(object, context) instance = described_class.authorized_new(object, context)
field.resolve_field(instance, {}, context) field.resolve_field(instance, {}, context)
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