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

require 'fast_spec_helper'

RSpec.describe Gitlab::GithubImport::Representation::Collaborator, feature_category: :importers do
  shared_examples 'a Collaborator' do
    it 'returns an instance of Collaborator' do
      expect(collaborator).to be_an_instance_of(described_class)
    end

    context 'with Collaborator' do
      it 'includes the user ID' do
        expect(collaborator.id).to eq(42)
      end

      it 'includes the username' do
        expect(collaborator.login).to eq('alice')
      end

      it 'includes the role' do
        expect(collaborator.role_name).to eq('maintainer')
      end
    end
  end

  describe '.from_api_response' do
    it_behaves_like 'a Collaborator' do
      let(:response) { { id: 42, login: 'alice', role_name: 'maintainer' } }
      let(:collaborator) { described_class.from_api_response(response) }
    end
  end

  describe '.from_json_hash' do
    it_behaves_like 'a Collaborator' do
      let(:hash) { { 'id' => 42, 'login' => 'alice', role_name: 'maintainer' } }
      let(:collaborator) { described_class.from_json_hash(hash) }
    end
  end
end