summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
blob: e762dc469c1ec8a16ffda0b5af9bb69ecacdefd6 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
  shared_examples 'a ProtectedBranch rule' do
    it 'returns an instance of ProtectedBranch' do
      expect(protected_branch).to be_an_instance_of(described_class)
    end

    context 'with ProtectedBranch' do
      it 'includes the protected branch ID (name)' do
        expect(protected_branch.id).to eq 'main'
      end

      it 'includes the protected branch allow_force_pushes' do
        expect(protected_branch.allow_force_pushes).to eq true
      end
    end
  end

  describe '.from_api_response' do
    let(:response) do
      response = Struct.new(:url, :allow_force_pushes, keyword_init: true)
      allow_force_pushes = Struct.new(:enabled, keyword_init: true)
      response.new(
        url: 'https://example.com/branches/main/protection',
        allow_force_pushes: allow_force_pushes.new(
          enabled: true
        )
      )
    end

    it_behaves_like 'a ProtectedBranch rule' do
      let(:protected_branch) { described_class.from_api_response(response) }
    end
  end

  describe '.from_json_hash' do
    it_behaves_like 'a ProtectedBranch rule' do
      let(:hash) do
        {
          'id' => 'main',
          'allow_force_pushes' => true
        }
      end

      let(:protected_branch) { described_class.from_json_hash(hash) }
    end
  end
end