Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
090e884a
Verified
Commit
090e884a
authored
Aug 11, 2018
by
Sébastiaan Versteeg
Browse files
Rename session actions
parent
8c3dc976
Changes
10
Hide whitespace changes
Inline
Side-by-side
__tests__/actions/session.spec.js
View file @
090e884a
...
...
@@ -3,12 +3,12 @@ import * as actions from '../../app/actions/session';
describe
(
'
session actions
'
,
()
=>
{
it
(
'
should expose the session actions
'
,
()
=>
{
expect
(
actions
.
INIT
).
toEqual
(
'
SESSION_INIT
'
);
expect
(
actions
.
S
UCCESS
).
toEqual
(
'
SESSION_SUCCESS
'
);
expect
(
actions
.
LOG
IN
).
toEqual
(
'
SESSION_LOGIN
'
);
expect
(
actions
.
S
IGNED_IN
).
toEqual
(
'
SESSION_SUCCESS
'
);
expect
(
actions
.
SIGN_
IN
).
toEqual
(
'
SESSION_LOGIN
'
);
expect
(
actions
.
TOKEN_INVALID
).
toEqual
(
'
SESSION_TOKEN_INVALID
'
);
expect
(
actions
.
LOG
OUT
).
toEqual
(
'
SESSION_LOGOUT
'
);
expect
(
actions
.
PROFILE
).
toEqual
(
'
SESSION_PROFILE
'
);
expect
(
actions
.
PROFILE_SUCCESS
).
toEqual
(
'
SESSION_PROFILE_SUCCESS
'
);
expect
(
actions
.
SIGN_
OUT
).
toEqual
(
'
SESSION_LOGOUT
'
);
expect
(
actions
.
FETCH_USER_INFO
).
toEqual
(
'
SESSION_PROFILE
'
);
expect
(
actions
.
SET_USER_INFO
).
toEqual
(
'
SESSION_PROFILE_SUCCESS
'
);
});
it
(
'
should create an action to init the session
'
,
()
=>
{
...
...
@@ -20,15 +20,15 @@ describe('session actions', () => {
});
it
(
'
should create an action to log the user in
'
,
()
=>
{
expect
(
actions
.
logi
n
(
'
username
'
,
'
password
'
)).
toMatchSnapshot
();
expect
(
actions
.
signI
n
(
'
username
'
,
'
password
'
)).
toMatchSnapshot
();
});
it
(
'
should create an action for a successful login
'
,
()
=>
{
expect
(
actions
.
s
uccess
(
'
username
'
,
'
token
'
)).
toMatchSnapshot
();
expect
(
actions
.
s
ignedIn
(
'
username
'
,
'
token
'
)).
toMatchSnapshot
();
});
it
(
'
should create an action to log the user out
'
,
()
=>
{
expect
(
actions
.
logo
ut
()).
toMatchSnapshot
();
expect
(
actions
.
signO
ut
()).
toMatchSnapshot
();
});
it
(
'
should create an action to load the user profile
'
,
()
=>
{
...
...
@@ -36,6 +36,6 @@ describe('session actions', () => {
});
it
(
'
should create an action for a successful user profile load
'
,
()
=>
{
expect
(
actions
.
profile
Success
(
'
displayName
'
,
'
photo
'
)).
toMatchSnapshot
();
expect
(
actions
.
userInfo
Success
(
'
displayName
'
,
'
photo
'
)).
toMatchSnapshot
();
});
});
\ No newline at end of file
__tests__/sagas/deepLinking.spec.js
View file @
090e884a
...
...
@@ -31,7 +31,7 @@ describe('calendar saga', () => {
[
matchers
.
call
.
fn
(
apiRequest
),
[]],
])
.
dispatch
(
deepLinkingActions
.
deepLink
(
`
${
siteURL
}
/events/1/`
))
.
dispatch
(
loginActions
.
s
uccess
(
''
,
''
))
.
dispatch
(
loginActions
.
s
ignedIn
(
''
,
''
))
.
put
(
eventActions
.
event
(
'
1
'
))
.
silentRun
());
...
...
__tests__/sagas/session.spec.js
View file @
090e884a
...
...
@@ -6,7 +6,7 @@ import { AsyncStorage } from 'react-native';
import
{
Sentry
}
from
'
react-native-sentry
'
;
import
sessionSaga
,
{
DISPLAYNAMEKEY
,
PHOTOKEY
,
TOKENKEY
,
USERNAMEKEY
DISPLAYNAMEKEY
,
PHOTOKEY
,
TOKENKEY
,
USERNAMEKEY
,
}
from
'
../../app/sagas/session
'
;
import
{
apiRequest
}
from
'
../../app/utils/url
'
;
import
*
as
sessionActions
from
'
../../app/actions/session
'
;
...
...
@@ -42,7 +42,7 @@ describe('session saga', () => {
describe
(
'
logging in
'
,
()
=>
{
it
(
'
should show a snackbar on start
'
,
()
=>
expectSaga
(
sessionSaga
)
.
dispatch
(
sessionActions
.
logi
n
(
'
username
'
,
'
password
'
))
.
dispatch
(
sessionActions
.
signI
n
(
'
username
'
,
'
password
'
))
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
show
).
toBeCalledWith
(
...
...
@@ -55,9 +55,9 @@ describe('session saga', () => {
[
matchers
.
call
.
like
({
fn
:
apiRequest
,
args
:
[
'
token-auth
'
]
}),
{
token
:
'
abc123
'
}],
[
matchers
.
call
.
like
({
fn
:
Sentry
.
setUserContext
}),
{}],
])
.
put
(
sessionActions
.
s
uccess
(
'
username
'
,
'
abc123
'
))
.
put
(
sessionActions
.
s
ignedIn
(
'
username
'
,
'
abc123
'
))
.
put
(
sessionActions
.
profile
(
'
abc123
'
))
.
dispatch
(
sessionActions
.
logi
n
(
'
username
'
,
'
password
'
))
.
dispatch
(
sessionActions
.
signI
n
(
'
username
'
,
'
password
'
))
.
silentRun
());
it
(
'
should show a snackbar when the request succeeds
'
,
()
=>
expectSaga
(
sessionSaga
)
...
...
@@ -65,7 +65,7 @@ describe('session saga', () => {
[
matchers
.
call
.
like
({
fn
:
apiRequest
,
args
:
[
'
token-auth
'
]
}),
{
token
:
'
abc123
'
}],
[
matchers
.
call
.
like
({
fn
:
Sentry
.
setUserContext
}),
{}],
])
.
dispatch
(
sessionActions
.
logi
n
(
'
username
'
,
'
password
'
))
.
dispatch
(
sessionActions
.
signI
n
(
'
username
'
,
'
password
'
))
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
dismiss
).
toBeCalled
();
...
...
@@ -79,7 +79,7 @@ describe('session saga', () => {
[
matchers
.
call
.
like
({
fn
:
apiRequest
,
args
:
[
'
token-auth
'
]
}),
{
token
:
'
abc123
'
}],
[
matchers
.
call
.
like
({
fn
:
Sentry
.
setUserContext
}),
{}],
])
.
dispatch
(
sessionActions
.
logi
n
(
'
username
'
,
'
password
'
))
.
dispatch
(
sessionActions
.
signI
n
(
'
username
'
,
'
password
'
))
.
silentRun
()
.
then
(()
=>
{
expect
(
AsyncStorage
.
multiSet
).
toBeCalledWith
([
...
...
@@ -92,7 +92,7 @@ describe('session saga', () => {
.
provide
([
[
matchers
.
call
.
fn
(
apiRequest
),
throwError
(
error
)],
])
.
dispatch
(
sessionActions
.
logi
n
(
'
username
'
,
'
password
'
))
.
dispatch
(
sessionActions
.
signI
n
(
'
username
'
,
'
password
'
))
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
dismiss
).
toBeCalled
();
...
...
@@ -102,7 +102,7 @@ describe('session saga', () => {
}));
it
(
'
should do a POST request
'
,
()
=>
expectSaga
(
sessionSaga
)
.
dispatch
(
sessionActions
.
logi
n
(
'
username
'
,
'
password
'
))
.
dispatch
(
sessionActions
.
signI
n
(
'
username
'
,
'
password
'
))
.
silentRun
()
.
then
(()
=>
{
expect
(
apiRequest
).
toBeCalledWith
(
'
token-auth
'
,
{
...
...
@@ -118,7 +118,7 @@ describe('session saga', () => {
describe
(
'
logging out
'
,
()
=>
{
it
(
'
should remove the token from the AsyncStorage
'
,
()
=>
expectSaga
(
sessionSaga
)
.
dispatch
(
sessionActions
.
logo
ut
())
.
dispatch
(
sessionActions
.
signO
ut
())
.
silentRun
()
.
then
(()
=>
{
expect
(
AsyncStorage
.
multiRemove
).
toBeCalledWith
([
USERNAMEKEY
,
TOKENKEY
]);
...
...
@@ -126,11 +126,11 @@ describe('session saga', () => {
it
(
'
should put a push notification invalidation action
'
,
()
=>
expectSaga
(
sessionSaga
)
.
put
(
pushNotificationsActions
.
invalidate
())
.
dispatch
(
sessionActions
.
logo
ut
())
.
dispatch
(
sessionActions
.
signO
ut
())
.
silentRun
());
it
(
'
should remove the token from the AsyncStorage
'
,
()
=>
expectSaga
(
sessionSaga
)
.
dispatch
(
sessionActions
.
logo
ut
())
.
dispatch
(
sessionActions
.
signO
ut
())
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
show
).
toBeCalledWith
(
...
...
@@ -149,7 +149,7 @@ describe('session saga', () => {
},
}],
])
.
put
(
sessionActions
.
profile
Success
(
'
Johnny Test
'
,
'
http://example.org/photo.png
'
))
.
put
(
sessionActions
.
userInfo
Success
(
'
Johnny Test
'
,
'
http://example.org/photo.png
'
))
.
dispatch
(
sessionActions
.
profile
(
'
abc123
'
))
.
silentRun
());
...
...
app/actions/session.js
View file @
090e884a
export
const
LOGIN
=
'
SESSION_LOGIN
'
;
export
const
INIT
=
'
SESSION_INIT
'
;
export
const
SUCCESS
=
'
SESSION_SUCCESS
'
;
export
const
LOGOUT
=
'
SESSION_LOGOUT
'
;
export
const
SIGN_IN
=
'
SESSION_SIGN_IN
'
;
export
const
SIGNED_IN
=
'
SESSION_SIGNED_IN
'
;
export
const
SIGN_OUT
=
'
SESSION_SIGN_OUT
'
;
export
const
TOKEN_INVALID
=
'
SESSION_TOKEN_INVALID
'
;
export
const
PROFILE
=
'
SESSION_PROFILE
'
;
export
const
PROFILE_SUCCESS
=
'
SESSION_PROFILE_SUCCESS
'
;
export
const
FETCH_USER_INFO
=
'
SESSION_FETCH_USER_INFO
'
;
export
const
SET_USER_INFO
=
'
SESSION_SET_USER_INFO
'
;
export
function
success
(
username
,
token
)
{
return
{
type
:
SUCCESS
,
payload
:
{
username
,
token
}
};
export
function
init
(
)
{
return
{
type
:
INIT
};
}
export
function
logi
n
(
user
,
pass
)
{
return
{
type
:
LOG
IN
,
payload
:
{
user
,
pass
}
};
export
function
signI
n
(
user
,
pass
)
{
return
{
type
:
SIGN_
IN
,
payload
:
{
user
,
pass
}
};
}
export
function
ini
t
()
{
return
{
type
:
INI
T
};
export
function
signOu
t
()
{
return
{
type
:
SIGN_OU
T
};
}
export
function
logout
(
)
{
return
{
type
:
LOGOUT
};
export
function
signedIn
(
username
,
token
)
{
return
{
type
:
SIGNED_IN
,
payload
:
{
username
,
token
}
};
}
export
function
tokenInvalid
()
{
return
{
type
:
TOKEN_INVALID
};
}
export
function
profile
(
token
)
{
return
{
type
:
PROFILE
,
payload
:
{
token
}
};
export
function
fetchUserInfo
(
token
)
{
return
{
type
:
FETCH_USER_INFO
,
payload
:
{
token
}
};
}
export
function
profileSuccess
(
displayName
,
photo
)
{
return
{
type
:
PROFILE_SUCCESS
,
payload
:
{
displayName
,
photo
}
};
export
function
setUserInfo
(
displayName
,
photo
)
{
return
{
type
:
SET_USER_INFO
,
payload
:
{
displayName
,
photo
}
};
}
app/reducers/navigation.js
View file @
090e884a
...
...
@@ -13,7 +13,7 @@ const initialState = {
export
default
function
navigate
(
state
=
initialState
,
action
=
{})
{
const
{
currentScene
,
previousScenes
,
drawerOpen
}
=
state
;
switch
(
action
.
type
)
{
case
sessionActions
.
S
UCCESS
:
{
case
sessionActions
.
S
IGNED_IN
:
{
return
{
...
state
,
loggedIn
:
true
,
...
...
@@ -64,7 +64,7 @@ export default function navigate(state = initialState, action = {}) {
};
}
case
sessionActions
.
TOKEN_INVALID
:
case
sessionActions
.
LOG
OUT
:
{
case
sessionActions
.
SIGN_
OUT
:
{
return
{
...
initialState
,
currentScene
:
LOGIN_SCENE
,
...
...
app/reducers/session.js
View file @
090e884a
...
...
@@ -11,20 +11,20 @@ const initialState = {
export
default
function
session
(
state
=
initialState
,
action
=
{})
{
switch
(
action
.
type
)
{
case
sessionActions
.
S
UCCESS
:
case
sessionActions
.
S
IGNED_IN
:
return
{
...
state
,
username
:
action
.
payload
.
username
,
token
:
action
.
payload
.
token
,
};
case
sessionActions
.
PROFILE_SUCCESS
:
case
sessionActions
.
SET_USER_INFO
:
return
{
...
state
,
displayName
:
action
.
payload
.
displayName
,
photo
:
action
.
payload
.
photo
,
};
case
sessionActions
.
TOKEN_INVALID
:
case
sessionActions
.
LOG
OUT
:
case
sessionActions
.
SIGN_
OUT
:
return
initialState
;
default
:
return
state
;
...
...
app/sagas/deepLinking.js
View file @
090e884a
...
...
@@ -44,7 +44,7 @@ const deepLink = function* deepLink(action) {
const
loggedIn
=
yield
select
(
loggedInSelector
);
if
(
!
loggedIn
)
{
yield
take
(
loginActions
.
S
UCCESS
);
yield
take
(
loginActions
.
S
IGNED_IN
);
}
const
patterns
=
[
...
...
app/sagas/session.js
View file @
090e884a
import
{
call
,
put
,
takeEvery
}
from
'
redux-saga/effects
'
;
import
{
call
,
put
,
takeEvery
,
select
,
}
from
'
redux-saga/effects
'
;
import
{
AsyncStorage
}
from
'
react-native
'
;
import
Snackbar
from
'
react-native-snackbar
'
;
import
{
Sentry
}
from
'
react-native-sentry
'
;
import
{
apiRequest
}
from
'
../utils/url
'
;
import
{
apiRequest
,
tokenSelector
}
from
'
../utils/url
'
;
import
*
as
sessionActions
from
'
../actions/session
'
;
import
*
as
pushNotificationsActions
from
'
../actions/pushNotifications
'
;
import
{
navigate
}
from
'
../actions/navigation
'
;
...
...
@@ -37,9 +39,9 @@ function* init() {
const
pushCategories
=
JSON
.
parse
(
values
[
PUSHCATEGORYKEY
]);
if
(
username
!==
null
&&
token
!==
null
)
{
yield
put
(
sessionActions
.
s
uccess
(
username
,
token
));
yield
put
(
sessionActions
.
profileSuccess
(
displayName
,
photo
));
yield
put
(
sessionActions
.
profile
(
token
));
yield
put
(
sessionActions
.
s
ignedIn
(
username
,
token
));
yield
put
(
sessionActions
.
setUserInfo
(
displayName
,
photo
));
yield
put
(
sessionActions
.
fetchUserInfo
(
));
yield
put
(
pushNotificationsActions
.
register
(
pushCategories
));
}
else
{
yield
put
(
navigate
(
LOGIN_SCENE
,
true
));
...
...
@@ -49,7 +51,7 @@ function* init() {
}
}
function
*
logi
n
(
action
)
{
function
*
signI
n
(
action
)
{
const
{
user
,
pass
}
=
action
.
payload
;
Snackbar
.
show
({
title
:
'
Logging in
'
,
duration
:
Snackbar
.
LENGTH_INDEFINITE
});
...
...
@@ -73,30 +75,32 @@ function* login(action) {
[
USERNAMEKEY
,
user
],
[
TOKENKEY
,
token
],
]);
yield
put
(
sessionActions
.
s
uccess
(
user
,
token
));
yield
put
(
sessionActions
.
profile
(
token
));
yield
put
(
sessionActions
.
s
ignedIn
(
user
,
token
));
yield
put
(
sessionActions
.
fetchUserInfo
(
));
yield
put
(
pushNotificationsActions
.
register
());
Snackbar
.
dismiss
();
Snackbar
.
show
({
title
:
'
Login successful
'
});
}
catch
(
error
)
{
}
catch
(
e
)
{
Sentry
.
captureException
(
e
);
Snackbar
.
dismiss
();
Snackbar
.
show
({
title
:
'
Login failed
'
});
}
}
function
*
logo
ut
()
{
yield
call
(
AsyncStorage
.
multiRemove
,
[
USERNAMEKEY
,
TOKENKEY
]
);
function
*
signO
ut
()
{
yield
call
(
AsyncStorage
.
clear
);
yield
put
(
pushNotificationsActions
.
invalidate
());
Snackbar
.
show
({
title
:
'
Logout successful
'
});
}
function
*
tokenInvalid
()
{
yield
call
(
AsyncStorage
.
clear
);
yield
put
(
pushNotificationsActions
.
invalidate
());
function
*
signedIn
({
payload
})
{
const
{
username
}
=
payload
;
yield
put
(
navigate
(
WELCOME_SCENE
,
true
));
yield
call
(
Sentry
.
setUserContext
,
{
username
});
}
function
*
profile
(
action
)
{
const
{
token
}
=
action
.
payload
;
function
*
userInfo
(
)
{
const
token
=
yield
select
(
tokenSelector
)
;
const
data
=
{
method
:
'
GET
'
,
...
...
@@ -114,25 +118,24 @@ function* profile(action) {
[
DISPLAYNAMEKEY
,
userProfile
.
display_name
],
[
PHOTOKEY
,
userProfile
.
avatar
.
medium
],
]);
yield
put
(
sessionActions
.
profileSuccess
(
userProfile
.
display_name
,
userProfile
.
avatar
.
medium
));
yield
put
(
sessionActions
.
setUserInfo
(
userProfile
.
display_name
,
userProfile
.
avatar
.
medium
));
}
catch
(
error
)
{
Sentry
.
captureException
(
error
);
}
}
function
*
success
({
payload
})
{
const
{
username
}
=
payload
;
yield
put
(
navigate
(
WELCOME_SCENE
,
true
));
yield
call
(
Sentry
.
setUserContext
,
{
username
});
function
*
tokenInvalid
()
{
yield
call
(
AsyncStorage
.
clear
);
yield
put
(
pushNotificationsActions
.
invalidate
());
}
const
sessionSaga
=
function
*
sessionSaga
()
{
yield
takeEvery
(
sessionActions
.
INIT
,
init
);
yield
takeEvery
(
sessionActions
.
LOGIN
,
login
);
yield
takeEvery
(
sessionActions
.
LOGOUT
,
logout
);
yield
takeEvery
(
sessionActions
.
PROFILE
,
profile
);
yield
takeEvery
(
sessionActions
.
SIGN_IN
,
signIn
);
yield
takeEvery
(
sessionActions
.
SIGN_OUT
,
signOut
);
yield
takeEvery
(
sessionActions
.
SIGNED_IN
,
signedIn
);
yield
takeEvery
(
sessionActions
.
FETCH_USER_INFO
,
userInfo
);
yield
takeEvery
(
sessionActions
.
TOKEN_INVALID
,
tokenInvalid
);
yield
takeEvery
(
sessionActions
.
SUCCESS
,
success
);
};
export
default
sessionSaga
;
app/ui/components/navigator/Sidebar.js
View file @
090e884a
...
...
@@ -65,7 +65,7 @@ const Sidebar = (props) => {
borderTopColor
:
Colors
.
lightGray
,
borderTopWidth
:
1
,
},
scene
:
'
logo
ut
'
,
scene
:
'
signO
ut
'
,
},
];
...
...
@@ -137,7 +137,7 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
dispatch
=>
({
navigate
:
(
scene
,
newSection
=
false
)
=>
dispatch
(
navigationActions
.
navigate
(
scene
,
newSection
)),
logout
:
()
=>
dispatch
(
loginActions
.
logo
ut
()),
logout
:
()
=>
dispatch
(
loginActions
.
signO
ut
()),
loadProfile
:
token
=>
dispatch
(
profileActions
.
profile
(
token
)),
});
...
...
app/ui/screens/user/Login.js
View file @
090e884a
...
...
@@ -88,7 +88,7 @@ const mapStateToProps = state => state.session;
const
mapDispatchToProps
=
dispatch
=>
({
login
:
(
username
,
password
)
=>
{
Keyboard
.
dismiss
();
dispatch
(
actions
.
logi
n
(
username
,
password
));
dispatch
(
actions
.
signI
n
(
username
,
password
));
},
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment