summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/etag_caching/router_spec.rb
blob: c748ee007219b8f2a237d5bb2feb5e11ab42bcc3 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::EtagCaching::Router do
  describe '.match', :aggregate_failures do
    context 'with RESTful routes' do
      it 'matches project pipelines endpoint' do
        result = match_route('/my-group/my-project/-/pipelines.json')

        expect(result).to be_present
        expect(result.name).to eq 'project_pipelines'
        expect(result.router).to eq Gitlab::EtagCaching::Router::Restful
      end
    end

    context 'with GraphQL routes' do
      it 'matches pipelines endpoint' do
        result = match_route('/api/graphql', 'pipelines/id/12')

        expect(result).to be_present
        expect(result.name).to eq 'pipelines_graph'
        expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
      end
    end
  end

  def match_route(path, header = nil)
    headers = { 'X-GITLAB-GRAPHQL-RESOURCE-ETAG' => header }.compact

    described_class.match(
      double(path_info: path, headers: headers)
    )
  end
end