Add test case for non-matching password confirmation.

This commit is contained in:
Dillon Kearns 2022-06-18 09:52:54 -07:00
parent df16cf19fc
commit 3e44e8eccc

View File

@ -20,60 +20,26 @@ type Action
all : Test all : Test
all = all =
describe "Form Parser" describe "Form Parser" <|
[ --test "new design idea with errors" <| let
-- \() -> passwordConfirmationParser =
-- FormParser.runNew FormParser.andThenNew
-- (fields (\password passwordConfirmation ->
-- [ ( "password", "mypassword" ) if password.value /= passwordConfirmation.value then
-- , ( "password-confirmation", "my-password" ) ( Nothing
-- ] , Dict.fromList
-- ) [ ( passwordConfirmation.name, [ "Must match password" ] )
-- (FormParser.andThenNew ]
-- (\password passwordConfirmation -> )
-- if password.value == passwordConfirmation.value then
-- passwordConfirmation |> FormParser.withError "Must match password" else
-- FormParser.ok { password = password.value }
-- else )
-- FormParser.ok (\fieldErrors password passwordConfirmation -> Div)
-- ) |> FormParser.field "password" (Field.text |> Field.required "Password is required")
-- |> FormParser.field "password" (FormParser.string "Password is required") |> FormParser.field "password-confirmation" (Field.text |> Field.required "Password confirmation is required")
-- |> FormParser.field "password-confirmation" (FormParser.string "Password confirmation is required") in
-- ) [ test "matching password" <|
-- |> Expect.equal
-- ( Nothing
-- , Dict.fromList
-- [ ( "password-confirmation", [ "Must match password" ] )
-- ]
-- )
--test "non-dependent field error" <|
-- \() ->
-- FormParser.runNew
-- (fields
-- [ ( "password", "mypassword" )
-- , ( "password-confirmation", "" )
-- ]
-- )
-- (FormParser.andThenNew
-- (\password passwordConfirmation ->
-- if password.value == passwordConfirmation.value then
-- --passwordConfirmation |> FormParser.withError "Must match password"
-- Debug.todo ""
--
-- else
-- FormParser.ok { password = password }
-- )
-- |> FormParser.field "password" (FormParser.requiredString "Password is required")
-- |> FormParser.field "password-confirmation" (FormParser.requiredString "Password confirmation is required")
-- )
-- |> Expect.equal
-- ( Nothing
-- , Dict.fromList
-- [ ( "password", [] )
-- , ( "password-confirmation", [ "Password confirmation is required" ] )
-- ]
-- ),
test "new design idea 3" <|
\() -> \() ->
FormParser.runServerSide FormParser.runServerSide
(fields (fields
@ -81,26 +47,24 @@ all =
, ( "password-confirmation", "mypassword" ) , ( "password-confirmation", "mypassword" )
] ]
) )
(FormParser.andThenNew passwordConfirmationParser
(\password passwordConfirmation ->
if password.value /= passwordConfirmation.value then
( Nothing
, Dict.fromList
[ ( passwordConfirmation.name, [ "Must match password" ] )
]
)
else
FormParser.ok { password = password.value }
)
(\fieldErrors password passwordConfirmation -> Div)
|> FormParser.field "password" (Field.text |> Field.required "Password is required")
|> FormParser.field "password-confirmation" (Field.text |> Field.required "Password confirmation is required")
)
|> Expect.equal |> Expect.equal
( Just { password = "mypassword" } ( Just { password = "mypassword" }
, Dict.empty , Dict.empty
) )
, test "non-matching password" <|
\() ->
FormParser.runServerSide
(fields
[ ( "password", "mypassword" )
, ( "password-confirmation", "doesnt-match-password" )
]
)
passwordConfirmationParser
|> Expect.equal
( Nothing
, Dict.fromList [ ( "password-confirmation", [ "Must match password" ] ) ]
)
, describe "oneOf" <| , describe "oneOf" <|
let let
oneOfParsers = oneOfParsers =