2019-10-17 05:07:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-16 09:04:41 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Resolvers::ProjectResolver do
|
2017-08-16 09:04:41 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:project1) { create(:project) }
|
|
|
|
let_it_be(:project2) { create(:project) }
|
|
|
|
let_it_be(:other_project) { create(:project) }
|
2017-08-16 09:04:41 -04:00
|
|
|
|
2018-05-23 03:55:14 -04:00
|
|
|
describe '#resolve' do
|
2017-08-16 09:04:41 -04:00
|
|
|
it 'batch-resolves projects by full path' do
|
|
|
|
paths = [project1.full_path, project2.full_path]
|
|
|
|
|
2019-09-04 13:42:48 -04:00
|
|
|
result = batch_sync(max_queries: 1) do
|
2017-08-16 09:04:41 -04:00
|
|
|
paths.map { |path| resolve_project(path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(result).to contain_exactly(project1, project2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resolves an unknown full_path to nil' do
|
2019-09-04 13:42:48 -04:00
|
|
|
result = batch_sync { resolve_project('unknown/project') }
|
2017-08-16 09:04:41 -04:00
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-06 17:24:19 -04:00
|
|
|
it 'does not increase complexity depending on number of load limits' do
|
|
|
|
field1 = Types::BaseField.new(name: 'test', type: GraphQL::STRING_TYPE, resolver_class: described_class, null: false, max_page_size: 100)
|
|
|
|
field2 = Types::BaseField.new(name: 'test', type: GraphQL::STRING_TYPE, resolver_class: described_class, null: false, max_page_size: 1)
|
|
|
|
|
|
|
|
expect(field1.to_graphql.complexity.call({}, {}, 1)).to eq 2
|
|
|
|
expect(field2.to_graphql.complexity.call({}, {}, 1)).to eq 2
|
|
|
|
end
|
|
|
|
|
2017-08-16 09:04:41 -04:00
|
|
|
def resolve_project(full_path)
|
2018-05-23 03:55:14 -04:00
|
|
|
resolve(described_class, args: { full_path: full_path })
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|