BigW Consortium Gitlab

members_mapper_spec.rb 2.05 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::ImportExport::MembersMapper, services: true do
4
  describe 'map members' do
5 6 7
    let(:user) { create(:user) }
    let(:project) { create(:project, :public, name: 'searchable_project') }
    let(:user2) { create(:user) }
8
    let(:exported_user_id) { 99 }
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    let(:exported_members) do
      [{
         "id" => 2,
         "access_level" => 40,
         "source_id" => 14,
         "source_type" => "Project",
         "user_id" => 19,
         "notification_level" => 3,
         "created_at" => "2016-03-11T10:21:44.822Z",
         "updated_at" => "2016-03-11T10:21:44.822Z",
         "created_by_id" => nil,
         "invite_email" => nil,
         "invite_token" => nil,
         "invite_accepted_at" => nil,
         "user" =>
           {
25
             "id" => exported_user_id,
26 27 28
             "email" => user2.email,
             "username" => user2.username
           }
29 30 31 32 33 34 35 36 37 38 39 40 41 42
       },
       {
         "id" => 3,
         "access_level" => 40,
         "source_id" => 14,
         "source_type" => "Project",
         "user_id" => nil,
         "notification_level" => 3,
         "created_at" => "2016-03-11T10:21:44.822Z",
         "updated_at" => "2016-03-11T10:21:44.822Z",
         "created_by_id" => 1,
         "invite_email" => 'invite@test.com',
         "invite_token" => 'token',
         "invite_accepted_at" => nil
43 44
       }]
    end
45 46

    let(:members_mapper) do
47
      described_class.new(
48
        exported_members: exported_members, user: user, project: project)
49 50 51
    end

    it 'maps a project member' do
52
      expect(members_mapper.map[exported_user_id]).to eq(user2.id)
53 54 55
    end

    it 'defaults to importer project member if it does not exist' do
56
      expect(members_mapper.map[-1]).to eq(user.id)
57 58
    end

59 60 61
    it 'updates missing author IDs on missing project member' do
      members_mapper.map[-1]

62
      expect(members_mapper.missing_author_ids.first).to eq(-1)
63
    end
64 65 66 67 68 69

    it 'has invited members with no user' do
      members_mapper.map

      expect(ProjectMember.find_by_invite_email('invite@test.com')).not_to be_nil
    end
70 71
  end
end