2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::LegacyGithubImport::UserFormatter do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:client) { double }
|
|
|
|
let(:octocat) { double(id: 123456, login: 'octocat', email: 'octocat@example.com') }
|
|
|
|
|
|
|
|
subject(:user) { described_class.new(client, octocat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(client).to receive(:user).and_return(octocat)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#gitlab_id' do
|
|
|
|
context 'when GitHub user is a GitLab user' do
|
|
|
|
it 'return GitLab user id when user associated their account with GitHub' do
|
|
|
|
gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github')
|
|
|
|
|
|
|
|
expect(user.gitlab_id).to eq gl_user.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns GitLab user id when user primary email matches GitHub email' do
|
|
|
|
gl_user = create(:user, email: octocat.email)
|
|
|
|
|
|
|
|
expect(user.gitlab_id).to eq gl_user.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns GitLab user id when any of user linked emails matches GitHub email' do
|
|
|
|
gl_user = create(:user, email: 'johndoe@example.com')
|
|
|
|
create(:email, user: gl_user, email: octocat.email)
|
|
|
|
|
|
|
|
expect(user.gitlab_id).to eq gl_user.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when GitHub user is not a GitLab user' do
|
|
|
|
expect(user.gitlab_id).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|