From 86efddf7b3c5f759c4e76cac7dc7a49d55e29b95 Mon Sep 17 00:00:00 2001 From: kiosion Date: Fri, 19 Jul 2024 05:55:29 -0400 Subject: [PATCH] test: Update `translate.ex` cases --- elixir-api/test/api/post_posts_test.exs | 6 ++---- elixir-api/test/translate_test.exs | 18 ++++++------------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/elixir-api/test/api/post_posts_test.exs b/elixir-api/test/api/post_posts_test.exs index 3c922a96c..c9eb71424 100644 --- a/elixir-api/test/api/post_posts_test.exs +++ b/elixir-api/test/api/post_posts_test.exs @@ -220,12 +220,10 @@ defmodule PostPostsTest do total: length(stub_posts["result"]) ) - stub_posts_translatable_calls = length(stub_posts["result"]) - Hexerei.HTTP.MockClient |> Mox.expect( :get, - 2, + length(stub_posts["result"]), fn url, _headers -> if String.contains?(url, "count") and String.contains?(url, "total") do {:ok, @@ -244,7 +242,7 @@ defmodule PostPostsTest do ) |> Mox.expect( :post, - stub_posts_translatable_calls, + 3, # title, desc, and body fn url, body, _params -> assert String.contains?(url, "https://translation.googleapis.com/") diff --git a/elixir-api/test/translate_test.exs b/elixir-api/test/translate_test.exs index 761b9cd6e..e95d90da1 100644 --- a/elixir-api/test/translate_test.exs +++ b/elixir-api/test/translate_test.exs @@ -56,6 +56,7 @@ defmodule TranslateTest do stub_post = TestFixtures.stub_post() stub_posts = TestFixtures.stub_posts() stub_invalid = %{"someKey" => "someValue"} + stub_translated_text = "someTranslatedText" Hexerei.HTTP.MockClient |> Mox.stub( @@ -71,7 +72,7 @@ defmodule TranslateTest do data: %{ translations: [ %{ - translatedText: "someTranslatedText" + translatedText: stub_translated_text } ] } @@ -108,7 +109,7 @@ defmodule TranslateTest do |> List.first() |> Map.get("children") |> List.first() - |> Map.get("text") == "someTranslatedText" + |> Map.get("text") == stub_translated_text assert is_map(translated_post) @@ -116,23 +117,16 @@ defmodule TranslateTest do |> List.first() |> Map.get("children") |> List.first() - |> Map.get("text") == "someTranslatedText" + |> Map.get("text") == stub_translated_text assert is_map(translated_posts) - # Posts should not have their body translated + # Posts should have their body translated assert translated_posts["result"] |> List.first() |> Map.get("body") |> List.first() |> Map.get("children") |> List.first() - |> Map.get("text") == - stub_posts["result"] - |> List.first() - |> Map.get("body") - |> List.first() - |> Map.get("children") - |> List.first() - |> Map.get("text") + |> Map.get("text") == stub_translated_text end end