From 619dbcc4a79eb3091241cf43bcb540085f75dff8 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 22 Mar 2024 13:28:31 +0100 Subject: [PATCH] Post-merge fix --- lib/api/community/achievement.ml | 12 +++--- .../response/community/user_achievements.ml | 39 ------------------- tests/test.ml | 3 +- tests/test_cases/api.ml | 2 +- 4 files changed, 9 insertions(+), 47 deletions(-) delete mode 100644 lib/models/response/community/user_achievements.ml diff --git a/lib/api/community/achievement.ml b/lib/api/community/achievement.ml index 4478758..73b6fd7 100644 --- a/lib/api/community/achievement.ml +++ b/lib/api/community/achievement.ml @@ -11,7 +11,7 @@ let get_available game domain send = | None -> Lwt.return None ;; -let get ?(profile_ids=[]) game domain send = +let get ?(profile_ids = []) game domain send = match profile_ids with | [] -> Lwt.fail_with "Profile IDs list cannot be empty" | _ids -> @@ -20,9 +20,9 @@ let get ?(profile_ids=[]) game domain send = Uri.with_query' base_url [ "title", Data.Game.to_str game; "profileids", Data.Query.encode_lst_i profile_ids ] in let* json = send url in - match json with - | Some j -> - let model = Models.Response.Community.Achievement_attainment.from_json j in - Lwt.return @@ Some model - | None -> Lwt.return None + (match json with + | Some j -> + let model = Models.Response.Community.Achievement_attainment.from_json j in + Lwt.return @@ Some model + | None -> Lwt.return None) ;; diff --git a/lib/models/response/community/user_achievements.ml b/lib/models/response/community/user_achievements.ml deleted file mode 100644 index 777c073..0000000 --- a/lib/models/response/community/user_achievements.ml +++ /dev/null @@ -1,39 +0,0 @@ -type achievement_response = - { result : Stub.Response.header - ; user_achievements_map : (string * Stub.Achievement_attainment.achievement_attainment) list - } - -let to_json r = - `Assoc - [ "result", Stub.Response.to_json r.result - ; ( "userAchievementsMap" - , `List - (List.map - (fun (id, achievements) -> - `Assoc [ id, `List (List.map Stub.Achievement_attainment.to_json achievements) ]) - r.user_achievements_map) ) - ] -;; - -let from_json (json : Yojson.Basic.t) = - { result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json) - ; user_achievements_map = - Yojson.Basic.Util.( - json - |> member "userAchievementsMap" - |> to_list - |> List.fold_left - (fun acc js -> - match js with - | `Assoc user_achievements -> - List.fold_left - (fun acc (id, ach_json) -> - match ach_json with - | `List achievements -> (id, List.map Stub.Achievement_attainment.from_json achievements) :: acc - | _ -> acc) - acc - user_achievements - | _ -> acc) - []) - } -;; diff --git a/tests/test.ml b/tests/test.ml index 205077c..ea0191a 100644 --- a/tests/test.ml +++ b/tests/test.ml @@ -6,7 +6,8 @@ let () = , [ Alcotest_lwt.test_case "/community/advertisement/findAdvertisements" `Quick (fun _ () -> Test_cases.Api.test_get_advertisements ()) ; Alcotest_lwt.test_case "/community/news/getNews" `Quick (fun _ () -> Test_cases.Api.test_get_news ()) - ; Alcotest_lwt.test_case "/community/achievement/getAchievements" `Quick (fun _ () -> Test_cases.Api.test_get_achievements ()) + ; Alcotest_lwt.test_case "/community/achievement/getAchievements" `Quick (fun _ () -> + Test_cases.Api.test_get_achievements ()) ; Alcotest_lwt.test_case "/community/achievement/getAvailableAchievements" `Quick (fun _ () -> Test_cases.Api.test_get_available_achievements ()) ] ) diff --git a/tests/test_cases/api.ml b/tests/test_cases/api.ml index b9e135a..67d6a16 100644 --- a/tests/test_cases/api.ml +++ b/tests/test_cases/api.ml @@ -31,7 +31,7 @@ let test_get_available_achievements () = let test_get_achievements () = let requester = Mock.Json_file.create_requester "getAchievements.json" in let client = Client.create "aoe-api.worldsedgelink.com" Data.Game.Age2 in - Client.get (Api.Community.Achievement.get ~profile_ids:[1]) client ~requester + Client.get (Api.Community.Achievement.get ~profile_ids:[ 1 ]) client ~requester >>= function | Some r -> Lwt.return @@ Alcotest.(check string) "Response was success" "SUCCESS" r.result.message | None -> Lwt.fail_with "Expected Some but got None"