summaryrefslogtreecommitdiff
path: root/spec/graphql/resolvers/ci/config_resolver_spec.rb
blob: 6911acdb4ec8382b1c8be2ef2cb1da95eda4051e (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Resolvers::Ci::ConfigResolver do
  include GraphqlHelpers

  describe '#resolve' do
    before do
      yaml_processor_double = instance_double(::Gitlab::Ci::YamlProcessor)
      allow(yaml_processor_double).to receive(:execute).and_return(fake_result)

      allow(::Gitlab::Ci::YamlProcessor).to receive(:new).and_return(yaml_processor_double)
    end

    context 'with a valid .gitlab-ci.yml' do
      let(:fake_result) do
        ::Gitlab::Ci::YamlProcessor::Result.new(
          ci_config: ::Gitlab::Ci::Config.new(content),
          errors: [],
          warnings: []
        )
      end

      let_it_be(:content) do
        File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
      end

      it 'lints the ci config file' do
        response = resolve(described_class, args: { content: content }, ctx: {})

        expect(response[:status]).to eq(:valid)
        expect(response[:errors]).to be_empty
      end
    end

    context 'with an invalid .gitlab-ci.yml' do
      let(:content) { 'invalid' }

      let(:fake_result) do
        Gitlab::Ci::YamlProcessor::Result.new(
          ci_config: nil,
          errors: ['Invalid configuration format'],
          warnings: []
        )
      end

      it 'responds with errors about invalid syntax' do
        response = resolve(described_class, args: { content: content }, ctx: {})

        expect(response[:status]).to eq(:invalid)
        expect(response[:errors]).to eq(['Invalid configuration format'])
      end
    end
  end
end