github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/UserStateTests.elm (about) 1 module UserStateTests exposing (all) 2 3 import Dict exposing (Dict) 4 import Expect 5 import Test exposing (Test, describe, test) 6 import UserState exposing (UserState(..), isAnonymous, isMember) 7 8 9 isMemberHelper : String -> Dict String (List String) -> Bool -> Bool 10 isMemberHelper teamName roles isAdmin = 11 isMember 12 { teamName = teamName 13 , userState = 14 UserStateLoggedIn 15 { id = "test" 16 , userName = "user" 17 , name = "username" 18 , email = "test_email" 19 , isAdmin = isAdmin 20 , teams = roles 21 } 22 } 23 24 25 all : Test 26 all = 27 describe "user state" 28 [ describe "isAnonymous" <| 29 [ test "is true when the user is unknown" <| 30 \_ -> 31 UserStateUnknown 32 |> isAnonymous 33 |> Expect.equal True 34 , test "is false when the user is logged in" <| 35 \_ -> 36 UserStateLoggedIn 37 { id = "test" 38 , userName = "user" 39 , name = "username" 40 , email = "test_email" 41 , isAdmin = True 42 , teams = Dict.fromList [ ( "team1", [ "role" ] ) ] 43 } 44 |> isAnonymous 45 |> Expect.false "logged-in user should not be anonymous" 46 , test "is true when the user is logged out" <| 47 \_ -> 48 UserStateLoggedOut 49 |> isAnonymous 50 |> Expect.true "logged-out user should be anonymous" 51 ] 52 , describe "isMember" 53 [ test "is true when the super admin user is NOT the member on the given team" <| 54 \_ -> 55 isMemberHelper "team1" (Dict.fromList [ ( "other-team", [ "owner" ] ) ]) True 56 |> Expect.equal True 57 , test "is true when the member is the of role 'pipeline operator'" <| 58 \_ -> 59 isMemberHelper "team1" (Dict.fromList [ ( "team1", [ "pipeline-operator" ] ) ]) False 60 |> Expect.equal True 61 , test "is true when the member is the of role 'member'" <| 62 \_ -> 63 isMemberHelper "team1" (Dict.fromList [ ( "team1", [ "member" ] ) ]) False 64 |> Expect.equal True 65 , test "is true when the member is the of role 'owner'" <| 66 \_ -> 67 isMemberHelper "team1" (Dict.fromList [ ( "team1", [ "owner" ] ) ]) False 68 |> Expect.equal True 69 , test "is false when the member is NOT any of role 'owner' or 'member' or 'pipeline-operator' or admin" <| 70 \_ -> 71 isMemberHelper "team1" (Dict.fromList [ ( "team1", [] ) ]) False 72 |> Expect.equal False 73 ] 74 ]