-
Notifications
You must be signed in to change notification settings - Fork 144
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 #436 from sharetribe/fix-private-marketplace-login
auth.duck.js: login should wait currentUser entity to be loaded
- Loading branch information
Showing
3 changed files
with
41 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import * as log from '../util/log'; | ||
import { storableError } from '../util/errors'; | ||
import { clearCurrentUser, currentUserShowRequest, currentUserShowSuccess } from './user.duck'; | ||
import { createCurrentUser } from '../util/testData'; | ||
import { | ||
clearCurrentUser, | ||
currentUserShowRequest, | ||
currentUserShowSuccess, | ||
fetchCurrentUserNotificationsRequest, | ||
fetchCurrentUserNotificationsSuccess, | ||
} from './user.duck'; | ||
import reducer, { | ||
authenticationInProgress, | ||
authInfoRequest, | ||
authInfoSuccess, | ||
login, | ||
loginRequest, | ||
|
@@ -188,7 +196,15 @@ describe('auth duck', () => { | |
it('should dispatch success and fetch current user', () => { | ||
const initialState = reducer(); | ||
const getState = () => ({ auth: initialState }); | ||
const sdk = { login: jest.fn(() => Promise.resolve({})) }; | ||
const fakeCurrentUser = createCurrentUser({ id: 'test-user' }); | ||
const fakeCurrentUserResponse = { data: { data: fakeCurrentUser, include: [] } }; | ||
const fakeTransactionsResponse = { data: { data: [], include: [] } }; | ||
const sdk = { | ||
login: jest.fn(() => Promise.resolve({})), | ||
authInfo: jest.fn(() => Promise.resolve({})), | ||
currentUser: { show: jest.fn(() => Promise.resolve(fakeCurrentUserResponse)) }, | ||
transactions: { query: jest.fn(() => Promise.resolve(fakeTransactionsResponse)) }, | ||
}; | ||
const dispatch = createFakeDispatch(getState, sdk); | ||
const username = '[email protected]'; | ||
const password = 'pass'; | ||
|
@@ -197,13 +213,13 @@ describe('auth duck', () => { | |
expect(sdk.login.mock.calls).toEqual([[{ username, password }]]); | ||
expect(dispatchedActions(dispatch)).toEqual([ | ||
loginRequest(), | ||
loginSuccess(), | ||
currentUserShowRequest(), | ||
|
||
// Test restriction: Since the getState mock always returns | ||
// the initial state, user isn't marked as logged in and | ||
// current user is still null. | ||
currentUserShowSuccess(null), | ||
currentUserShowSuccess(fakeCurrentUser), | ||
fetchCurrentUserNotificationsRequest(), | ||
authInfoRequest(), | ||
fetchCurrentUserNotificationsSuccess([]), | ||
authInfoSuccess({}), | ||
loginSuccess(), | ||
]); | ||
}); | ||
}); | ||
|
@@ -335,11 +351,17 @@ describe('auth duck', () => { | |
|
||
describe('signup thunk', () => { | ||
it('should dispatch success and login', () => { | ||
const fakeCurrentUser = createCurrentUser({ id: 'test-user' }); | ||
const fakeCurrentUserResponse = { data: { data: fakeCurrentUser, include: [] } }; | ||
const fakeTransactionsResponse = { data: { data: [], include: [] } }; | ||
const sdk = { | ||
currentUser: { | ||
create: jest.fn(() => Promise.resolve({})), | ||
show: jest.fn(() => Promise.resolve(fakeCurrentUserResponse)), | ||
}, | ||
login: jest.fn(() => Promise.resolve({})), | ||
authInfo: jest.fn(() => Promise.resolve({})), | ||
transactions: { query: jest.fn(() => Promise.resolve(fakeTransactionsResponse)) }, | ||
}; | ||
const getState = () => ({ auth: state }); | ||
const dispatch = createFakeDispatch(getState, sdk); | ||
|
@@ -363,13 +385,13 @@ describe('auth duck', () => { | |
signupRequest(), | ||
signupSuccess(), | ||
loginRequest(), | ||
loginSuccess(), | ||
currentUserShowRequest(), | ||
|
||
// Test restriction: Since the getState mock always returns | ||
// the initial state, user isn't marked as logged in and | ||
// current user is still null. | ||
currentUserShowSuccess(null), | ||
currentUserShowSuccess(fakeCurrentUser), | ||
fetchCurrentUserNotificationsRequest(), | ||
authInfoRequest(), | ||
fetchCurrentUserNotificationsSuccess([]), | ||
authInfoSuccess({}), | ||
loginSuccess(), | ||
]); | ||
}); | ||
}); | ||
|
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