(** Tests for the automatic development account fixture. *) open Hito_app module Seed = Development_seed.Make (Test_repo) (Test_hash) module Service = Service.Make (Test_repo) (Test_hash) module Workout = Evidence.Workout let run = Lwt_main.run let day = 86_400 let now = Recovery.timestamp_of_unix_seconds (100 * day) let development_seed_tests = [ ( "creates test with three months of native Ideal Routine history", `Quick, fun () -> let repo = Test_repo.create () in run (Seed.seed repo ~now); let service = Service.make ~repo in let trainee = match run (Service.authenticate service ~username:"test" ~password:"test") with | Some trainee -> trainee | None -> Alcotest.fail "expected the development account" in let history = run (Test_repo.history repo trainee.Trainee.id) in Alcotest.(check int) "thirteen weekly cycles" 39 (List.length history); Alcotest.(check bool) "all workouts are complete" true (List.for_all (fun record -> Workout.is_finished record.Repository.workout) history); let oldest = List.hd (List.rev history) in let newest = List.hd history in Alcotest.(check int) "oldest workout starts ninety days ago" ((100 * day) - (90 * day)) (Recovery.timestamp_to_unix_seconds (Workout.started_at oldest.Repository.workout)); Alcotest.(check int) "newest workout starts two days ago" ((100 * day) - (2 * day)) (Recovery.timestamp_to_unix_seconds (Workout.started_at newest.Repository.workout)); match run (Service.active_routine service trainee.Trainee.id) with | Some (_, routine) -> Alcotest.(check string) "Ideal Routine is active" "Ideal Routine" (Prescription.Routine.name routine) | None -> Alcotest.fail "expected an active routine" ); ( "does not duplicate existing development history", `Quick, fun () -> let repo = Test_repo.create () in run (Seed.seed repo ~now); run (Seed.seed repo ~now); let trainee = match run (Test_repo.find_trainee_by_username repo (Result.get_ok (Trainee.username "test"))) with | Some trainee -> trainee | None -> Alcotest.fail "expected the development account" in Alcotest.(check int) "history remains one fixture" 39 (List.length (run (Test_repo.history repo trainee.Trainee.id))) ); ] let suite = [ ("development seed", development_seed_tests) ]