-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add feature to sync from and to cognito
- Loading branch information
Showing
6 changed files
with
129 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
# Changelog | ||
All notable changes to this project made by Monade Team are documented in this file. For info refer to [email protected] | ||
|
||
## [UNRELEASED] - 2023-03-30 | ||
## [1.0.0] - 2023-03-30 | ||
### Added | ||
- `sync_from_cognito!` to create users in the local database from cognito | ||
- `sync_to_cognito!` to create cognito users based from the local database | ||
|
||
### Changed | ||
- [BREAKING] Switched from explicit `aws_access_key`/`aws_secret_access_key` to a more flexible `aws_client_credentials` | ||
|
||
|
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
module CognitoRails | ||
# @return [String] gem version | ||
VERSION = '0.1.0' | ||
VERSION = '1.0.0' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,42 @@ | |
end | ||
end | ||
|
||
context 'class methods' do | ||
before do | ||
expect(CognitoRails::User).to receive(:cognito_client).at_least(:once).and_return(fake_cognito_client) | ||
end | ||
|
||
it '#sync_from_cognito!' do | ||
expect(fake_cognito_client).to receive(:list_users).and_return( | ||
OpenStruct.new( | ||
users: [ | ||
build_cognito_user_data('[email protected]'), | ||
build_cognito_user_data('[email protected]') | ||
], | ||
pagination_token: nil | ||
) | ||
) | ||
|
||
expect do | ||
users = User.sync_from_cognito! | ||
|
||
expect(users).to be_a(Array) | ||
expect(users.size).to eq(2) | ||
expect(users.first).to be_a(User) | ||
end.to change { User.count }.by(2) | ||
|
||
expect(User.pluck(:email)).to match_array(['[email protected]', '[email protected]']) | ||
expect(User.pluck(:name)).to match_array(['Giovanni', 'Giovanni']) | ||
end | ||
|
||
it '#sync_to_cognito!' do | ||
User.create!(email: sample_cognito_email) | ||
|
||
expect_any_instance_of(User).to receive(:init_cognito_user).exactly(1).times | ||
User.sync_to_cognito! | ||
end | ||
end | ||
|
||
context 'admin' do | ||
before do | ||
expect(CognitoRails::User).to receive(:cognito_client).at_least(:once).and_return(fake_cognito_client) | ||
|
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