-
Notifications
You must be signed in to change notification settings - Fork 141
Completed redux-logic transition for linkGithubIdentity code #1672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5968455
CHECKPOINT jest
outoftime 01116f1
Fix unnecessary addition of an eslint-disable directive
jwang1919 2214081
Initial transition to react-logic. Moved over unlickGithubIdentity lo…
jwang1919 a3e7c65
Got redux-saga and redux-logic working at the same time.
jwang1919 cd69fcc
Attempt to get jest working on IntelliJ
jwang1919 1fd6c2e
Make jest config more consistent; transform lodash-es
outoftime 32cc3d3
Mocks for bugsnag and firebase libraries
outoftime d515b5c
Revert unnecessary change to karma config
outoftime 8e6b2db
Add some jest rules to eslint config
outoftime 3e1babc
Write test for unlinkGithubIdentityTest.js
jwang1919 d5bce83
Small refactor
jwang1919 e9ed80c
Fix yarn.lock with deduplicate
jwang1919 25b6603
Fix yarn.lock again?
jwang1919 8aa9e02
Refactored test, installed jest-extended (but didn't use it)
jwang1919 785dbde
Fix package.json after rebase
jwang1919 7d59962
Fix yarn.lock again
jwang1919 41914c3
Fix incorrect merge with .eslintrc
jwang1919 0f4523b
Add jest override to .eslintrc
outoftime ca43651
Lint fixing
outoftime 89081bd
Start redux-logic transition for linkGithubIdentity code
jwang1919 cc93549
Completed redux-logic transition for linkGithubIdentity code
jwang1919 8db03c2
Merge remote-tracking branch 'upstream/master' into jest
jwang1919 f0302a7
Fix easy nit-pits. Will work on Rosie and factory approach later.
jwang1919 d3db32e
Fix eslint warnings triggered by Travis
jwang1919 86abf45
Add support for factories
outoftime 2de5d78
Attempt to use Rosie into jest testing
jwang1919 feb77a2
Label all factory objects with a suffix of "Factory". Added mock user…
jwang1919 dfd9bd4
Merge branch 'master' into jest
jwang1919 bfa3636
Fix eslint failing in Travis
jwang1919 c67aa17
Merge remote-tracking branch 'origin/jest' into jest
jwang1919 1d9f486
2nd attempt at fixing eslint failing in Travis
jwang1919 58d7cdd
Added more realistic mock data for githubProfileFactory. Revert chang…
jwang1919 19fa7e5
Merge branch 'master' into jest
outoftime 86d033e
Upgrade eslint-plugin-import, fix import order
outoftime 02fedd8
Merge branch 'master' into jest
outoftime 68123c1
Created new client factory github.js and moved relevant code there. A…
jwang1919 abb5d5d
outoftime requested changes
jwang1919 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,51 @@ | ||
| import {Factory} from 'rosie'; | ||
|
|
||
| class FirebaseError extends Error { | ||
| constructor(args) { | ||
| super(args.name); | ||
| this.code = args.name; | ||
| this.credential = args.credential; | ||
| Error.captureStackTrace(this, FirebaseError); | ||
| } | ||
| } | ||
|
|
||
| export const credentialFactory = new Factory().attrs({ | ||
| providerId: 'github.com', | ||
| accessToken: 'abc123', | ||
| }); | ||
|
|
||
| export const firebaseErrorFactory = Factory.define( | ||
| 'firebaseError', | ||
| FirebaseError, | ||
| ).attrs({ | ||
| name: 'some other error', | ||
| }); | ||
|
|
||
| export const credentialInUseErrorFactory = new Factory().extend( | ||
| firebaseErrorFactory, | ||
| ).attrs({ | ||
| name: 'auth/credential-already-in-use', | ||
| credential: () => credentialFactory.build(), | ||
| }); | ||
|
|
||
| export const userProviderDataFactory = new Factory().attrs({ | ||
| displayName: 'popcoder', | ||
| email: null, | ||
| phoneNumber: null, | ||
| photoUrl: null, | ||
| providerId: 'github.com', | ||
| uid: '1234567', | ||
| }); | ||
|
|
||
| export const userFactory = new Factory().extend( | ||
| userProviderDataFactory, | ||
| ).attrs({ | ||
| emailVerified: false, | ||
| isAnonymous: false, | ||
| metadata: { | ||
| creationTime: Date.now(), | ||
| lastSignInTime: Date.now(), | ||
| }, | ||
| providerData: () => [userProviderDataFactory.build()], | ||
| refreshToken: 'token123', | ||
| }); | ||
This file contains hidden or 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,47 @@ | ||
| import {Factory} from 'rosie'; | ||
|
|
||
| export const githubProfileFactory = new Factory().attrs({ | ||
| login: 'popcoder', | ||
| id: 123456, | ||
| node_id: 'ABC123', | ||
| avatar_url: null, | ||
| gravatar_id: null, | ||
| url: 'https://api.github.com/users/popcoder', | ||
| html_url: 'https://github.com/popcoder', | ||
| followers_url: 'https://api.github.com/users/popcoder/followers', | ||
| following_url: 'https://api.github.com/users/popcoder/following{/other_user}', | ||
| gists_url: 'https://api.github.com/users/popcoder/gists{/gist_id}', | ||
| starred_url: 'https://api.github.com/users/popcoder/starred{/owner}{/repo}', | ||
| subscriptions_url: 'https://api.github.com/users/popcoder/subscriptions', | ||
| organizations_url: 'https://api.github.com/users/popcoder/orgs', | ||
| repos_url: 'https://api.github.com/users/popcoder/repos', | ||
| events_url: 'https://api.github.com/users/popcoder/events{/privacy}', | ||
| received_events_url: 'https://api.github.com/users/popcoder/received_events', | ||
| type: 'User', | ||
| site_admin: false, | ||
| name: 'Popcoder', | ||
| company: null, | ||
| blog: '', | ||
| location: null, | ||
| email: null, | ||
| hireable: null, | ||
| bio: null, | ||
| public_repos: 0, | ||
| public_gists: 0, | ||
| followers: 0, | ||
| following: 0, | ||
| created_at: '2014-09-12T15:02:43Z', | ||
| updated_at: '2019-05-02T13:50:32Z', | ||
| private_gists: 0, | ||
| total_private_repos: 0, | ||
| owned_private_repos: 0, | ||
| disk_usage: 0, | ||
| collaborators: 0, | ||
| two_factor_authentication: false, | ||
| plan: { | ||
| name: 'free', | ||
| space: 1234567, | ||
| collaborators: 0, | ||
| private_repos: 10000, | ||
| }, | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| import linkGithubIdentity from '../linkGithubIdentity'; | ||
| import { | ||
| linkGithub, | ||
| saveCredentialForCurrentUser, | ||
| } from '../../clients/firebase'; | ||
| import {getProfileForAuthenticatedUser} from '../../clients/github'; | ||
| import {bugsnagClient} from '../../util/bugsnag'; | ||
|
|
||
| import { | ||
| credentialFactory, | ||
| credentialInUseErrorFactory, | ||
| firebaseErrorFactory, | ||
| userFactory, | ||
| } from '@factories/clients/firebase'; | ||
|
|
||
| import {githubProfileFactory} from '@factories/clients/github'; | ||
|
|
||
| jest.mock('../../clients/firebase.js'); | ||
| jest.mock('../../clients/github.js'); | ||
| jest.mock('../../util/bugsnag.js'); | ||
|
|
||
| describe('linkGithubIdentity', () => { | ||
| test('success', async() => { | ||
| const mockCredential = credentialFactory.build(); | ||
| const mockUser = userFactory.build(); | ||
|
|
||
| linkGithub.mockResolvedValue({ | ||
| user: mockUser, | ||
| credential: mockCredential, | ||
| }); | ||
|
|
||
| const { | ||
| type, | ||
| payload: { | ||
| credential: {providerId}, | ||
| user, | ||
| }, | ||
| } = await linkGithubIdentity.process(); | ||
|
|
||
| expect(linkGithub).toHaveBeenCalledWith(); | ||
| expect(saveCredentialForCurrentUser).toHaveBeenCalledWith(mockCredential); | ||
| expect(type).toBe('IDENTITY_LINKED'); | ||
| expect(providerId).toBe(mockCredential.providerId); | ||
| expect(user).toEqual(mockUser); | ||
| }); | ||
|
|
||
| test('credential already in use', async() => { | ||
| const error = credentialInUseErrorFactory.build(); | ||
| const githubProfile = githubProfileFactory.build(); | ||
|
|
||
| linkGithub.mockRejectedValue(error); | ||
| getProfileForAuthenticatedUser.mockResolvedValue(githubProfile); | ||
|
|
||
| const { | ||
| type, | ||
| payload: { | ||
| credential: { | ||
| providerId, | ||
| accessToken, | ||
| }, | ||
| }, | ||
| } = await linkGithubIdentity.process(); | ||
| expect(linkGithub).toHaveBeenCalledWith(); | ||
| expect(getProfileForAuthenticatedUser).toHaveBeenCalledWith( | ||
| error.credential.accessToken, | ||
| ); | ||
| expect(type).toBe('ACCOUNT_MIGRATION_NEEDED'); | ||
| expect(providerId).toBe(error.credential.providerId); | ||
| expect(accessToken).toBe(error.credential.accessToken); | ||
jwang1919 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| test('other error', async() => { | ||
| const otherError = firebaseErrorFactory.build(); | ||
|
|
||
| linkGithub.mockRejectedValue(otherError); | ||
| bugsnagClient.notify.mockResolvedValue(); | ||
|
|
||
| const { | ||
| type, | ||
| error, | ||
| payload: {message}, | ||
| } = await linkGithubIdentity.process(); | ||
| expect(linkGithub).toHaveBeenCalledWith(); | ||
| expect(bugsnagClient.notify).toHaveBeenCalledWith(otherError); | ||
| expect(type).toBe('LINK_IDENTITY_FAILED'); | ||
| expect(error).toBe(true); | ||
| expect(message).toBe(otherError.code); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,3 +1,7 @@ | ||
| import linkGithubIdentity from './linkGithubIdentity'; | ||
| import unlinkGithubIdentity from './unlinkGithubIdentity'; | ||
|
|
||
| export default [unlinkGithubIdentity]; | ||
| export default [ | ||
| linkGithubIdentity, | ||
| unlinkGithubIdentity, | ||
| ]; |
This file contains hidden or 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,33 @@ | ||
| import {createLogic} from 'redux-logic'; | ||
|
|
||
| import { | ||
| linkGithub, | ||
| saveCredentialForCurrentUser, | ||
| } from '../clients/firebase'; | ||
| import { | ||
| accountMigrationNeeded, | ||
| identityLinked, | ||
| linkIdentityFailed, | ||
| } from '../actions/user'; | ||
| import {getProfileForAuthenticatedUser} from '../clients/github'; | ||
| import {bugsnagClient} from '../util/bugsnag'; | ||
|
|
||
| export default createLogic({ | ||
| type: 'LINK_GITHUB_IDENTITY', | ||
| async process() { | ||
| try { | ||
| const {user: userData, credential} = await linkGithub(); | ||
| await saveCredentialForCurrentUser(credential); | ||
| return identityLinked(userData, credential); | ||
| } catch (e) { | ||
| if (e.code === 'auth/credential-already-in-use') { | ||
| const {data: githubProfile} = await getProfileForAuthenticatedUser( | ||
| e.credential.accessToken, | ||
| ); | ||
| return accountMigrationNeeded(githubProfile, e.credential); | ||
| } | ||
| await bugsnagClient.notify(e); | ||
| return linkIdentityFailed(e); | ||
| } | ||
| }, | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the right approach to me! 👍