-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from kortirso/issue_52
IS-52 Attaching more identities to one account
- Loading branch information
Showing
10 changed files
with
170 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,8 @@ | |
} | ||
} | ||
} | ||
|
||
.auth-icon { | ||
display: flex; | ||
justify-content: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Auth | ||
class AttachUserService | ||
def call(user:, auth:) | ||
identity = Identity.find_by(uid: auth[:uid], provider: auth[:provider]) | ||
return if identity.present? | ||
|
||
email = auth[:email] | ||
return if email.nil? | ||
|
||
Identities::CreateService.call(user: user, params: auth) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Auth::AttachUserService, type: :service do | ||
subject(:service_call) { described_class.new.call(user: user, auth: oauth) } | ||
|
||
let!(:user) { create :user } | ||
let(:oauth) { | ||
{ | ||
uid: '1234567890', | ||
provider: 'github', | ||
login: 'test_first_name', | ||
email: 'test@email.com' | ||
} | ||
} | ||
|
||
context 'for unexisting identity' do | ||
it 'creates new Identity' do | ||
expect { service_call }.to change(Identity, :count).by(1) | ||
end | ||
|
||
it 'new Identity has params from oauth and belongs to existed user', :aggregate_failures do | ||
service_call | ||
|
||
identity = Identity.last | ||
|
||
expect(identity.uid).to eq oauth[:uid] | ||
expect(identity.provider).to eq oauth[:provider] | ||
expect(identity.user).to eq user | ||
end | ||
end | ||
|
||
context 'for existed identity' do | ||
before { create :identity, uid: oauth[:uid] } | ||
|
||
it 'does not create new Identity and returns nil', :aggregate_failures do | ||
expect { service_call }.not_to change(Identity, :count) | ||
expect(service_call).to be_nil | ||
end | ||
end | ||
end |