Skip to content

Commit

Permalink
add test for the logout route, #10
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Mar 5, 2020
1 parent 7bf2ef0 commit 50c26e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Session.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
port module Session exposing (Person, Session(..), changeSession, decode, encode, logout, navKey, onSessionChange, storeSession)

{-| Represent the current user
The user can be authenticated or a guest
-}

import Browser.Navigation as Nav
Expand Down Expand Up @@ -53,11 +54,6 @@ port storeSession : Maybe JD.Value -> Cmd msg
port onSessionChange : (JE.Value -> msg) -> Sub msg



-- create function which use onSessionChange: pass transform value to maybe person
-- create change function which transform a maybe person to session


changeSession : (Session -> msg) -> Nav.Key -> Sub msg
changeSession toMsg key =
changePerson (\maybePerson -> toMsg (sessionFromPerson maybePerson key))
Expand Down Expand Up @@ -91,6 +87,10 @@ decodeFromChange decoder val =
|> Result.toMaybe



-- set value in localStorage to null


logout : Cmd msg
logout =
storeSession Nothing
17 changes: 17 additions & 0 deletions tests/RouteTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,21 @@ suite =
in
Parser.parse Route.routeParser url
|> Expect.equal Nothing
, test "Test logout route" <|
\_ ->
let
defaultUrl =
{ protocol = Url.Https
, host = "dwyl.com"
, port_ = Just 443
, path = "/"
, query = Nothing
, fragment = Nothing
}

url =
Maybe.withDefault defaultUrl (Url.fromString "http://locahost/logout")
in
Parser.parse Route.routeParser url
|> Expect.equal (Just Route.Logout)
]

0 comments on commit 50c26e0

Please sign in to comment.