summaryrefslogtreecommitdiff
path: root/spec/graphql/loaders/full_path_loader_spec.rb
blob: 2a4732395509168cbd79ab851e20d67af7bd4dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'spec_helper'

describe Loaders::FullPathLoader do
  include GraphqlHelpers

  set(:project1) { create(:project) }
  set(:project2) { create(:project) }

  set(:other_project) { create(:project) }

  describe '.project' do
    it 'batch-resolves projects by full path' do
      paths = [project1.full_path, project2.full_path]

      result = batch(max_queries: 1) do
        paths.map { |path| resolve_project(path) }
      end

      expect(result).to contain_exactly(project1, project2)
    end

    it 'resolves an unknown full_path to nil' do
      result = batch { resolve_project('unknown/project') }

      expect(result).to be_nil
    end

    it 'returns a promise' do
      batch do
        expect(resolve_project(project1.full_path)).to be_a(Promise)
      end
    end
  end

  def resolve_project(full_path)
    resolve(described_class, :project, args: { full_path: full_path })
  end
end