lanonna/pam/test/test_pam.ml

39 lines
1.4 KiB
OCaml
Raw Normal View History

2024-04-24 09:33:01 +02:00
open Alcotest
2024-04-24 09:34:19 +02:00
open Pam.Datatypes
2024-04-23 09:35:10 +02:00
2024-04-24 09:33:01 +02:00
let pprint_ptime ppf x = Fmt.pf ppf "%s" (Ptime.to_rfc3339 x)
let ptime_testable = Alcotest.testable pprint_ptime Ptime.equal
let test_parse () =
2024-04-24 09:34:19 +02:00
let body = {|@alert: -12:38 10:02 +09:24 --10:00 +++23:00
2024-04-24 09:33:01 +02:00
## Description
Specify a time format by writing the exact time of the alert, then adding zero or more '+' or '-'.
Examples, due date is 1/1/1970:
1. 12:38: you get the alert 1/1/1970 at 12:38
2. -12:38: you get the alert 31/12/1969 at 12:38
3. --12:38: you get the alert 30/12/1969 at 12:38
4. +12:38: you get the alert 2/1/1970 at 12:38 |}
2024-04-23 09:35:10 +02:00
in
let m = MatrixRoom.make "test" in
let reminder = {url="example.org"; title= "example"; due_date= Some "2024-04-20T23:59:59+02:00"; body=body; matrix_target=m} in
2024-04-24 09:33:01 +02:00
let expected = [
"2024-04-19T12:38:00+02:00" ;
"2024-04-20T10:02:00+02:00" ;
"2024-04-21T09:24:00+02:00" ;
2024-04-24 09:34:19 +02:00
"2024-04-18T10:00:00+02:00" ;
"2024-04-23T23:00:00+02:00" ;
2024-04-24 09:33:01 +02:00
] |> List.map (fun e -> e |> Ptime.of_rfc3339 |> Result.get_ok |> function | t, _, _ -> t) in
2024-04-23 09:35:10 +02:00
let res = Pam.Issue_parser.to_datetime reminder in
match res with
2024-04-24 09:33:01 +02:00
| Ok None -> Alcotest.fail "Got Ok None"
| Error e -> Alcotest.fail [%string "Got Error %{e}"]
| Ok (Some got) -> Alcotest.check (list ptime_testable) "Alert times" expected got
2024-04-23 09:35:10 +02:00
let () =
2024-04-24 09:33:01 +02:00
Alcotest.run "test1" [
"alert_times", [test_case "Test Alert Times" `Quick test_parse]
]