[OCaml] High Intensity Training Online
1
open Support
2
3
let suite =
4
[
5
( "web.errors",
6
[
7
( "form error keys are phrased for the trainee and never leak raw",
8
`Quick,
9
fun () ->
10
(* Library keys are phrased through Dream_html's exported constants,
11
and a key with no wording reads as a generic message rather than
12
the key itself. *)
13
let text = Hito_web.Decode.errors_to_text in
14
Alcotest.(check string)
15
"a library key is phrased" "Enter a value."
16
(text [ ("load", Dream_html.Form.error_required) ]);
17
Alcotest.(check string)
18
"a whole-number key is phrased" "Enter a valid whole number."
19
(text [ ("reps", Dream_html.Form.error_expected_int) ]);
20
let unknown = text [ ("reps", "error.something.new") ] in
21
Alcotest.(check bool)
22
"an unknown key does not leak" false
23
(Option.is_some (index_from ~needle:"error." unknown 0));
24
Alcotest.(check string)
25
"an unknown key reads as a generic message" "Enter a valid value."
26
unknown );
27
( "an unknown path responds 404",
28
`Quick,
29
fun () ->
30
let c = client () in
31
let _ = sign_in_new c in
32
Alcotest.(check int)
33
"responds 404" 404
34
(status (get c "/no-such-page")) );
35
( "the 404 response never depends on a session",
36
`Quick,
37
fun () ->
38
let c = client () in
39
Alcotest.(check int)
40
"unauthenticated 404" 404
41
(status (get c "/deep/unknown/path")) );
42
] );
43
]
44