Skip to content

Commit 53060a7

Browse files
committed
Remove deprecated arg style syntax and update tests to mantain coverage
1 parent d3df1e5 commit 53060a7

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
},
5353
"dependencies": {
5454
"hoist-non-react-statics": "1.0.5",
55-
"lodash.isempty": "4.1.1",
56-
"warning": "2.1.0"
55+
"lodash.isempty": "4.1.1"
5756
}
5857
}

src/index.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { Component, PropTypes } from 'react'
22
import { connect } from 'react-redux'
33
import hoistStatics from 'hoist-non-react-statics'
44
import isEmpty from 'lodash.isempty'
5-
import warning from 'warning'
65

76
const defaults = {
87
failureRedirectPath: '/login',
@@ -11,7 +10,7 @@ const defaults = {
1110
allowRedirectBack: true
1211
}
1312

14-
const UserAuthWrapper = (args) => {
13+
export const UserAuthWrapper = (args) => {
1514
const { authSelector, failureRedirectPath, wrapperDisplayName, predicate, allowRedirectBack, redirectAction } = {
1615
...defaults,
1716
...args
@@ -114,27 +113,3 @@ const UserAuthWrapper = (args) => {
114113

115114
return wrapComponent
116115
}
117-
118-
// Support the old 0.1.x with deprecation warning
119-
const DeprecatedWrapper = authSelector =>
120-
(failureRedirectPath, wrapperDisplayName, predicate = x => !isEmpty(x), allowRedirectBack = true) => {
121-
warning(false, `Deprecated arg style syntax found for auth wrapper named ${wrapperDisplayName}. Pass a config object instead`)
122-
return UserAuthWrapper({
123-
...defaults,
124-
authSelector,
125-
failureRedirectPath,
126-
wrapperDisplayName,
127-
predicate,
128-
allowRedirectBack
129-
})
130-
}
131-
132-
const BackwardsCompatWrapper = (arg) => {
133-
if (typeof arg === 'function') {
134-
return DeprecatedWrapper(arg)
135-
} else {
136-
return UserAuthWrapper(arg)
137-
}
138-
}
139-
140-
module.exports.UserAuthWrapper = BackwardsCompatWrapper

test/UserAuthWrapper-test.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ const UserIsOnlyTest = UserAuthWrapper({
6262
predicate: user => user.firstName === 'Test'
6363
})
6464

65-
// Intential deprecated version
66-
const UserIsOnlyMcDuderson = UserAuthWrapper(userSelector)('/', 'UserIsOnlyMcDuderson', user => user.lastName === 'McDuderson')
65+
const UserIsOnlyMcDuderson = UserAuthWrapper({
66+
authSelector: userSelector,
67+
redirectAction: routeActions.replace,
68+
failureRedirectPath: '/',
69+
wrapperDisplayName: 'UserIsOnlyMcDuderson',
70+
predicate: user => user.lastName === 'McDuderson'
71+
})
6772

6873
class App extends Component {
6974
static propTypes = {
@@ -362,4 +367,28 @@ describe('UserAuthWrapper', () => {
362367
expect(store.getState().routing.location.pathname).to.equal('/login')
363368
expect(store.getState().routing.location.search).to.equal('?redirect=%2FownProps%2F2')
364369
})
370+
371+
it('uses router for redirect if no redirectAction specified', () => {
372+
373+
const UserIsAuthenticatedNoAction = UserAuthWrapper({
374+
authSelector: userSelector,
375+
wrapperDisplayName: 'UserIsAuthenticatedRouter'
376+
})
377+
378+
const routes = (
379+
<Route path="/" component={App} >
380+
<Route path="login" component={UnprotectedComponent} />
381+
<Route path="noaction" component={UserIsAuthenticatedNoAction(UnprotectedComponent)} />
382+
</Route>
383+
)
384+
385+
const { history, store } = setupTest(routes)
386+
387+
expect(store.getState().routing.location.pathname).to.equal('/')
388+
expect(store.getState().routing.location.search).to.equal('')
389+
390+
history.push('/noaction')
391+
expect(store.getState().routing.location.pathname).to.equal('/login')
392+
expect(store.getState().routing.location.search).to.equal('?redirect=%2Fnoaction')
393+
})
365394
})

0 commit comments

Comments
 (0)