Skip to content

Commit

Permalink
Implement user:logout
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Jan 20, 2017
1 parent f1190b8 commit 95ef89a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 0 additions & 2 deletions components/ClearUserData.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ exports.getComponent = ->
localStorage.removeItem key
out.send {}
do callback

c
14 changes: 8 additions & 6 deletions graphs/UserMiddleware.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ INPORT=Dispatch.IN:ACTION
OUTPORT=Passed.OUT:PASS
OUTPORT=NewActions.OUT:ACTION

'user,start' -> ROUTES Dispatch(ui/DispatchAction)
'start,user:logout' -> ROUTES Dispatch(ui/DispatchAction)

# User action handling
Dispatch HANDLE[0] -> IN NewActions(core/Merge)
# Pass actions we don't care about onwards
Dispatch PASS -> IN Passed(core/Merge)

# Start action handling
Dispatch HANDLE[1] -> IN ApplicationStart(core/Merge)
Dispatch HANDLE[0] -> IN ApplicationStart(core/Merge)
ApplicationStart OUT -> IN Passed
ApplicationStart OUT -> START LoadUser(ui/LoadUserData)
'user:info' -> ACTION UserInfoAction(ui/SetAction)
LoadUser USER -> IN UserInfoAction OUT -> IN NewActions
LoadUser USER -> IN UserInfoAction OUT -> IN NewActions(core/Merge)
'user:error' -> ACTION UserErrorAction(ui/SetAction)
LoadUser ERROR -> IN UserErrorAction OUT -> IN NewActions

Dispatch PASS -> IN Passed(core/Merge)
# Logout action handling
Dispatch HANDLE[1] -> CLEAR Reset(ui/ClearUserData)
Reset USER -> IN UserInfoAction
23 changes: 23 additions & 0 deletions spec/UserMiddleware.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,26 @@ describe 'User Middleware', ->
return unless received.pass
done()
send actionIn, action, payload
describe 'receiving user:logout action', ->
originalUser = null
userData =
id: 1
name: 'Henri Bergius'
before ->
originalUser = localStorage.getItem 'grid-user'
localStorage.setItem 'grid-user', JSON.stringify userData
after ->
return unless originalUser
localStorage.setItem 'grid-user', originalUser
it 'should send empty object as user:info', (done) ->
received =
pass: false
user: false
action = 'user:logout'
check = (data) ->
chai.expect(data).to.eql {}
receiveAction newAction, 'user:info', check, done
send actionIn, action, true
it 'should have cleared user data', (done) ->
chai.expect(localStorage.getItem('grid-user')).to.equal null
done()

0 comments on commit 95ef89a

Please sign in to comment.